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 | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 4 | * Copyright © 2012 Collabora, Ltd. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 5 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 15 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
Kristian Høgsberg | 06bc264 | 2010-12-01 09:50:16 -0500 | [diff] [blame] | 25 | #define _GNU_SOURCE |
| 26 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 29 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 34 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 35 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 36 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 37 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 38 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 39 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 40 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 41 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 42 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 43 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 44 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 45 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 46 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 47 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 48 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 49 | #include <sys/time.h> |
| 50 | #include <time.h> |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 51 | #include <ctype.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 52 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 53 | #include <wayland-server.h> |
Kristian Høgsberg | 8286302 | 2010-06-04 21:52:02 -0400 | [diff] [blame] | 54 | #include "compositor.h" |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 55 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 56 | #include "git-version.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 57 | |
Pekka Paalanen | 07c91f8 | 2012-08-30 16:47:21 -0500 | [diff] [blame^] | 58 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) |
| 59 | |
| 60 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 61 | static struct wl_list child_process_list; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 62 | static struct weston_compositor *segv_compositor; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 63 | |
| 64 | static int |
| 65 | sigchld_handler(int signal_number, void *data) |
| 66 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 67 | struct weston_process *p; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 68 | int status; |
| 69 | pid_t pid; |
| 70 | |
Bill Spitzak | 027b962 | 2012-03-17 15:22:03 -0700 | [diff] [blame] | 71 | pid = waitpid(-1, &status, WNOHANG); |
| 72 | if (!pid) |
| 73 | return 1; |
| 74 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 75 | wl_list_for_each(p, &child_process_list, link) { |
| 76 | if (p->pid == pid) |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | if (&p->link == &child_process_list) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 81 | weston_log("unknown child process exited\n"); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 82 | return 1; |
| 83 | } |
| 84 | |
| 85 | wl_list_remove(&p->link); |
| 86 | p->cleanup(p, status); |
| 87 | |
| 88 | return 1; |
| 89 | } |
| 90 | |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 91 | WL_EXPORT int |
| 92 | weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode) |
| 93 | { |
| 94 | if (!output->switch_mode) |
| 95 | return -1; |
| 96 | |
| 97 | return output->switch_mode(output, mode); |
| 98 | } |
| 99 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 100 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 101 | weston_watch_process(struct weston_process *process) |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 102 | { |
| 103 | wl_list_insert(&child_process_list, &process->link); |
| 104 | } |
| 105 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 106 | static void |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 107 | child_client_exec(int sockfd, const char *path) |
| 108 | { |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 109 | int clientfd; |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 110 | char s[32]; |
Pekka Paalanen | c47ddfd | 2011-12-08 10:44:56 +0200 | [diff] [blame] | 111 | sigset_t allsigs; |
| 112 | |
| 113 | /* do not give our signal mask to the new process */ |
| 114 | sigfillset(&allsigs); |
| 115 | sigprocmask(SIG_UNBLOCK, &allsigs, NULL); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 116 | |
Kristian Høgsberg | eb76484 | 2012-01-31 22:17:25 -0500 | [diff] [blame] | 117 | /* Launch clients as the user. */ |
| 118 | seteuid(getuid()); |
| 119 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 120 | /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a |
| 121 | * non-CLOEXEC fd to pass through exec. */ |
| 122 | clientfd = dup(sockfd); |
| 123 | if (clientfd == -1) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 124 | weston_log("compositor: dup failed: %m\n"); |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 125 | return; |
| 126 | } |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 127 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 128 | snprintf(s, sizeof s, "%d", clientfd); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 129 | setenv("WAYLAND_SOCKET", s, 1); |
| 130 | |
| 131 | if (execl(path, path, NULL) < 0) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 132 | weston_log("compositor: executing '%s' failed: %m\n", |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 133 | path); |
| 134 | } |
| 135 | |
| 136 | WL_EXPORT struct wl_client * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 137 | weston_client_launch(struct weston_compositor *compositor, |
| 138 | struct weston_process *proc, |
| 139 | const char *path, |
| 140 | weston_process_cleanup_func_t cleanup) |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 141 | { |
| 142 | int sv[2]; |
| 143 | pid_t pid; |
| 144 | struct wl_client *client; |
| 145 | |
Pekka Paalanen | df1fd36 | 2012-08-06 14:57:03 +0300 | [diff] [blame] | 146 | weston_log("launching '%s'\n", path); |
| 147 | |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 148 | if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 149 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 150 | "socketpair failed while launching '%s': %m\n", |
| 151 | path); |
| 152 | return NULL; |
| 153 | } |
| 154 | |
| 155 | pid = fork(); |
| 156 | if (pid == -1) { |
| 157 | close(sv[0]); |
| 158 | close(sv[1]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 159 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 160 | "fork failed while launching '%s': %m\n", path); |
| 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | if (pid == 0) { |
| 165 | child_client_exec(sv[1], path); |
| 166 | exit(-1); |
| 167 | } |
| 168 | |
| 169 | close(sv[1]); |
| 170 | |
| 171 | client = wl_client_create(compositor->wl_display, sv[0]); |
| 172 | if (!client) { |
| 173 | close(sv[0]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 174 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 175 | "wl_client_create failed while launching '%s'.\n", |
| 176 | path); |
| 177 | return NULL; |
| 178 | } |
| 179 | |
| 180 | proc->pid = pid; |
| 181 | proc->cleanup = cleanup; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 182 | weston_watch_process(proc); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 183 | |
| 184 | return client; |
| 185 | } |
| 186 | |
| 187 | static void |
Kristian Høgsberg | a85b4fb | 2012-06-20 09:24:35 -0400 | [diff] [blame] | 188 | update_shm_texture(struct weston_surface *surface); |
| 189 | |
| 190 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 191 | surface_handle_buffer_destroy(struct wl_listener *listener, void *data) |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 192 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 193 | struct weston_surface *es = |
| 194 | container_of(listener, struct weston_surface, |
| 195 | buffer_destroy_listener); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 196 | |
Kristian Høgsberg | a85b4fb | 2012-06-20 09:24:35 -0400 | [diff] [blame] | 197 | if (es->buffer && wl_buffer_is_shm(es->buffer)) |
| 198 | update_shm_texture(es); |
| 199 | |
Kristian Høgsberg | 2459694 | 2011-10-24 17:51:02 -0400 | [diff] [blame] | 200 | es->buffer = NULL; |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 203 | static const pixman_region32_data_t undef_region_data; |
| 204 | |
| 205 | static void |
| 206 | undef_region(pixman_region32_t *region) |
| 207 | { |
Kristian Høgsberg | 66a099b | 2012-05-29 16:49:45 -0400 | [diff] [blame] | 208 | if (region->data != &undef_region_data) |
| 209 | pixman_region32_fini(region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 210 | region->data = (pixman_region32_data_t *) &undef_region_data; |
| 211 | } |
| 212 | |
| 213 | static int |
| 214 | region_is_undefined(pixman_region32_t *region) |
| 215 | { |
| 216 | return region->data == &undef_region_data; |
| 217 | } |
| 218 | |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 219 | static void |
| 220 | empty_region(pixman_region32_t *region) |
| 221 | { |
| 222 | if (!region_is_undefined(region)) |
| 223 | pixman_region32_fini(region); |
| 224 | |
| 225 | pixman_region32_init(region); |
| 226 | } |
| 227 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 228 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 229 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 230 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 231 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 232 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 233 | surface = calloc(1, sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 234 | if (surface == NULL) |
| 235 | return NULL; |
| 236 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 237 | wl_signal_init(&surface->surface.resource.destroy_signal); |
Kristian Høgsberg | 4889154 | 2012-02-23 17:38:33 -0500 | [diff] [blame] | 238 | |
Kristian Høgsberg | f6b1471 | 2011-01-06 15:32:14 -0500 | [diff] [blame] | 239 | wl_list_init(&surface->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 240 | wl_list_init(&surface->layer_link); |
Kristian Høgsberg | c551bd2 | 2010-12-06 16:43:16 -0500 | [diff] [blame] | 241 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 242 | surface->surface.resource.client = NULL; |
Kristian Høgsberg | 8244b44 | 2011-06-23 15:44:14 -0400 | [diff] [blame] | 243 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 244 | surface->compositor = compositor; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 245 | surface->alpha = 1.0; |
Kristian Høgsberg | 0b0c2bb | 2012-05-15 23:16:53 -0400 | [diff] [blame] | 246 | surface->opaque_rect[0] = 0.0; |
| 247 | surface->opaque_rect[1] = 0.0; |
| 248 | surface->opaque_rect[2] = 0.0; |
| 249 | surface->opaque_rect[3] = 0.0; |
Juan Zhao | 4643661 | 2012-03-20 01:48:46 +0800 | [diff] [blame] | 250 | surface->pitch = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 251 | |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 252 | surface->num_textures = 0; |
| 253 | surface->num_images = 0; |
| 254 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 255 | surface->buffer = NULL; |
Kristian Høgsberg | 6f7179c | 2011-08-29 16:09:32 -0400 | [diff] [blame] | 256 | surface->output = NULL; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 257 | surface->plane = &compositor->primary_plane; |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 258 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 259 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 260 | pixman_region32_init(&surface->opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 261 | pixman_region32_init(&surface->clip); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 262 | undef_region(&surface->input); |
Pekka Paalanen | 730d87e | 2012-02-09 16:39:38 +0200 | [diff] [blame] | 263 | pixman_region32_init(&surface->transform.opaque); |
Kristian Høgsberg | 496433b | 2011-11-15 13:50:21 -0500 | [diff] [blame] | 264 | wl_list_init(&surface->frame_callback_list); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 265 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 266 | surface->buffer_destroy_listener.notify = |
| 267 | surface_handle_buffer_destroy; |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 268 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 269 | wl_list_init(&surface->geometry.transformation_list); |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 270 | wl_list_insert(&surface->geometry.transformation_list, |
| 271 | &surface->transform.position.link); |
| 272 | weston_matrix_init(&surface->transform.position.matrix); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 273 | pixman_region32_init(&surface->transform.boundingbox); |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 274 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 275 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 276 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 279 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 280 | weston_surface_set_color(struct weston_surface *surface, |
| 281 | GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
| 282 | { |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 283 | surface->color[0] = red; |
| 284 | surface->color[1] = green; |
| 285 | surface->color[2] = blue; |
| 286 | surface->color[3] = alpha; |
| 287 | surface->shader = &surface->compositor->solid_shader; |
| 288 | } |
| 289 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 290 | WL_EXPORT void |
| 291 | weston_surface_to_global_float(struct weston_surface *surface, |
| 292 | GLfloat sx, GLfloat sy, GLfloat *x, GLfloat *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 293 | { |
| 294 | if (surface->transform.enabled) { |
| 295 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 296 | |
| 297 | weston_matrix_transform(&surface->transform.matrix, &v); |
| 298 | |
| 299 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 300 | weston_log("warning: numerical instability in " |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 301 | "weston_surface_to_global(), divisor = %g\n", |
| 302 | v.f[3]); |
| 303 | *x = 0; |
| 304 | *y = 0; |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | *x = v.f[0] / v.f[3]; |
| 309 | *y = v.f[1] / v.f[3]; |
| 310 | } else { |
| 311 | *x = sx + surface->geometry.x; |
| 312 | *y = sy + surface->geometry.y; |
| 313 | } |
| 314 | } |
| 315 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 316 | WL_EXPORT void |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 317 | weston_surface_move_to_plane(struct weston_surface *surface, |
| 318 | struct weston_plane *plane) |
| 319 | { |
| 320 | if (surface->plane == plane) |
| 321 | return; |
| 322 | |
| 323 | weston_surface_damage_below(surface); |
| 324 | surface->plane = plane; |
| 325 | weston_surface_damage(surface); |
| 326 | } |
| 327 | |
| 328 | WL_EXPORT void |
Kristian Høgsberg | 323ee04 | 2012-02-17 12:45:43 -0500 | [diff] [blame] | 329 | weston_surface_damage_below(struct weston_surface *surface) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 330 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 331 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 332 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 333 | pixman_region32_init(&damage); |
| 334 | pixman_region32_subtract(&damage, &surface->transform.boundingbox, |
| 335 | &surface->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 336 | pixman_region32_union(&surface->plane->damage, |
| 337 | &surface->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 338 | pixman_region32_fini(&damage); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 342 | surface_compute_bbox(struct weston_surface *surface, int32_t sx, int32_t sy, |
| 343 | int32_t width, int32_t height, |
| 344 | pixman_region32_t *bbox) |
| 345 | { |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 346 | GLfloat min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 347 | GLfloat max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 348 | int32_t s[4][2] = { |
| 349 | { sx, sy }, |
| 350 | { sx, sy + height }, |
| 351 | { sx + width, sy }, |
| 352 | { sx + width, sy + height } |
| 353 | }; |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 354 | GLfloat int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 355 | int i; |
| 356 | |
| 357 | for (i = 0; i < 4; ++i) { |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 358 | GLfloat x, y; |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 359 | weston_surface_to_global_float(surface, |
| 360 | s[i][0], s[i][1], &x, &y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 361 | if (x < min_x) |
| 362 | min_x = x; |
| 363 | if (x > max_x) |
| 364 | max_x = x; |
| 365 | if (y < min_y) |
| 366 | min_y = y; |
| 367 | if (y > max_y) |
| 368 | max_y = y; |
| 369 | } |
| 370 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 371 | int_x = floorf(min_x); |
| 372 | int_y = floorf(min_y); |
| 373 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 374 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 377 | static void |
| 378 | weston_surface_update_transform_disable(struct weston_surface *surface) |
| 379 | { |
| 380 | surface->transform.enabled = 0; |
| 381 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 382 | /* round off fractions when not transformed */ |
| 383 | surface->geometry.x = roundf(surface->geometry.x); |
| 384 | surface->geometry.y = roundf(surface->geometry.y); |
| 385 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 386 | pixman_region32_init_rect(&surface->transform.boundingbox, |
| 387 | surface->geometry.x, |
| 388 | surface->geometry.y, |
| 389 | surface->geometry.width, |
| 390 | surface->geometry.height); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 391 | |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 392 | if (surface->alpha == 1.0) { |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 393 | pixman_region32_copy(&surface->transform.opaque, |
| 394 | &surface->opaque); |
| 395 | pixman_region32_translate(&surface->transform.opaque, |
| 396 | surface->geometry.x, |
| 397 | surface->geometry.y); |
| 398 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static int |
| 402 | weston_surface_update_transform_enable(struct weston_surface *surface) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 403 | { |
| 404 | struct weston_matrix *matrix = &surface->transform.matrix; |
| 405 | struct weston_matrix *inverse = &surface->transform.inverse; |
| 406 | struct weston_transform *tform; |
| 407 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 408 | surface->transform.enabled = 1; |
| 409 | |
| 410 | /* Otherwise identity matrix, but with x and y translation. */ |
| 411 | surface->transform.position.matrix.d[12] = surface->geometry.x; |
| 412 | surface->transform.position.matrix.d[13] = surface->geometry.y; |
| 413 | |
| 414 | weston_matrix_init(matrix); |
| 415 | wl_list_for_each(tform, &surface->geometry.transformation_list, link) |
| 416 | weston_matrix_multiply(matrix, &tform->matrix); |
| 417 | |
| 418 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 419 | /* Oops, bad total transformation, not invertible */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 420 | weston_log("error: weston_surface %p" |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 421 | " transformation not invertible.\n", surface); |
| 422 | return -1; |
| 423 | } |
| 424 | |
| 425 | surface_compute_bbox(surface, 0, 0, surface->geometry.width, |
| 426 | surface->geometry.height, |
| 427 | &surface->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 428 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | WL_EXPORT void |
| 433 | weston_surface_update_transform(struct weston_surface *surface) |
| 434 | { |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 435 | if (!surface->geometry.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 436 | return; |
| 437 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 438 | surface->geometry.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 439 | |
Kristian Høgsberg | 323ee04 | 2012-02-17 12:45:43 -0500 | [diff] [blame] | 440 | weston_surface_damage_below(surface); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 441 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 442 | pixman_region32_fini(&surface->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 443 | pixman_region32_fini(&surface->transform.opaque); |
| 444 | pixman_region32_init(&surface->transform.opaque); |
| 445 | |
| 446 | if (region_is_undefined(&surface->input)) |
| 447 | pixman_region32_init_rect(&surface->input, 0, 0, |
| 448 | surface->geometry.width, |
| 449 | surface->geometry.height); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 450 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 451 | /* transform.position is always in transformation_list */ |
| 452 | if (surface->geometry.transformation_list.next == |
| 453 | &surface->transform.position.link && |
| 454 | surface->geometry.transformation_list.prev == |
| 455 | &surface->transform.position.link) { |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 456 | weston_surface_update_transform_disable(surface); |
| 457 | } else { |
| 458 | if (weston_surface_update_transform_enable(surface) < 0) |
| 459 | weston_surface_update_transform_disable(surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 460 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 461 | |
Kristian Høgsberg | f1ea63f | 2012-07-18 12:02:51 -0400 | [diff] [blame] | 462 | weston_surface_damage_below(surface); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 463 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 464 | if (weston_surface_is_mapped(surface)) |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 465 | weston_surface_assign_output(surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 468 | WL_EXPORT void |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 469 | weston_surface_to_global_fixed(struct weston_surface *surface, |
| 470 | wl_fixed_t sx, wl_fixed_t sy, |
| 471 | wl_fixed_t *x, wl_fixed_t *y) |
| 472 | { |
| 473 | GLfloat xf, yf; |
| 474 | |
| 475 | weston_surface_to_global_float(surface, |
| 476 | wl_fixed_to_double(sx), |
| 477 | wl_fixed_to_double(sy), |
| 478 | &xf, &yf); |
| 479 | *x = wl_fixed_from_double(xf); |
| 480 | *y = wl_fixed_from_double(yf); |
| 481 | } |
| 482 | |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 483 | static void |
| 484 | surface_from_global_float(struct weston_surface *surface, |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 485 | GLfloat x, GLfloat y, GLfloat *sx, GLfloat *sy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 486 | { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 487 | if (surface->transform.enabled) { |
| 488 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 489 | |
| 490 | weston_matrix_transform(&surface->transform.inverse, &v); |
| 491 | |
| 492 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 493 | weston_log("warning: numerical instability in " |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 494 | "weston_surface_from_global(), divisor = %g\n", |
| 495 | v.f[3]); |
| 496 | *sx = 0; |
| 497 | *sy = 0; |
| 498 | return; |
| 499 | } |
| 500 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 501 | *sx = v.f[0] / v.f[3]; |
| 502 | *sy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 503 | } else { |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 504 | *sx = x - surface->geometry.x; |
| 505 | *sy = y - surface->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | WL_EXPORT void |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 510 | weston_surface_from_global_fixed(struct weston_surface *surface, |
| 511 | wl_fixed_t x, wl_fixed_t y, |
| 512 | wl_fixed_t *sx, wl_fixed_t *sy) |
| 513 | { |
| 514 | GLfloat sxf, syf; |
| 515 | |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 516 | surface_from_global_float(surface, |
| 517 | wl_fixed_to_double(x), |
| 518 | wl_fixed_to_double(y), |
| 519 | &sxf, &syf); |
| 520 | *sx = wl_fixed_from_double(sxf); |
| 521 | *sy = wl_fixed_from_double(syf); |
| 522 | } |
| 523 | |
| 524 | WL_EXPORT void |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 525 | weston_surface_from_global(struct weston_surface *surface, |
| 526 | int32_t x, int32_t y, int32_t *sx, int32_t *sy) |
| 527 | { |
| 528 | GLfloat sxf, syf; |
| 529 | |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 530 | surface_from_global_float(surface, x, y, &sxf, &syf); |
| 531 | *sx = floorf(sxf); |
| 532 | *sy = floorf(syf); |
| 533 | } |
| 534 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 535 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 536 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 537 | { |
| 538 | struct weston_output *output; |
| 539 | |
| 540 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 541 | if (surface->output_mask & (1 << output->id)) |
| 542 | weston_output_schedule_repaint(output); |
| 543 | } |
| 544 | |
| 545 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 546 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 547 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 548 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
| 549 | 0, 0, surface->geometry.width, |
| 550 | surface->geometry.height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 551 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 552 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 553 | } |
| 554 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 555 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 556 | weston_surface_configure(struct weston_surface *surface, |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 557 | GLfloat x, GLfloat y, int width, int height) |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 558 | { |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 559 | surface->geometry.x = x; |
| 560 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 561 | surface->geometry.width = width; |
| 562 | surface->geometry.height = height; |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 563 | surface->geometry.dirty = 1; |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 566 | WL_EXPORT void |
| 567 | weston_surface_set_position(struct weston_surface *surface, |
| 568 | GLfloat x, GLfloat y) |
| 569 | { |
| 570 | surface->geometry.x = x; |
| 571 | surface->geometry.y = y; |
| 572 | surface->geometry.dirty = 1; |
| 573 | } |
| 574 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 575 | WL_EXPORT int |
| 576 | weston_surface_is_mapped(struct weston_surface *surface) |
| 577 | { |
| 578 | if (surface->output) |
| 579 | return 1; |
| 580 | else |
| 581 | return 0; |
| 582 | } |
| 583 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 584 | WL_EXPORT uint32_t |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 585 | weston_compositor_get_time(void) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 586 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 587 | struct timeval tv; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 588 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 589 | gettimeofday(&tv, NULL); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 590 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 591 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 594 | static struct weston_surface * |
| 595 | weston_compositor_pick_surface(struct weston_compositor *compositor, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 596 | wl_fixed_t x, wl_fixed_t y, |
| 597 | wl_fixed_t *sx, wl_fixed_t *sy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 598 | { |
| 599 | struct weston_surface *surface; |
| 600 | |
| 601 | wl_list_for_each(surface, &compositor->surface_list, link) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 602 | weston_surface_from_global_fixed(surface, x, y, sx, sy); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 603 | if (pixman_region32_contains_point(&surface->input, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 604 | wl_fixed_to_int(*sx), |
| 605 | wl_fixed_to_int(*sy), |
| 606 | NULL)) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 607 | return surface; |
| 608 | } |
| 609 | |
| 610 | return NULL; |
| 611 | } |
| 612 | |
| 613 | static void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 614 | weston_device_repick(struct weston_seat *seat) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 615 | { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 616 | const struct wl_pointer_grab_interface *interface; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 617 | struct weston_surface *surface, *focus; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 618 | struct wl_pointer *pointer = seat->seat.pointer; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 619 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 620 | if (!pointer) |
Daniel Stone | e9e92d2 | 2012-06-04 11:40:47 +0100 | [diff] [blame] | 621 | return; |
| 622 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 623 | surface = weston_compositor_pick_surface(seat->compositor, |
| 624 | pointer->x, |
| 625 | pointer->y, |
| 626 | &pointer->current_x, |
| 627 | &pointer->current_y); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 628 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 629 | if (&surface->surface != pointer->current) { |
| 630 | interface = pointer->grab->interface; |
| 631 | pointer->current = &surface->surface; |
| 632 | interface->focus(pointer->grab, &surface->surface, |
| 633 | pointer->current_x, |
| 634 | pointer->current_y); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 635 | } |
| 636 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 637 | focus = (struct weston_surface *) pointer->grab->focus; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 638 | if (focus) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 639 | weston_surface_from_global_fixed(focus, |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 640 | pointer->x, |
| 641 | pointer->y, |
| 642 | &pointer->grab->x, |
| 643 | &pointer->grab->y); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Kristian Høgsberg | 4ff5a74 | 2012-06-18 16:48:27 -0400 | [diff] [blame] | 646 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 647 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 648 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 649 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 650 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 651 | if (!compositor->focus) |
| 652 | return; |
| 653 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 654 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 655 | weston_device_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 658 | WL_EXPORT void |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 659 | weston_surface_unmap(struct weston_surface *surface) |
| 660 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 661 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 662 | |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 663 | weston_surface_damage_below(surface); |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 664 | surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 665 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 666 | |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 667 | wl_list_for_each(seat, &surface->compositor->seat_list, link) { |
Daniel Stone | e9e92d2 | 2012-06-04 11:40:47 +0100 | [diff] [blame] | 668 | if (seat->seat.keyboard && |
| 669 | seat->seat.keyboard->focus == &surface->surface) |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 670 | wl_keyboard_set_focus(seat->seat.keyboard, NULL); |
Daniel Stone | e9e92d2 | 2012-06-04 11:40:47 +0100 | [diff] [blame] | 671 | if (seat->seat.pointer && |
| 672 | seat->seat.pointer->focus == &surface->surface) |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 673 | wl_pointer_set_focus(seat->seat.pointer, |
| 674 | NULL, |
| 675 | wl_fixed_from_int(0), |
| 676 | wl_fixed_from_int(0)); |
| 677 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 678 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 679 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 680 | } |
| 681 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 682 | struct weston_frame_callback { |
| 683 | struct wl_resource resource; |
| 684 | struct wl_list link; |
| 685 | }; |
| 686 | |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 687 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 688 | destroy_surface(struct wl_resource *resource) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 689 | { |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 690 | int i; |
| 691 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 692 | struct weston_surface *surface = |
| 693 | container_of(resource, |
| 694 | struct weston_surface, surface.resource); |
| 695 | struct weston_compositor *compositor = surface->compositor; |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 696 | struct weston_frame_callback *cb, *next; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 697 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 698 | if (weston_surface_is_mapped(surface)) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 699 | weston_surface_unmap(surface); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 700 | |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 701 | glDeleteTextures(surface->num_textures, surface->textures); |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 702 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 703 | if (surface->buffer) |
| 704 | wl_list_remove(&surface->buffer_destroy_listener.link); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 705 | |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 706 | for (i = 0; i < surface->num_images; i++) |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 707 | compositor->destroy_image(compositor->egl_display, |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 708 | surface->images[i]); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 709 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 710 | pixman_region32_fini(&surface->transform.boundingbox); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 711 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 712 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 713 | pixman_region32_fini(&surface->clip); |
Kristian Høgsberg | dd631c1 | 2012-02-23 16:20:38 -0500 | [diff] [blame] | 714 | if (!region_is_undefined(&surface->input)) |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 715 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 716 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 717 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
| 718 | wl_resource_destroy(&cb->resource); |
| 719 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 720 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 721 | } |
| 722 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 723 | WL_EXPORT void |
| 724 | weston_surface_destroy(struct weston_surface *surface) |
| 725 | { |
| 726 | /* Not a valid way to destroy a client surface */ |
| 727 | assert(surface->surface.resource.client == NULL); |
| 728 | |
Kristian Høgsberg | 9a050af | 2012-06-07 18:17:42 -0400 | [diff] [blame] | 729 | wl_signal_emit(&surface->surface.resource.destroy_signal, |
| 730 | &surface->surface.resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 731 | destroy_surface(&surface->surface.resource); |
| 732 | } |
| 733 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 734 | static void |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 735 | ensure_textures(struct weston_surface *es, int num_textures) |
| 736 | { |
| 737 | int i; |
| 738 | |
| 739 | if (num_textures <= es->num_textures) |
| 740 | return; |
| 741 | |
| 742 | for (i = es->num_textures; i < num_textures; i++) { |
| 743 | glGenTextures(1, &es->textures[i]); |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 744 | glBindTexture(es->target, es->textures[i]); |
| 745 | glTexParameteri(es->target, |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 746 | GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 747 | glTexParameteri(es->target, |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 748 | GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 749 | } |
| 750 | es->num_textures = num_textures; |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 751 | glBindTexture(es->target, 0); |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | static void |
Kristian Høgsberg | 8cbfb2a | 2012-03-27 17:04:59 -0400 | [diff] [blame] | 755 | weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 756 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 757 | struct weston_surface *es = (struct weston_surface *) surface; |
| 758 | struct weston_compositor *ec = es->compositor; |
Kristian Høgsberg | 905d7ce | 2012-07-19 14:20:20 -0400 | [diff] [blame] | 759 | EGLint attribs[3], format; |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 760 | int i, num_planes; |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 761 | |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 762 | if (es->buffer) { |
| 763 | weston_buffer_post_release(es->buffer); |
| 764 | wl_list_remove(&es->buffer_destroy_listener.link); |
| 765 | } |
| 766 | |
| 767 | es->buffer = buffer; |
| 768 | |
| 769 | if (!buffer) { |
| 770 | if (weston_surface_is_mapped(es)) |
| 771 | weston_surface_unmap(es); |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 772 | for (i = 0; i < es->num_images; i++) { |
| 773 | ec->destroy_image(ec->egl_display, es->images[i]); |
| 774 | es->images[i] = NULL; |
Kristian Høgsberg | b8ceaaa | 2012-06-19 15:41:12 -0400 | [diff] [blame] | 775 | } |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 776 | es->num_images = 0; |
| 777 | glDeleteTextures(es->num_textures, es->textures); |
| 778 | es->num_textures = 0; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 779 | return; |
| 780 | } |
| 781 | |
| 782 | buffer->busy_count++; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 783 | wl_signal_add(&es->buffer->resource.destroy_signal, |
| 784 | &es->buffer_destroy_listener); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 785 | |
| 786 | if (es->geometry.width != buffer->width || |
| 787 | es->geometry.height != buffer->height) { |
| 788 | undef_region(&es->input); |
| 789 | pixman_region32_fini(&es->opaque); |
| 790 | pixman_region32_init(&es->opaque); |
| 791 | } |
| 792 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 793 | if (wl_buffer_is_shm(buffer)) { |
Benjamin Franzke | fab5ec1 | 2011-04-25 19:44:47 +0200 | [diff] [blame] | 794 | es->pitch = wl_shm_buffer_get_stride(buffer) / 4; |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 795 | es->target = GL_TEXTURE_2D; |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 796 | |
| 797 | ensure_textures(es, 1); |
| 798 | glBindTexture(GL_TEXTURE_2D, es->textures[0]); |
Kristian Høgsberg | fb6de22 | 2012-03-27 17:10:13 -0400 | [diff] [blame] | 799 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, |
| 800 | es->pitch, es->buffer->height, 0, |
| 801 | GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL); |
Kristian Høgsberg | d6ad122 | 2012-05-17 11:11:15 -0400 | [diff] [blame] | 802 | if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888) |
Pekka Paalanen | 6b5585b | 2012-08-30 16:47:19 -0500 | [diff] [blame] | 803 | es->shader = &ec->texture_shader_rgbx; |
Kristian Høgsberg | d6ad122 | 2012-05-17 11:11:15 -0400 | [diff] [blame] | 804 | else |
Pekka Paalanen | 6b5585b | 2012-08-30 16:47:19 -0500 | [diff] [blame] | 805 | es->shader = &ec->texture_shader_rgba; |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 806 | } else if (ec->query_buffer(ec->egl_display, buffer, |
Kristian Høgsberg | 905d7ce | 2012-07-19 14:20:20 -0400 | [diff] [blame] | 807 | EGL_TEXTURE_FORMAT, &format)) { |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 808 | for (i = 0; i < es->num_images; i++) |
Kristian Høgsberg | 971cbc8 | 2012-07-17 14:21:25 -0400 | [diff] [blame] | 809 | ec->destroy_image(ec->egl_display, es->images[i]); |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 810 | es->num_images = 0; |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 811 | es->target = GL_TEXTURE_2D; |
Kristian Høgsberg | 905d7ce | 2012-07-19 14:20:20 -0400 | [diff] [blame] | 812 | switch (format) { |
| 813 | case EGL_TEXTURE_RGB: |
| 814 | case EGL_TEXTURE_RGBA: |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 815 | default: |
| 816 | num_planes = 1; |
| 817 | es->shader = &ec->texture_shader_rgba; |
| 818 | break; |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 819 | case EGL_TEXTURE_EXTERNAL_WL: |
| 820 | num_planes = 1; |
| 821 | es->target = GL_TEXTURE_EXTERNAL_OES; |
| 822 | es->shader = &ec->texture_shader_egl_external; |
| 823 | break; |
Kristian Høgsberg | 905d7ce | 2012-07-19 14:20:20 -0400 | [diff] [blame] | 824 | case EGL_TEXTURE_Y_UV_WL: |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 825 | num_planes = 2; |
| 826 | es->shader = &ec->texture_shader_y_uv; |
| 827 | break; |
Kristian Høgsberg | 905d7ce | 2012-07-19 14:20:20 -0400 | [diff] [blame] | 828 | case EGL_TEXTURE_Y_U_V_WL: |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 829 | num_planes = 3; |
| 830 | es->shader = &ec->texture_shader_y_u_v; |
| 831 | break; |
Kristian Høgsberg | 905d7ce | 2012-07-19 14:20:20 -0400 | [diff] [blame] | 832 | case EGL_TEXTURE_Y_XUXV_WL: |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 833 | num_planes = 2; |
| 834 | es->shader = &ec->texture_shader_y_xuxv; |
| 835 | break; |
| 836 | } |
| 837 | |
| 838 | ensure_textures(es, num_planes); |
| 839 | for (i = 0; i < num_planes; i++) { |
| 840 | attribs[0] = EGL_WAYLAND_PLANE_WL; |
| 841 | attribs[1] = i; |
| 842 | attribs[2] = EGL_NONE; |
| 843 | es->images[i] = ec->create_image(ec->egl_display, |
| 844 | NULL, |
| 845 | EGL_WAYLAND_BUFFER_WL, |
| 846 | buffer, attribs); |
Rob Clark | 48cd58b | 2012-08-13 17:39:17 -0500 | [diff] [blame] | 847 | if (!es->images[i]) { |
| 848 | weston_log("failed to create img for plane %d\n", i); |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 849 | continue; |
Rob Clark | 48cd58b | 2012-08-13 17:39:17 -0500 | [diff] [blame] | 850 | } |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 851 | es->num_images++; |
| 852 | |
| 853 | glActiveTexture(GL_TEXTURE0 + i); |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 854 | glBindTexture(es->target, es->textures[i]); |
| 855 | ec->image_target_texture_2d(es->target, |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 856 | es->images[i]); |
| 857 | } |
Kristian Høgsberg | f389cac | 2011-08-31 16:21:38 -0400 | [diff] [blame] | 858 | |
Ander Conselvan de Oliveira | 9390ae3 | 2012-03-27 17:36:38 +0300 | [diff] [blame] | 859 | es->pitch = buffer->width; |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 860 | } else { |
Rob Clark | 48cd58b | 2012-08-13 17:39:17 -0500 | [diff] [blame] | 861 | weston_log("unhandled buffer type!\n"); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 865 | |
| 866 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
| 867 | #define min(a, b) (((a) > (b)) ? (b) : (a)) |
| 868 | #define clip(x, a, b) min(max(x, a), b) |
| 869 | #define sign(x) ((x) >= 0) |
| 870 | |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 871 | static int |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 872 | calculate_edges(struct weston_surface *es, pixman_box32_t *rect, |
| 873 | pixman_box32_t *surf_rect, GLfloat *ex, GLfloat *ey) |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 874 | { |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 875 | int i, n = 0; |
| 876 | GLfloat min_x, max_x, min_y, max_y; |
| 877 | GLfloat x[4] = { |
| 878 | surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1, |
| 879 | }; |
| 880 | GLfloat y[4] = { |
| 881 | surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2, |
| 882 | }; |
| 883 | GLfloat cx1 = rect->x1; |
| 884 | GLfloat cx2 = rect->x2; |
| 885 | GLfloat cy1 = rect->y1; |
| 886 | GLfloat cy2 = rect->y2; |
Kristian Høgsberg | 525e4c0 | 2011-02-14 10:39:54 -0500 | [diff] [blame] | 887 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 888 | GLfloat dist_squared(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) |
| 889 | { |
| 890 | GLfloat dx = (x1 - x2); |
| 891 | GLfloat dy = (y1 - y2); |
| 892 | return dx * dx + dy * dy; |
| 893 | } |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 894 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 895 | void append_vertex(GLfloat x, GLfloat y) |
| 896 | { |
| 897 | /* don't emit duplicate vertices: */ |
| 898 | if ((n > 0) && (ex[n-1] == x) && (ey[n-1] == y)) |
| 899 | return; |
| 900 | ex[n] = x; |
| 901 | ey[n] = y; |
| 902 | n++; |
| 903 | } |
Kristian Høgsberg | fa4e2a7 | 2011-02-13 13:44:55 -0500 | [diff] [blame] | 904 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 905 | /* transform surface to screen space: */ |
| 906 | for (i = 0; i < 4; i++) |
| 907 | weston_surface_to_global_float(es, x[i], y[i], &x[i], &y[i]); |
Kristian Høgsberg | fa4e2a7 | 2011-02-13 13:44:55 -0500 | [diff] [blame] | 908 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 909 | /* find bounding box: */ |
| 910 | min_x = max_x = x[0]; |
| 911 | min_y = max_y = y[0]; |
Kristian Høgsberg | fa4e2a7 | 2011-02-13 13:44:55 -0500 | [diff] [blame] | 912 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 913 | for (i = 1; i < 4; i++) { |
| 914 | min_x = min(min_x, x[i]); |
| 915 | max_x = max(max_x, x[i]); |
| 916 | min_y = min(min_y, y[i]); |
| 917 | max_y = max(max_y, y[i]); |
| 918 | } |
Kristian Høgsberg | 525e4c0 | 2011-02-14 10:39:54 -0500 | [diff] [blame] | 919 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 920 | /* First, simple bounding box check to discard early transformed |
| 921 | * surface rects that do not intersect with the clip region: |
| 922 | */ |
| 923 | if ((min_x > cx2) || (max_x < cx1) || |
| 924 | (min_y > cy2) || (max_y < cy1)) |
| 925 | return 0; |
| 926 | |
| 927 | /* Simple case, bounding box edges are parallel to surface edges, |
| 928 | * there will be only four edges. We just need to clip the surface |
| 929 | * vertices to the clip rect bounds: |
| 930 | */ |
| 931 | if (!es->transform.enabled) { |
| 932 | for (i = 0; i < 4; i++) { |
| 933 | ex[n] = clip(x[i], cx1, cx2); |
| 934 | ey[n] = clip(y[i], cy1, cy2); |
| 935 | n++; |
| 936 | } |
| 937 | return 4; |
| 938 | } |
| 939 | |
| 940 | /* Hard case, transformation applied. We need to find the vertices |
| 941 | * of the shape that is the intersection of the clip rect and |
| 942 | * transformed surface. This can be anything from 3 to 8 sides. |
| 943 | * |
| 944 | * Observation: all the resulting vertices will be the intersection |
| 945 | * points of the transformed surface and the clip rect, plus the |
| 946 | * vertices of the clip rect which are enclosed by the transformed |
| 947 | * surface and the vertices of the transformed surface which are |
| 948 | * enclosed by the clip rect. |
| 949 | * |
| 950 | * Observation: there will be zero, one, or two resulting vertices |
| 951 | * for each edge of the src rect. |
| 952 | * |
| 953 | * Loop over four edges of the transformed rect: |
| 954 | */ |
| 955 | for (i = 0; i < 4; i++) { |
| 956 | GLfloat x1, y1, x2, y2; |
| 957 | int last_n = n; |
| 958 | |
| 959 | x1 = x[i]; |
| 960 | y1 = y[i]; |
| 961 | |
| 962 | /* if this vertex is contained in the clip rect, use it as-is: */ |
| 963 | if ((cx1 <= x1) && (x1 <= cx2) && |
| 964 | (cy1 <= y1) && (y1 <= cy2)) |
| 965 | append_vertex(x1, y1); |
| 966 | |
| 967 | /* for remaining, we consider the point as part of a line: */ |
| 968 | x2 = x[(i+1) % 4]; |
| 969 | y2 = y[(i+1) % 4]; |
| 970 | |
| 971 | if (x1 == x2) { |
| 972 | append_vertex(clip(x1, cx1, cx2), clip(y1, cy1, cy2)); |
| 973 | append_vertex(clip(x2, cx1, cx2), clip(y2, cy1, cy2)); |
| 974 | } else if (y1 == y2) { |
| 975 | append_vertex(clip(x1, cx1, cx2), clip(y1, cy1, cy2)); |
| 976 | append_vertex(clip(x2, cx1, cx2), clip(y2, cy1, cy2)); |
| 977 | } else { |
| 978 | GLfloat m, c, p; |
| 979 | GLfloat tx[2], ty[2]; |
| 980 | int tn = 0; |
| 981 | |
| 982 | int intersect_horiz(GLfloat y, GLfloat *p) |
| 983 | { |
| 984 | GLfloat x; |
| 985 | |
| 986 | /* if y does not lie between y1 and y2, no |
| 987 | * intersection possible |
| 988 | */ |
| 989 | if (sign(y-y1) == sign(y-y2)) |
| 990 | return 0; |
| 991 | |
| 992 | x = (y - c) / m; |
| 993 | |
| 994 | /* if x does not lie between cx1 and cx2, no |
| 995 | * intersection: |
| 996 | */ |
| 997 | if (sign(x-cx1) == sign(x-cx2)) |
| 998 | return 0; |
| 999 | |
| 1000 | *p = x; |
| 1001 | return 1; |
| 1002 | } |
| 1003 | |
| 1004 | int intersect_vert(GLfloat x, GLfloat *p) |
| 1005 | { |
| 1006 | GLfloat y; |
| 1007 | |
| 1008 | if (sign(x-x1) == sign(x-x2)) |
| 1009 | return 0; |
| 1010 | |
| 1011 | y = m * x + c; |
| 1012 | |
| 1013 | if (sign(y-cy1) == sign(y-cy2)) |
| 1014 | return 0; |
| 1015 | |
| 1016 | *p = y; |
| 1017 | return 1; |
| 1018 | } |
| 1019 | |
| 1020 | /* y = mx + c */ |
| 1021 | m = (y2 - y1) / (x2 - x1); |
| 1022 | c = y1 - m * x1; |
| 1023 | |
| 1024 | /* check for up to two intersections with the four edges |
| 1025 | * of the clip rect. Note that we don't know the orientation |
| 1026 | * of the transformed surface wrt. the clip rect. So if when |
| 1027 | * there are two intersection points, we need to put the one |
| 1028 | * closest to x1,y1 first: |
| 1029 | */ |
| 1030 | |
| 1031 | /* check top clip rect edge: */ |
| 1032 | if (intersect_horiz(cy1, &p)) { |
| 1033 | ty[tn] = cy1; |
| 1034 | tx[tn] = p; |
| 1035 | tn++; |
| 1036 | } |
| 1037 | |
| 1038 | /* check right clip rect edge: */ |
| 1039 | if (intersect_vert(cx2, &p)) { |
| 1040 | ty[tn] = p; |
| 1041 | tx[tn] = cx2; |
| 1042 | tn++; |
| 1043 | if (tn == 2) |
| 1044 | goto edge_check_done; |
| 1045 | } |
| 1046 | |
| 1047 | /* check bottom clip rect edge: */ |
| 1048 | if (intersect_horiz(cy2, &p)) { |
| 1049 | ty[tn] = cy2; |
| 1050 | tx[tn] = p; |
| 1051 | tn++; |
| 1052 | if (tn == 2) |
| 1053 | goto edge_check_done; |
| 1054 | } |
| 1055 | |
| 1056 | /* check left clip rect edge: */ |
| 1057 | if (intersect_vert(cx1, &p)) { |
| 1058 | ty[tn] = p; |
| 1059 | tx[tn] = cx1; |
| 1060 | tn++; |
| 1061 | } |
| 1062 | |
| 1063 | edge_check_done: |
| 1064 | if (tn == 1) { |
| 1065 | append_vertex(tx[0], ty[0]); |
| 1066 | } else if (tn == 2) { |
| 1067 | if (dist_squared(x1, y1, tx[0], ty[0]) < |
| 1068 | dist_squared(x1, y1, tx[1], ty[1])) { |
| 1069 | append_vertex(tx[0], ty[0]); |
| 1070 | append_vertex(tx[1], ty[1]); |
| 1071 | } else { |
| 1072 | append_vertex(tx[1], ty[1]); |
| 1073 | append_vertex(tx[0], ty[0]); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | if (n == last_n) { |
| 1078 | GLfloat best_x=0, best_y=0; |
| 1079 | uint32_t d, best_d = (unsigned int)-1; /* distance squared */ |
| 1080 | uint32_t max_d = dist_squared(x2, y2, |
| 1081 | x[(i+2) % 4], y[(i+2) % 4]); |
| 1082 | |
| 1083 | /* if there are no vertices on this line, it could be that |
| 1084 | * there is a vertex of the clip rect that is enclosed by |
| 1085 | * the transformed surface. Find the vertex of the clip |
| 1086 | * rect that is reached by the shortest line perpendicular |
| 1087 | * to the current edge, if any. |
| 1088 | * |
| 1089 | * slope of perpendicular is 1/m, so |
| 1090 | * |
| 1091 | * cy = -cx/m + c2 |
| 1092 | * c2 = cy + cx/m |
| 1093 | * |
| 1094 | */ |
| 1095 | |
| 1096 | int perp_intersect(GLfloat cx, GLfloat cy, uint32_t *d) |
| 1097 | { |
| 1098 | GLfloat c2 = cy + cx/m; |
| 1099 | GLfloat x = (c2 - c) / (m + 1/m); |
| 1100 | |
| 1101 | /* if the x position of the intersection of the |
| 1102 | * perpendicular with the transformed edge does |
| 1103 | * not lie within the bounds of the edge, then |
| 1104 | * no intersection: |
| 1105 | */ |
| 1106 | if (sign(x-x1) == sign(x-x2)) |
| 1107 | return 0; |
| 1108 | |
| 1109 | *d = dist_squared(cx, cy, x, (m * x) + c); |
| 1110 | |
| 1111 | /* if intersection distance is further away than |
| 1112 | * opposite edge of surface region, it is invalid: |
| 1113 | */ |
| 1114 | if (*d > max_d) |
| 1115 | return 0; |
| 1116 | |
| 1117 | return 1; |
| 1118 | } |
| 1119 | |
| 1120 | if (perp_intersect(cx1, cy1, &d)) { |
| 1121 | best_x = cx1; |
| 1122 | best_y = cy1; |
| 1123 | best_d = d; |
| 1124 | } |
| 1125 | |
| 1126 | if (perp_intersect(cx1, cy2, &d) && (d < best_d)) { |
| 1127 | best_x = cx1; |
| 1128 | best_y = cy2; |
| 1129 | best_d = d; |
| 1130 | } |
| 1131 | |
| 1132 | if (perp_intersect(cx2, cy2, &d) && (d < best_d)) { |
| 1133 | best_x = cx2; |
| 1134 | best_y = cy2; |
| 1135 | best_d = d; |
| 1136 | } |
| 1137 | |
| 1138 | if (perp_intersect(cx2, cy1, &d) && (d < best_d)) { |
| 1139 | best_x = cx2; |
| 1140 | best_y = cy1; |
| 1141 | best_d = d; |
| 1142 | } |
| 1143 | |
| 1144 | if (best_d != (unsigned int)-1) // XXX can this happen? |
| 1145 | append_vertex(best_x, best_y); |
| 1146 | } |
| 1147 | } |
| 1148 | |
Kristian Høgsberg | 525e4c0 | 2011-02-14 10:39:54 -0500 | [diff] [blame] | 1149 | } |
Kristian Høgsberg | fa4e2a7 | 2011-02-13 13:44:55 -0500 | [diff] [blame] | 1150 | |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1151 | return n; |
| 1152 | } |
| 1153 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1154 | static int |
| 1155 | texture_region(struct weston_surface *es, pixman_region32_t *region, |
| 1156 | pixman_region32_t *surf_region) |
| 1157 | { |
| 1158 | struct weston_compositor *ec = es->compositor; |
| 1159 | GLfloat *v, inv_width, inv_height; |
| 1160 | unsigned int *vtxcnt, nvtx = 0; |
| 1161 | pixman_box32_t *rects, *surf_rects; |
| 1162 | int i, j, k, nrects, nsurf; |
| 1163 | |
| 1164 | rects = pixman_region32_rectangles(region, &nrects); |
| 1165 | surf_rects = pixman_region32_rectangles(surf_region, &nsurf); |
| 1166 | |
| 1167 | /* worst case we can have 10 vertices per rect (ie. clipped into |
| 1168 | * an octagon): |
| 1169 | */ |
| 1170 | v = wl_array_add(&ec->vertices, nrects * nsurf * 10 * 4 * sizeof *v); |
| 1171 | vtxcnt = wl_array_add(&ec->vtxcnt, nrects * nsurf * sizeof *vtxcnt); |
| 1172 | |
| 1173 | inv_width = 1.0 / es->pitch; |
| 1174 | inv_height = 1.0 / es->geometry.height; |
| 1175 | |
| 1176 | for (i = 0; i < nrects; i++) { |
| 1177 | pixman_box32_t *rect = &rects[i]; |
| 1178 | for (j = 0; j < nsurf; j++) { |
| 1179 | pixman_box32_t *surf_rect = &surf_rects[j]; |
| 1180 | GLfloat cx, cy; |
| 1181 | GLfloat ex[8], ey[8]; /* edge points in screen space */ |
| 1182 | int n; |
| 1183 | |
| 1184 | void emit_vertex(GLfloat gx, GLfloat gy) |
| 1185 | { |
| 1186 | GLfloat sx, sy; |
| 1187 | surface_from_global_float(es, gx, gy, &sx, &sy); |
| 1188 | /* In groups of 4 attributes, first two are 'position', 2nd two |
| 1189 | * are 'texcoord'. |
| 1190 | */ |
| 1191 | *(v++) = gx; |
| 1192 | *(v++) = gy; |
| 1193 | *(v++) = sx * inv_width; |
| 1194 | *(v++) = sy * inv_height; |
| 1195 | } |
| 1196 | |
| 1197 | /* The transformed surface, after clipping to the clip region, |
| 1198 | * can have as many as eight sides, emitted as a triangle-fan. |
| 1199 | * The first vertex is the center, followed by each corner. |
| 1200 | * |
| 1201 | * If a corner of the transformed surface falls outside of the |
| 1202 | * clip region, instead of emitting one vertex for the corner |
| 1203 | * of the surface, up to two are emitted for two corresponding |
| 1204 | * intersection point(s) between the surface and the clip region. |
| 1205 | * |
| 1206 | * To do this, we first calculate the (up to eight) points that |
| 1207 | * form the intersection of the clip rect and the transformed |
| 1208 | * surface. After that we calculate the average to determine |
| 1209 | * the center point, and emit the center and edge vertices of |
| 1210 | * the fan. |
| 1211 | */ |
| 1212 | n = calculate_edges(es, rect, surf_rect, ex, ey); |
| 1213 | if (n < 3) |
| 1214 | continue; |
| 1215 | |
| 1216 | /* calculate/emit center point: */ |
| 1217 | cx = 0; |
| 1218 | cy = 0; |
| 1219 | for (k = 0; k < n; k++) { |
| 1220 | cx += ex[k]; |
| 1221 | cy += ey[k]; |
| 1222 | } |
| 1223 | cx /= n; |
| 1224 | cy /= n; |
| 1225 | emit_vertex(cx, cy); |
| 1226 | |
| 1227 | /* then emit edge points: */ |
| 1228 | for (k = 0; k < n; k++) |
| 1229 | emit_vertex(ex[k], ey[k]); |
| 1230 | |
| 1231 | /* and close the fan: */ |
| 1232 | emit_vertex(ex[0], ey[0]); |
| 1233 | |
| 1234 | vtxcnt[nvtx++] = n + 2; |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | return nvtx; |
| 1239 | } |
| 1240 | |
| 1241 | static void |
Pekka Paalanen | 07c91f8 | 2012-08-30 16:47:21 -0500 | [diff] [blame^] | 1242 | triangle_fan_debug(struct weston_surface *surface, int first, int count) |
| 1243 | { |
| 1244 | struct weston_compositor *compositor = surface->compositor; |
| 1245 | int i; |
| 1246 | GLushort *buffer; |
| 1247 | GLushort *index; |
| 1248 | int nelems; |
| 1249 | static int color_idx = 0; |
| 1250 | static const GLfloat color[][4] = { |
| 1251 | { 1.0, 0.0, 0.0, 1.0 }, |
| 1252 | { 0.0, 1.0, 0.0, 1.0 }, |
| 1253 | { 0.0, 0.0, 1.0, 1.0 }, |
| 1254 | { 1.0, 1.0, 1.0, 1.0 }, |
| 1255 | }; |
| 1256 | |
| 1257 | nelems = (count - 1 + count - 2) * 2; |
| 1258 | |
| 1259 | buffer = malloc(sizeof(GLushort) * nelems); |
| 1260 | index = buffer; |
| 1261 | |
| 1262 | for (i = 1; i < count; i++) { |
| 1263 | *index++ = first; |
| 1264 | *index++ = first + i; |
| 1265 | } |
| 1266 | |
| 1267 | for (i = 2; i < count; i++) { |
| 1268 | *index++ = first + i - 1; |
| 1269 | *index++ = first + i; |
| 1270 | } |
| 1271 | |
| 1272 | glUseProgram(compositor->solid_shader.program); |
| 1273 | glUniform4fv(compositor->solid_shader.color_uniform, 1, |
| 1274 | color[color_idx++ % ARRAY_SIZE(color)]); |
| 1275 | glDrawElements(GL_LINES, nelems, GL_UNSIGNED_SHORT, buffer); |
| 1276 | glUseProgram(surface->shader->program); |
| 1277 | free(buffer); |
| 1278 | } |
| 1279 | |
| 1280 | static void |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1281 | repaint_region(struct weston_surface *es, pixman_region32_t *region, |
| 1282 | pixman_region32_t *surf_region) |
| 1283 | { |
| 1284 | struct weston_compositor *ec = es->compositor; |
| 1285 | GLfloat *v; |
| 1286 | unsigned int *vtxcnt; |
| 1287 | int i, first, nfans; |
| 1288 | |
| 1289 | /* The final region to be painted is the intersection of |
| 1290 | * 'region' and 'surf_region'. However, 'region' is in the global |
| 1291 | * coordinates, and 'surf_region' is in the surface-local |
| 1292 | * corodinates. texture_region() will iterate over all pairs of |
| 1293 | * rectangles from both regions, compute the intersection |
| 1294 | * polygon for each pair, and store it as a triangle fan if |
| 1295 | * it has a non-zero area. |
| 1296 | */ |
| 1297 | nfans = texture_region(es, region, surf_region); |
| 1298 | |
| 1299 | v = ec->vertices.data; |
| 1300 | vtxcnt = ec->vtxcnt.data; |
| 1301 | |
| 1302 | /* position: */ |
| 1303 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]); |
| 1304 | glEnableVertexAttribArray(0); |
| 1305 | |
| 1306 | /* texcoord: */ |
| 1307 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]); |
| 1308 | glEnableVertexAttribArray(1); |
| 1309 | |
| 1310 | for (i = 0, first = 0; i < nfans; i++) { |
| 1311 | glDrawArrays(GL_TRIANGLE_FAN, first, vtxcnt[i]); |
Pekka Paalanen | 07c91f8 | 2012-08-30 16:47:21 -0500 | [diff] [blame^] | 1312 | if (ec->fan_debug) |
| 1313 | triangle_fan_debug(es, first, vtxcnt[i]); |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1314 | first += vtxcnt[i]; |
| 1315 | } |
| 1316 | |
| 1317 | glDisableVertexAttribArray(1); |
| 1318 | glDisableVertexAttribArray(0); |
| 1319 | |
| 1320 | ec->vertices.size = 0; |
| 1321 | ec->vtxcnt.size = 0; |
| 1322 | } |
| 1323 | |
| 1324 | |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 1325 | WL_EXPORT void |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1326 | weston_surface_draw(struct weston_surface *es, struct weston_output *output, |
Pekka Paalanen | 8a15bb8 | 2012-08-30 16:47:20 -0500 | [diff] [blame] | 1327 | pixman_region32_t *damage) /* in global coordinates */ |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1328 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1329 | struct weston_compositor *ec = es->compositor; |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1330 | /* repaint bounding region in global coordinates: */ |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1331 | pixman_region32_t repaint; |
Pekka Paalanen | 8a15bb8 | 2012-08-30 16:47:20 -0500 | [diff] [blame] | 1332 | /* non-opaque region in surface coordinates: */ |
| 1333 | pixman_region32_t surface_blend; |
Kristian Høgsberg | 40caded | 2011-06-20 19:48:16 -0400 | [diff] [blame] | 1334 | GLint filter; |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1335 | int i; |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1336 | |
Pekka Paalanen | a9f8a21 | 2012-01-26 11:28:08 +0200 | [diff] [blame] | 1337 | pixman_region32_init(&repaint); |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1338 | pixman_region32_init(&surface_blend); |
| 1339 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1340 | pixman_region32_intersect(&repaint, |
| 1341 | &es->transform.boundingbox, damage); |
| 1342 | pixman_region32_subtract(&repaint, &repaint, &es->clip); |
Pekka Paalanen | c7b45f6 | 2012-02-06 12:16:07 +0200 | [diff] [blame] | 1343 | |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1344 | if (!pixman_region32_not_empty(&repaint)) |
Pekka Paalanen | a9f8a21 | 2012-01-26 11:28:08 +0200 | [diff] [blame] | 1345 | goto out; |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1346 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1347 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 1348 | &ec->primary_plane.damage, &repaint); |
| 1349 | |
Kristian Høgsberg | 101cb65 | 2012-02-17 10:45:16 -0500 | [diff] [blame] | 1350 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
Pekka Paalanen | 8a15bb8 | 2012-08-30 16:47:20 -0500 | [diff] [blame] | 1351 | |
| 1352 | /* blended region is whole surface minus opaque region: */ |
| 1353 | pixman_region32_init_rect(&surface_blend, 0, 0, |
| 1354 | es->geometry.width, es->geometry.height); |
| 1355 | if (es->alpha >= 1.0) |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1356 | pixman_region32_subtract(&surface_blend, &surface_blend, |
Pekka Paalanen | 8a15bb8 | 2012-08-30 16:47:20 -0500 | [diff] [blame] | 1357 | &es->opaque); |
Kristian Høgsberg | 2e94d11 | 2011-05-02 13:47:51 -0400 | [diff] [blame] | 1358 | |
Kristian Høgsberg | 0763262 | 2012-01-25 23:02:06 -0500 | [diff] [blame] | 1359 | if (ec->current_shader != es->shader) { |
| 1360 | glUseProgram(es->shader->program); |
Kristian Høgsberg | 0763262 | 2012-01-25 23:02:06 -0500 | [diff] [blame] | 1361 | ec->current_shader = es->shader; |
| 1362 | } |
| 1363 | |
Kristian Høgsberg | 0452abc | 2012-01-31 15:38:36 -0500 | [diff] [blame] | 1364 | glUniformMatrix4fv(es->shader->proj_uniform, |
| 1365 | 1, GL_FALSE, output->matrix.d); |
Pekka Paalanen | f55f544 | 2012-02-02 16:49:05 +0200 | [diff] [blame] | 1366 | glUniform4fv(es->shader->color_uniform, 1, es->color); |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 1367 | glUniform1f(es->shader->alpha_uniform, es->alpha); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1368 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1369 | if (es->transform.enabled || output->zoom.active) |
Kristian Høgsberg | 40caded | 2011-06-20 19:48:16 -0400 | [diff] [blame] | 1370 | filter = GL_LINEAR; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1371 | else |
Pekka Paalanen | c61eca6 | 2012-01-06 14:10:06 +0200 | [diff] [blame] | 1372 | filter = GL_NEAREST; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1373 | |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 1374 | for (i = 0; i < es->num_textures; i++) { |
| 1375 | glUniform1i(es->shader->tex_uniforms[i], i); |
| 1376 | glActiveTexture(GL_TEXTURE0 + i); |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 1377 | glBindTexture(es->target, es->textures[i]); |
| 1378 | glTexParameteri(es->target, GL_TEXTURE_MIN_FILTER, filter); |
| 1379 | glTexParameteri(es->target, GL_TEXTURE_MAG_FILTER, filter); |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 1380 | } |
Kristian Høgsberg | 40caded | 2011-06-20 19:48:16 -0400 | [diff] [blame] | 1381 | |
Pekka Paalanen | 8a15bb8 | 2012-08-30 16:47:20 -0500 | [diff] [blame] | 1382 | if (pixman_region32_not_empty(&es->opaque) && es->alpha >= 1.0) { |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1383 | glDisable(GL_BLEND); |
Pekka Paalanen | 8a15bb8 | 2012-08-30 16:47:20 -0500 | [diff] [blame] | 1384 | repaint_region(es, &repaint, &es->opaque); |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1385 | } |
Pekka Paalanen | 3df327f | 2012-01-24 15:53:35 +0200 | [diff] [blame] | 1386 | |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1387 | if (pixman_region32_not_empty(&surface_blend)) { |
| 1388 | glEnable(GL_BLEND); |
| 1389 | repaint_region(es, &repaint, &surface_blend); |
| 1390 | } |
Pekka Paalanen | a9f8a21 | 2012-01-26 11:28:08 +0200 | [diff] [blame] | 1391 | |
| 1392 | out: |
Kristian Høgsberg | 525e4c0 | 2011-02-14 10:39:54 -0500 | [diff] [blame] | 1393 | pixman_region32_fini(&repaint); |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 1394 | pixman_region32_fini(&surface_blend); |
Kristian Høgsberg | 4c9f2c9 | 2008-11-21 19:25:44 -0500 | [diff] [blame] | 1395 | } |
| 1396 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1397 | WL_EXPORT void |
| 1398 | weston_surface_restack(struct weston_surface *surface, struct wl_list *below) |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1399 | { |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1400 | wl_list_remove(&surface->layer_link); |
| 1401 | wl_list_insert(below, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1402 | weston_surface_damage_below(surface); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1403 | weston_surface_damage(surface); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1404 | } |
| 1405 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1406 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1407 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1408 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1409 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1410 | |
| 1411 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1412 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 1415 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1416 | weston_buffer_post_release(struct wl_buffer *buffer) |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 1417 | { |
Kristian Høgsberg | 2459694 | 2011-10-24 17:51:02 -0400 | [diff] [blame] | 1418 | if (--buffer->busy_count > 0) |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 1419 | return; |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 1420 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1421 | assert(buffer->resource.client != NULL); |
Kristian Høgsberg | eccef6a | 2011-11-17 16:46:19 -0500 | [diff] [blame] | 1422 | wl_resource_queue_event(&buffer->resource, WL_BUFFER_RELEASE); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1425 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1426 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1427 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1428 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1429 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1430 | pixman_region32_union(&compositor->primary_plane.damage, |
| 1431 | &compositor->primary_plane.damage, |
| 1432 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1433 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1436 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1437 | fade_frame(struct weston_animation *animation, |
| 1438 | struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1439 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1440 | struct weston_compositor *compositor = |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1441 | container_of(animation, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1442 | struct weston_compositor, fade.animation); |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1443 | struct weston_surface *surface; |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1444 | |
Scott Moreau | 94b0b0c | 2012-06-14 01:01:56 -0600 | [diff] [blame] | 1445 | if (animation->frame_counter <= 1) |
Scott Moreau | e2949db | 2012-06-11 13:09:23 -0600 | [diff] [blame] | 1446 | compositor->fade.spring.timestamp = msecs; |
| 1447 | |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1448 | surface = compositor->fade.surface; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1449 | weston_spring_update(&compositor->fade.spring, msecs); |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1450 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, |
| 1451 | compositor->fade.spring.current); |
| 1452 | weston_surface_damage(surface); |
| 1453 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1454 | if (weston_spring_done(&compositor->fade.spring)) { |
Kristian Høgsberg | 269c782 | 2011-05-02 14:38:18 -0400 | [diff] [blame] | 1455 | compositor->fade.spring.current = |
| 1456 | compositor->fade.spring.target; |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1457 | wl_list_remove(&animation->link); |
| 1458 | wl_list_init(&animation->link); |
Pekka Paalanen | 2e097ee | 2011-12-02 10:39:49 +0200 | [diff] [blame] | 1459 | |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1460 | if (compositor->fade.spring.current < 0.001) { |
| 1461 | destroy_surface(&surface->surface.resource); |
| 1462 | compositor->fade.surface = NULL; |
| 1463 | } else if (compositor->fade.spring.current > 0.999) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1464 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1465 | wl_signal_emit(&compositor->lock_signal, compositor); |
Pekka Paalanen | 2e097ee | 2011-12-02 10:39:49 +0200 | [diff] [blame] | 1466 | } |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1467 | } |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1470 | static void |
| 1471 | update_shm_texture(struct weston_surface *surface) |
| 1472 | { |
| 1473 | #ifdef GL_UNPACK_ROW_LENGTH |
| 1474 | pixman_box32_t *rectangles; |
| 1475 | void *data; |
| 1476 | int i, n; |
| 1477 | #endif |
| 1478 | |
Gwenole Beauchesne | 023f855 | 2012-04-20 11:07:06 +0200 | [diff] [blame] | 1479 | glBindTexture(GL_TEXTURE_2D, surface->textures[0]); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1480 | |
| 1481 | if (!surface->compositor->has_unpack_subimage) { |
| 1482 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, |
| 1483 | surface->pitch, surface->buffer->height, 0, |
| 1484 | GL_BGRA_EXT, GL_UNSIGNED_BYTE, |
| 1485 | wl_shm_buffer_get_data(surface->buffer)); |
| 1486 | |
| 1487 | return; |
| 1488 | } |
| 1489 | |
| 1490 | #ifdef GL_UNPACK_ROW_LENGTH |
| 1491 | /* Mesa does not define GL_EXT_unpack_subimage */ |
| 1492 | glPixelStorei(GL_UNPACK_ROW_LENGTH, surface->pitch); |
| 1493 | data = wl_shm_buffer_get_data(surface->buffer); |
| 1494 | rectangles = pixman_region32_rectangles(&surface->damage, &n); |
| 1495 | for (i = 0; i < n; i++) { |
| 1496 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, rectangles[i].x1); |
| 1497 | glPixelStorei(GL_UNPACK_SKIP_ROWS, rectangles[i].y1); |
| 1498 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 1499 | rectangles[i].x1, rectangles[i].y1, |
Rob Bradford | 8f24156 | 2012-07-02 17:33:40 +0100 | [diff] [blame] | 1500 | rectangles[i].x2 - rectangles[i].x1, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1501 | rectangles[i].y2 - rectangles[i].y1, |
| 1502 | GL_BGRA_EXT, GL_UNSIGNED_BYTE, data); |
| 1503 | } |
| 1504 | #endif |
| 1505 | } |
| 1506 | |
| 1507 | static void |
| 1508 | surface_accumulate_damage(struct weston_surface *surface, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1509 | pixman_region32_t *opaque) |
| 1510 | { |
| 1511 | if (surface->buffer && wl_buffer_is_shm(surface->buffer)) |
| 1512 | update_shm_texture(surface); |
| 1513 | |
| 1514 | if (surface->transform.enabled) { |
| 1515 | pixman_box32_t *extents; |
| 1516 | |
| 1517 | extents = pixman_region32_extents(&surface->damage); |
| 1518 | surface_compute_bbox(surface, extents->x1, extents->y1, |
| 1519 | extents->x2 - extents->x1, |
| 1520 | extents->y2 - extents->y1, |
| 1521 | &surface->damage); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1522 | pixman_region32_translate(&surface->damage, |
| 1523 | -surface->plane->x, |
| 1524 | -surface->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1525 | } else { |
| 1526 | pixman_region32_translate(&surface->damage, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1527 | surface->geometry.x - surface->plane->x, |
| 1528 | surface->geometry.y - surface->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | pixman_region32_subtract(&surface->damage, &surface->damage, opaque); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1532 | pixman_region32_union(&surface->plane->damage, |
| 1533 | &surface->plane->damage, &surface->damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1534 | empty_region(&surface->damage); |
| 1535 | pixman_region32_copy(&surface->clip, opaque); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1536 | pixman_region32_union(opaque, opaque, &surface->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1539 | static void |
Rob Bradford | 0fb7975 | 2012-08-02 15:36:57 +0100 | [diff] [blame] | 1540 | weston_output_repaint(struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1541 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1542 | struct weston_compositor *ec = output->compositor; |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1543 | struct weston_surface *es; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1544 | struct weston_layer *layer; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1545 | struct weston_animation *animation, *next; |
| 1546 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1547 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1548 | pixman_region32_t opaque, output_damage, new_damage; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 1549 | int32_t width, height; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1550 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1551 | weston_compositor_update_drag_surfaces(ec); |
| 1552 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 1553 | width = output->current->width + |
| 1554 | output->border.left + output->border.right; |
| 1555 | height = output->current->height + |
| 1556 | output->border.top + output->border.bottom; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1557 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 1558 | glViewport(0, 0, width, height); |
Kristian Høgsberg | fdec236 | 2001-01-01 22:23:51 -0500 | [diff] [blame] | 1559 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1560 | /* Rebuild the surface list and update surface transforms up front. */ |
| 1561 | wl_list_init(&ec->surface_list); |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1562 | wl_list_init(&frame_callback_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1563 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 1564 | wl_list_for_each(es, &layer->surface_list, layer_link) { |
| 1565 | weston_surface_update_transform(es); |
| 1566 | wl_list_insert(ec->surface_list.prev, &es->link); |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1567 | if (es->output == output) { |
| 1568 | wl_list_insert_list(&frame_callback_list, |
| 1569 | &es->frame_callback_list); |
| 1570 | wl_list_init(&es->frame_callback_list); |
| 1571 | } |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1572 | } |
| 1573 | } |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 1574 | |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 1575 | if (output->assign_planes && !output->disable_planes) |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 1576 | output->assign_planes(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 1577 | else |
| 1578 | wl_list_for_each(es, &ec->surface_list, link) |
| 1579 | weston_surface_move_to_plane(es, &ec->primary_plane); |
| 1580 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1581 | pixman_region32_init(&opaque); |
| 1582 | |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1583 | wl_list_for_each(es, &ec->surface_list, link) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1584 | surface_accumulate_damage(es, &opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1585 | |
Kristian Høgsberg | 7341e9b | 2011-07-01 22:12:11 -0400 | [diff] [blame] | 1586 | pixman_region32_fini(&opaque); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 1587 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1588 | pixman_region32_init(&output_damage); |
| 1589 | |
| 1590 | pixman_region32_init(&new_damage); |
| 1591 | pixman_region32_copy(&new_damage, &ec->primary_plane.damage); |
| 1592 | |
| 1593 | pixman_region32_union(&ec->primary_plane.damage, |
| 1594 | &ec->primary_plane.damage, |
| 1595 | &output->previous_damage); |
| 1596 | |
| 1597 | pixman_region32_intersect(&output->previous_damage, |
| 1598 | &new_damage, &output->region); |
| 1599 | |
| 1600 | pixman_region32_intersect(&output_damage, |
| 1601 | &ec->primary_plane.damage, &output->region); |
| 1602 | |
| 1603 | pixman_region32_fini(&new_damage); |
| 1604 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1605 | if (output->dirty) |
| 1606 | weston_output_update_matrix(output); |
| 1607 | |
Pekka Paalanen | 07c91f8 | 2012-08-30 16:47:21 -0500 | [diff] [blame^] | 1608 | /* if debugging, redraw everything outside the damage to clean up |
| 1609 | * debug lines from the previous draw on this buffer: |
| 1610 | */ |
| 1611 | if (ec->fan_debug) { |
| 1612 | pixman_region32_t undamaged; |
| 1613 | pixman_region32_init(&undamaged); |
| 1614 | pixman_region32_subtract(&undamaged, &output->region, |
| 1615 | &output_damage); |
| 1616 | ec->fan_debug = 0; |
| 1617 | output->repaint(output, &undamaged, 0); |
| 1618 | ec->fan_debug = 1; |
| 1619 | pixman_region32_fini(&undamaged); |
| 1620 | } |
| 1621 | |
| 1622 | output->repaint(output, &output_damage, 1); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1623 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1624 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1625 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1626 | output->repaint_needed = 0; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1627 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 1628 | weston_compositor_repick(ec); |
| 1629 | wl_event_loop_dispatch(ec->input_loop, 0); |
| 1630 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1631 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1632 | wl_callback_send_done(&cb->resource, msecs); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1633 | wl_resource_destroy(&cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1634 | } |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1635 | wl_list_init(&frame_callback_list); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1636 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1637 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1638 | animation->frame_counter++; |
Scott Moreau | 94b0b0c | 2012-06-14 01:01:56 -0600 | [diff] [blame] | 1639 | animation->frame(animation, output, msecs); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1640 | } |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1641 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1642 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1643 | static int |
| 1644 | weston_compositor_read_input(int fd, uint32_t mask, void *data) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1645 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1646 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 1647 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1648 | wl_event_loop_dispatch(compositor->input_loop, 0); |
| 1649 | |
| 1650 | return 1; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | WL_EXPORT void |
Rob Bradford | 0fb7975 | 2012-08-02 15:36:57 +0100 | [diff] [blame] | 1654 | weston_output_finish_frame(struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1655 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1656 | struct weston_compositor *compositor = output->compositor; |
| 1657 | struct wl_event_loop *loop = |
| 1658 | wl_display_get_event_loop(compositor->wl_display); |
| 1659 | int fd; |
| 1660 | |
Kristian Høgsberg | e9d0492 | 2012-06-19 23:54:26 -0400 | [diff] [blame] | 1661 | output->frame_time = msecs; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1662 | if (output->repaint_needed) { |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1663 | weston_output_repaint(output, msecs); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1664 | return; |
| 1665 | } |
| 1666 | |
| 1667 | output->repaint_scheduled = 0; |
| 1668 | if (compositor->input_loop_source) |
| 1669 | return; |
| 1670 | |
| 1671 | fd = wl_event_loop_get_fd(compositor->input_loop); |
| 1672 | compositor->input_loop_source = |
| 1673 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 1674 | weston_compositor_read_input, compositor); |
| 1675 | } |
| 1676 | |
| 1677 | static void |
| 1678 | idle_repaint(void *data) |
| 1679 | { |
| 1680 | struct weston_output *output = data; |
| 1681 | |
| 1682 | weston_output_finish_frame(output, weston_compositor_get_time()); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1683 | } |
| 1684 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1685 | WL_EXPORT void |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1686 | weston_layer_init(struct weston_layer *layer, struct wl_list *below) |
| 1687 | { |
| 1688 | wl_list_init(&layer->surface_list); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1689 | if (below != NULL) |
| 1690 | wl_list_insert(below, &layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1694 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1695 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1696 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1697 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1698 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1699 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1700 | return; |
| 1701 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1702 | loop = wl_display_get_event_loop(compositor->wl_display); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1703 | output->repaint_needed = 1; |
| 1704 | if (output->repaint_scheduled) |
| 1705 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1706 | |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1707 | wl_event_loop_add_idle(loop, idle_repaint, output); |
| 1708 | output->repaint_scheduled = 1; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1709 | |
| 1710 | if (compositor->input_loop_source) { |
| 1711 | wl_event_source_remove(compositor->input_loop_source); |
| 1712 | compositor->input_loop_source = NULL; |
| 1713 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1714 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1715 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1716 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1717 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 1718 | { |
| 1719 | struct weston_output *output; |
| 1720 | |
| 1721 | wl_list_for_each(output, &compositor->output_list, link) |
| 1722 | weston_output_schedule_repaint(output); |
| 1723 | } |
| 1724 | |
| 1725 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1726 | weston_compositor_fade(struct weston_compositor *compositor, float tint) |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1727 | { |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 1728 | struct weston_output *output; |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1729 | struct weston_surface *surface; |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1730 | |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 1731 | output = container_of(compositor->output_list.next, |
| 1732 | struct weston_output, link); |
| 1733 | |
Kristian Høgsberg | 269c782 | 2011-05-02 14:38:18 -0400 | [diff] [blame] | 1734 | compositor->fade.spring.target = tint; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1735 | if (weston_spring_done(&compositor->fade.spring)) |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1736 | return; |
| 1737 | |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1738 | if (compositor->fade.surface == NULL) { |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 1739 | surface = weston_surface_create(compositor); |
| 1740 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1741 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 0.0); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1742 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 1743 | &surface->layer_link); |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 1744 | weston_surface_assign_output(surface); |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1745 | compositor->fade.surface = surface; |
Kristian Høgsberg | 9bc7095 | 2012-02-29 12:22:38 -0500 | [diff] [blame] | 1746 | pixman_region32_init(&surface->input); |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | weston_surface_damage(compositor->fade.surface); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1750 | if (wl_list_empty(&compositor->fade.animation.link)) { |
| 1751 | compositor->fade.animation.frame_counter = 0; |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 1752 | wl_list_insert(output->animation_list.prev, |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1753 | &compositor->fade.animation.link); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1754 | } |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1755 | } |
| 1756 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1757 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1758 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1759 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1760 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
Casey Dahlin | 96d8a75 | 2012-04-19 22:50:07 -0400 | [diff] [blame] | 1763 | static struct wl_resource * |
| 1764 | find_resource_for_client(struct wl_list *list, struct wl_client *client) |
| 1765 | { |
| 1766 | struct wl_resource *r; |
| 1767 | |
| 1768 | wl_list_for_each(r, list, link) { |
| 1769 | if (r->client == client) |
| 1770 | return r; |
| 1771 | } |
| 1772 | |
| 1773 | return NULL; |
| 1774 | } |
| 1775 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1776 | static void |
| 1777 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1778 | { |
| 1779 | uint32_t different = es->output_mask ^ mask; |
| 1780 | uint32_t entered = mask & different; |
| 1781 | uint32_t left = es->output_mask & different; |
| 1782 | struct weston_output *output; |
Rob Bradford | 8667e77 | 2012-05-18 14:13:03 +0100 | [diff] [blame] | 1783 | struct wl_resource *resource = NULL; |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1784 | struct wl_client *client = es->surface.resource.client; |
| 1785 | |
Scott Moreau | a502152 | 2012-08-03 17:11:51 -0600 | [diff] [blame] | 1786 | es->output_mask = mask; |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1787 | if (es->surface.resource.client == NULL) |
| 1788 | return; |
| 1789 | if (different == 0) |
| 1790 | return; |
| 1791 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1792 | wl_list_for_each(output, &es->compositor->output_list, link) { |
| 1793 | if (1 << output->id & different) |
| 1794 | resource = |
| 1795 | find_resource_for_client(&output->resource_list, |
| 1796 | client); |
Kristian Høgsberg | c7814d2 | 2012-07-12 12:34:43 -0400 | [diff] [blame] | 1797 | if (resource == NULL) |
| 1798 | continue; |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1799 | if (1 << output->id & entered) |
| 1800 | wl_surface_send_enter(&es->surface.resource, resource); |
| 1801 | if (1 << output->id & left) |
| 1802 | wl_surface_send_leave(&es->surface.resource, resource); |
| 1803 | } |
| 1804 | } |
| 1805 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1806 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1807 | weston_surface_assign_output(struct weston_surface *es) |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1808 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1809 | struct weston_compositor *ec = es->compositor; |
| 1810 | struct weston_output *output, *new_output; |
Kristian Høgsberg | 4f0df04 | 2011-07-21 11:30:22 -0700 | [diff] [blame] | 1811 | pixman_region32_t region; |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1812 | uint32_t max, area, mask; |
Kristian Høgsberg | 4f0df04 | 2011-07-21 11:30:22 -0700 | [diff] [blame] | 1813 | pixman_box32_t *e; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1814 | |
Kristian Høgsberg | 496433b | 2011-11-15 13:50:21 -0500 | [diff] [blame] | 1815 | new_output = NULL; |
Kristian Høgsberg | 4f0df04 | 2011-07-21 11:30:22 -0700 | [diff] [blame] | 1816 | max = 0; |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1817 | mask = 0; |
Pekka Paalanen | 45f3e40 | 2012-01-26 11:34:16 +0200 | [diff] [blame] | 1818 | pixman_region32_init(®ion); |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1819 | wl_list_for_each(output, &ec->output_list, link) { |
Pekka Paalanen | 45f3e40 | 2012-01-26 11:34:16 +0200 | [diff] [blame] | 1820 | pixman_region32_intersect(®ion, &es->transform.boundingbox, |
| 1821 | &output->region); |
Kristian Høgsberg | 4f0df04 | 2011-07-21 11:30:22 -0700 | [diff] [blame] | 1822 | |
| 1823 | e = pixman_region32_extents(®ion); |
| 1824 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1825 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1826 | if (area > 0) |
| 1827 | mask |= 1 << output->id; |
| 1828 | |
Kristian Høgsberg | 4f0df04 | 2011-07-21 11:30:22 -0700 | [diff] [blame] | 1829 | if (area >= max) { |
Kristian Høgsberg | 496433b | 2011-11-15 13:50:21 -0500 | [diff] [blame] | 1830 | new_output = output; |
Kristian Høgsberg | 4f0df04 | 2011-07-21 11:30:22 -0700 | [diff] [blame] | 1831 | max = area; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1832 | } |
| 1833 | } |
Pekka Paalanen | 45f3e40 | 2012-01-26 11:34:16 +0200 | [diff] [blame] | 1834 | pixman_region32_fini(®ion); |
Kristian Høgsberg | 496433b | 2011-11-15 13:50:21 -0500 | [diff] [blame] | 1835 | |
| 1836 | es->output = new_output; |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 1837 | weston_surface_update_output_mask(es, mask); |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1838 | } |
| 1839 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1840 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1841 | surface_attach(struct wl_client *client, |
| 1842 | struct wl_resource *resource, |
| 1843 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 1844 | { |
| 1845 | struct weston_surface *es = resource->data; |
| 1846 | struct wl_buffer *buffer = NULL; |
| 1847 | |
| 1848 | if (buffer_resource) |
| 1849 | buffer = buffer_resource->data; |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1850 | |
Kristian Høgsberg | 8cbfb2a | 2012-03-27 17:04:59 -0400 | [diff] [blame] | 1851 | weston_surface_attach(&es->surface, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1852 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1853 | if (buffer && es->configure) |
| 1854 | es->configure(es, sx, sy); |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1857 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1858 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1859 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1860 | 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] | 1861 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1862 | struct weston_surface *es = resource->data; |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 1863 | |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1864 | pixman_region32_union_rect(&es->damage, &es->damage, |
| 1865 | x, y, width, height); |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1866 | weston_surface_schedule_repaint(es); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1867 | } |
| 1868 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1869 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1870 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1871 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1872 | struct weston_frame_callback *cb = resource->data; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1873 | |
| 1874 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 1875 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | static void |
| 1879 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1880 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1881 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1882 | struct weston_frame_callback *cb; |
| 1883 | struct weston_surface *es = resource->data; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1884 | |
| 1885 | cb = malloc(sizeof *cb); |
| 1886 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1887 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1888 | return; |
| 1889 | } |
| 1890 | |
| 1891 | cb->resource.object.interface = &wl_callback_interface; |
| 1892 | cb->resource.object.id = callback; |
| 1893 | cb->resource.destroy = destroy_frame_callback; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1894 | cb->resource.client = client; |
| 1895 | cb->resource.data = cb; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1896 | |
| 1897 | wl_client_add_resource(client, &cb->resource); |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1898 | wl_list_insert(es->frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1899 | } |
| 1900 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1901 | static void |
| 1902 | surface_set_opaque_region(struct wl_client *client, |
| 1903 | struct wl_resource *resource, |
| 1904 | struct wl_resource *region_resource) |
| 1905 | { |
| 1906 | struct weston_surface *surface = resource->data; |
| 1907 | struct weston_region *region; |
| 1908 | |
| 1909 | pixman_region32_fini(&surface->opaque); |
| 1910 | |
| 1911 | if (region_resource) { |
| 1912 | region = region_resource->data; |
| 1913 | pixman_region32_init_rect(&surface->opaque, 0, 0, |
| 1914 | surface->geometry.width, |
| 1915 | surface->geometry.height); |
| 1916 | pixman_region32_intersect(&surface->opaque, |
| 1917 | &surface->opaque, ®ion->region); |
| 1918 | } else { |
| 1919 | pixman_region32_init(&surface->opaque); |
| 1920 | } |
| 1921 | |
| 1922 | surface->geometry.dirty = 1; |
| 1923 | } |
| 1924 | |
| 1925 | static void |
| 1926 | surface_set_input_region(struct wl_client *client, |
| 1927 | struct wl_resource *resource, |
| 1928 | struct wl_resource *region_resource) |
| 1929 | { |
| 1930 | struct weston_surface *surface = resource->data; |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 1931 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1932 | |
| 1933 | if (region_resource) { |
| 1934 | region = region_resource->data; |
| 1935 | pixman_region32_init_rect(&surface->input, 0, 0, |
| 1936 | surface->geometry.width, |
| 1937 | surface->geometry.height); |
| 1938 | pixman_region32_intersect(&surface->input, |
| 1939 | &surface->input, ®ion->region); |
| 1940 | } else { |
| 1941 | pixman_region32_init_rect(&surface->input, 0, 0, |
| 1942 | surface->geometry.width, |
| 1943 | surface->geometry.height); |
| 1944 | } |
| 1945 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1946 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1947 | } |
| 1948 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1949 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1950 | surface_destroy, |
| 1951 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1952 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1953 | surface_frame, |
| 1954 | surface_set_opaque_region, |
| 1955 | surface_set_input_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1956 | }; |
| 1957 | |
| 1958 | static void |
| 1959 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1960 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1961 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1962 | struct weston_compositor *ec = resource->data; |
| 1963 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1964 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 1965 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1966 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1967 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1968 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1969 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1970 | |
Kristian Høgsberg | b313b02 | 2010-12-01 17:07:41 -0500 | [diff] [blame] | 1971 | surface->surface.resource.destroy = destroy_surface; |
Kristian Høgsberg | f66d0f4 | 2010-09-02 20:27:16 -0400 | [diff] [blame] | 1972 | |
Kristian Høgsberg | b313b02 | 2010-12-01 17:07:41 -0500 | [diff] [blame] | 1973 | surface->surface.resource.object.id = id; |
| 1974 | surface->surface.resource.object.interface = &wl_surface_interface; |
| 1975 | surface->surface.resource.object.implementation = |
Kristian Høgsberg | f66d0f4 | 2010-09-02 20:27:16 -0400 | [diff] [blame] | 1976 | (void (**)(void)) &surface_interface; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1977 | surface->surface.resource.data = surface; |
Kristian Høgsberg | f66d0f4 | 2010-09-02 20:27:16 -0400 | [diff] [blame] | 1978 | |
Kristian Høgsberg | b313b02 | 2010-12-01 17:07:41 -0500 | [diff] [blame] | 1979 | wl_client_add_resource(client, &surface->surface.resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1982 | static void |
| 1983 | destroy_region(struct wl_resource *resource) |
| 1984 | { |
| 1985 | struct weston_region *region = |
| 1986 | container_of(resource, struct weston_region, resource); |
| 1987 | |
| 1988 | pixman_region32_fini(®ion->region); |
| 1989 | free(region); |
| 1990 | } |
| 1991 | |
| 1992 | static void |
| 1993 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 1994 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1995 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | static void |
| 1999 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 2000 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2001 | { |
| 2002 | struct weston_region *region = resource->data; |
| 2003 | |
| 2004 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 2005 | x, y, width, height); |
| 2006 | } |
| 2007 | |
| 2008 | static void |
| 2009 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 2010 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2011 | { |
| 2012 | struct weston_region *region = resource->data; |
| 2013 | pixman_region32_t rect; |
| 2014 | |
| 2015 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 2016 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 2017 | pixman_region32_fini(&rect); |
| 2018 | } |
| 2019 | |
| 2020 | static const struct wl_region_interface region_interface = { |
| 2021 | region_destroy, |
| 2022 | region_add, |
| 2023 | region_subtract |
| 2024 | }; |
| 2025 | |
| 2026 | static void |
| 2027 | compositor_create_region(struct wl_client *client, |
| 2028 | struct wl_resource *resource, uint32_t id) |
| 2029 | { |
| 2030 | struct weston_region *region; |
| 2031 | |
| 2032 | region = malloc(sizeof *region); |
| 2033 | if (region == NULL) { |
| 2034 | wl_resource_post_no_memory(resource); |
| 2035 | return; |
| 2036 | } |
| 2037 | |
| 2038 | region->resource.destroy = destroy_region; |
| 2039 | |
| 2040 | region->resource.object.id = id; |
| 2041 | region->resource.object.interface = &wl_region_interface; |
| 2042 | region->resource.object.implementation = |
| 2043 | (void (**)(void)) ®ion_interface; |
| 2044 | region->resource.data = region; |
| 2045 | |
| 2046 | pixman_region32_init(®ion->region); |
| 2047 | |
| 2048 | wl_client_add_resource(client, ®ion->resource); |
| 2049 | } |
| 2050 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2051 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2052 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2053 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2054 | }; |
| 2055 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2056 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2057 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2058 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2059 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 2060 | weston_compositor_fade(compositor, 0.0); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2061 | |
| 2062 | wl_event_source_timer_update(compositor->idle_source, |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 2063 | compositor->idle_time * 1000); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2066 | static void |
| 2067 | weston_compositor_dpms_on(struct weston_compositor *compositor) |
| 2068 | { |
| 2069 | struct weston_output *output; |
| 2070 | |
| 2071 | wl_list_for_each(output, &compositor->output_list, link) |
| 2072 | if (output->set_dpms) |
| 2073 | output->set_dpms(output, WESTON_DPMS_ON); |
| 2074 | } |
| 2075 | |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2076 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2077 | weston_compositor_activity(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2078 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2079 | if (compositor->state == WESTON_COMPOSITOR_ACTIVE) { |
| 2080 | weston_compositor_wake(compositor); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2081 | } else { |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2082 | weston_compositor_dpms_on(compositor); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2083 | wl_signal_emit(&compositor->unlock_signal, compositor); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2087 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2088 | weston_compositor_idle_inhibit(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2089 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2090 | weston_compositor_activity(compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2091 | compositor->idle_inhibit++; |
| 2092 | } |
| 2093 | |
| 2094 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2095 | weston_compositor_idle_release(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2096 | { |
| 2097 | compositor->idle_inhibit--; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2098 | weston_compositor_activity(compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | static int |
| 2102 | idle_handler(void *data) |
| 2103 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2104 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2105 | |
| 2106 | if (compositor->idle_inhibit) |
| 2107 | return 1; |
| 2108 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2109 | weston_compositor_fade(compositor, 1.0); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2110 | |
| 2111 | return 1; |
| 2112 | } |
| 2113 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2114 | WL_EXPORT void |
| 2115 | weston_plane_init(struct weston_plane *plane, int32_t x, int32_t y) |
| 2116 | { |
| 2117 | pixman_region32_init(&plane->damage); |
| 2118 | plane->x = x; |
| 2119 | plane->y = y; |
| 2120 | } |
| 2121 | |
| 2122 | WL_EXPORT void |
| 2123 | weston_plane_release(struct weston_plane *plane) |
| 2124 | { |
| 2125 | pixman_region32_fini(&plane->damage); |
| 2126 | } |
| 2127 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2128 | static void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2129 | weston_seat_update_drag_surface(struct weston_seat *seat, int dx, int dy); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2130 | |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 2131 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2132 | clip_pointer_motion(struct weston_seat *seat, wl_fixed_t *fx, wl_fixed_t *fy) |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 2133 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2134 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 2135 | struct weston_output *output, *prev = NULL; |
| 2136 | int x, y, old_x, old_y, valid = 0; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 2137 | |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 2138 | x = wl_fixed_to_int(*fx); |
| 2139 | y = wl_fixed_to_int(*fy); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2140 | old_x = wl_fixed_to_int(seat->seat.pointer->x); |
| 2141 | old_y = wl_fixed_to_int(seat->seat.pointer->y); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2142 | |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2143 | wl_list_for_each(output, &ec->output_list, link) { |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 2144 | if (pixman_region32_contains_point(&output->region, |
| 2145 | x, y, NULL)) |
| 2146 | valid = 1; |
| 2147 | if (pixman_region32_contains_point(&output->region, |
| 2148 | old_x, old_y, NULL)) |
| 2149 | prev = output; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2150 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2151 | |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 2152 | if (!valid) { |
| 2153 | if (x < prev->x) |
| 2154 | *fx = wl_fixed_from_int(prev->x); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2155 | else if (x >= prev->x + prev->width) |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 2156 | *fx = wl_fixed_from_int(prev->x + |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2157 | prev->width - 1); |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 2158 | if (y < prev->y) |
| 2159 | *fy = wl_fixed_from_int(prev->y); |
| 2160 | else if (y >= prev->y + prev->current->height) |
| 2161 | *fy = wl_fixed_from_int(prev->y + |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2162 | prev->height - 1); |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2163 | } |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2167 | notify_motion(struct weston_seat *seat, uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 2168 | { |
| 2169 | const struct wl_pointer_grab_interface *interface; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2170 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 2171 | struct weston_output *output; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2172 | struct wl_pointer *pointer = seat->seat.pointer; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2173 | int32_t ix, iy; |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 2174 | |
| 2175 | weston_compositor_activity(ec); |
| 2176 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2177 | clip_pointer_motion(seat, &x, &y); |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 2178 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2179 | weston_seat_update_drag_surface(seat, x - pointer->x, y - pointer->y); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2180 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2181 | pointer->x = x; |
| 2182 | pointer->y = y; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2183 | |
| 2184 | ix = wl_fixed_to_int(x); |
| 2185 | iy = wl_fixed_to_int(y); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 2186 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2187 | wl_list_for_each(output, &ec->output_list, link) |
| 2188 | if (output->zoom.active && |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2189 | pixman_region32_contains_point(&output->region, |
| 2190 | ix, iy, NULL)) |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2191 | weston_output_update_zoom(output, ZOOM_FOCUS_POINTER); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2192 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2193 | weston_device_repick(seat); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2194 | interface = pointer->grab->interface; |
| 2195 | interface->motion(pointer->grab, time, |
| 2196 | pointer->grab->x, pointer->grab->y); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 2197 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2198 | if (seat->sprite) { |
| 2199 | weston_surface_set_position(seat->sprite, |
| 2200 | ix - seat->hotspot_x, |
| 2201 | iy - seat->hotspot_y); |
| 2202 | weston_surface_schedule_repaint(seat->sprite); |
Kristian Høgsberg | cd9ac1d | 2011-12-15 09:14:34 -0500 | [diff] [blame] | 2203 | } |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 2204 | } |
| 2205 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2206 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2207 | weston_surface_activate(struct weston_surface *surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2208 | struct weston_seat *seat) |
Kristian Høgsberg | c9824dd | 2011-02-06 16:54:59 -0500 | [diff] [blame] | 2209 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2210 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2211 | |
Pekka Paalanen | bdc7cd0 | 2012-06-07 15:07:07 +0300 | [diff] [blame] | 2212 | if (seat->seat.keyboard) { |
| 2213 | wl_keyboard_set_focus(seat->seat.keyboard, &surface->surface); |
| 2214 | wl_data_device_set_keyboard_focus(&seat->seat); |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 2215 | } |
| 2216 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2217 | wl_signal_emit(&compositor->activate_signal, surface); |
Kristian Høgsberg | c9824dd | 2011-02-06 16:54:59 -0500 | [diff] [blame] | 2218 | } |
| 2219 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2220 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2221 | notify_button(struct weston_seat *seat, uint32_t time, int32_t button, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2222 | enum wl_pointer_button_state state) |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 2223 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2224 | struct weston_compositor *compositor = seat->compositor; |
| 2225 | struct wl_pointer *pointer = seat->seat.pointer; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2226 | struct weston_surface *focus = |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2227 | (struct weston_surface *) pointer->focus; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2228 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | ea08115 | 2010-12-07 08:59:51 -0500 | [diff] [blame] | 2229 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2230 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2231 | if (compositor->ping_handler && focus) |
| 2232 | compositor->ping_handler(focus, serial); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2233 | weston_compositor_idle_inhibit(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2234 | if (pointer->button_count == 0) { |
| 2235 | pointer->grab_button = button; |
| 2236 | pointer->grab_time = time; |
| 2237 | pointer->grab_x = pointer->x; |
| 2238 | pointer->grab_y = pointer->y; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 2239 | } |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2240 | pointer->button_count++; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 2241 | } else { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2242 | weston_compositor_idle_release(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2243 | pointer->button_count--; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 2244 | } |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2245 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2246 | weston_compositor_run_button_binding(compositor, seat, time, button, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2247 | state); |
Kristian Høgsberg | b3fc757 | 2010-12-08 11:07:57 -0500 | [diff] [blame] | 2248 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2249 | pointer->grab->interface->button(pointer->grab, time, button, state); |
Kristian Høgsberg | 5a5f007 | 2011-12-19 14:54:11 -0500 | [diff] [blame] | 2250 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2251 | if (pointer->button_count == 1) |
| 2252 | pointer->grab_serial = |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2253 | wl_display_get_serial(compositor->wl_display); |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 2254 | } |
| 2255 | |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 2256 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2257 | notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 878f0b7 | 2012-05-30 16:31:57 +0100 | [diff] [blame] | 2258 | wl_fixed_t value) |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 2259 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2260 | struct weston_compositor *compositor = seat->compositor; |
| 2261 | struct wl_pointer *pointer = seat->seat.pointer; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2262 | struct weston_surface *focus = |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2263 | (struct weston_surface *) pointer->focus; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2264 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
| 2265 | |
| 2266 | if (compositor->ping_handler && focus) |
| 2267 | compositor->ping_handler(focus, serial); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 2268 | |
| 2269 | weston_compositor_activity(compositor); |
| 2270 | |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2271 | if (value) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2272 | weston_compositor_run_axis_binding(compositor, seat, |
| 2273 | time, axis, value); |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2274 | else |
| 2275 | return; |
| 2276 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2277 | if (pointer->focus_resource) |
| 2278 | wl_pointer_send_axis(pointer->focus_resource, time, axis, |
Daniel Stone | 2fce402 | 2012-05-30 16:32:00 +0100 | [diff] [blame] | 2279 | value); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 2280 | } |
| 2281 | |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2282 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2283 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 2284 | { |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2285 | struct wl_keyboard *keyboard = &seat->keyboard; |
| 2286 | struct wl_keyboard_grab *grab = keyboard->grab; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 2287 | uint32_t mods_depressed, mods_latched, mods_locked, group; |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 2288 | uint32_t mods_lookup; |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 2289 | enum weston_led leds = 0; |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2290 | int changed = 0; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 2291 | |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 2292 | /* Serialize and update our internal state, checking to see if it's |
| 2293 | * different to the previous state. */ |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2294 | mods_depressed = xkb_state_serialize_mods(seat->xkb_state.state, |
| 2295 | XKB_STATE_DEPRESSED); |
| 2296 | mods_latched = xkb_state_serialize_mods(seat->xkb_state.state, |
| 2297 | XKB_STATE_LATCHED); |
| 2298 | mods_locked = xkb_state_serialize_mods(seat->xkb_state.state, |
| 2299 | XKB_STATE_LOCKED); |
| 2300 | group = xkb_state_serialize_group(seat->xkb_state.state, |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 2301 | XKB_STATE_EFFECTIVE); |
| 2302 | |
Daniel Stone | 71c3877 | 2012-06-22 13:21:30 +0100 | [diff] [blame] | 2303 | if (mods_depressed != seat->seat.keyboard->modifiers.mods_depressed || |
| 2304 | mods_latched != seat->seat.keyboard->modifiers.mods_latched || |
| 2305 | mods_locked != seat->seat.keyboard->modifiers.mods_locked || |
| 2306 | group != seat->seat.keyboard->modifiers.group) |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2307 | changed = 1; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 2308 | |
Daniel Stone | 71c3877 | 2012-06-22 13:21:30 +0100 | [diff] [blame] | 2309 | seat->seat.keyboard->modifiers.mods_depressed = mods_depressed; |
| 2310 | seat->seat.keyboard->modifiers.mods_latched = mods_latched; |
| 2311 | seat->seat.keyboard->modifiers.mods_locked = mods_locked; |
| 2312 | seat->seat.keyboard->modifiers.group = group; |
Kristian Høgsberg | ab909ae | 2001-01-01 22:24:24 -0500 | [diff] [blame] | 2313 | |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 2314 | /* And update the modifier_state for bindings. */ |
| 2315 | mods_lookup = mods_depressed | mods_latched; |
| 2316 | seat->modifier_state = 0; |
Daniel Stone | 8db7969 | 2012-06-01 12:13:58 +0100 | [diff] [blame] | 2317 | if (mods_lookup & (1 << seat->xkb_info.ctrl_mod)) |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 2318 | seat->modifier_state |= MODIFIER_CTRL; |
Daniel Stone | 8db7969 | 2012-06-01 12:13:58 +0100 | [diff] [blame] | 2319 | if (mods_lookup & (1 << seat->xkb_info.alt_mod)) |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 2320 | seat->modifier_state |= MODIFIER_ALT; |
Daniel Stone | 8db7969 | 2012-06-01 12:13:58 +0100 | [diff] [blame] | 2321 | if (mods_lookup & (1 << seat->xkb_info.super_mod)) |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 2322 | seat->modifier_state |= MODIFIER_SUPER; |
Kristian Høgsberg | 73694c8 | 2012-06-28 14:13:10 -0400 | [diff] [blame] | 2323 | if (mods_lookup & (1 << seat->xkb_info.shift_mod)) |
| 2324 | seat->modifier_state |= MODIFIER_SHIFT; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 2325 | |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 2326 | /* Finally, notify the compositor that LEDs have changed. */ |
| 2327 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2328 | seat->xkb_info.num_led)) |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 2329 | leds |= LED_NUM_LOCK; |
| 2330 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2331 | seat->xkb_info.caps_led)) |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 2332 | leds |= LED_CAPS_LOCK; |
| 2333 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2334 | seat->xkb_info.scroll_led)) |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 2335 | leds |= LED_SCROLL_LOCK; |
| 2336 | if (leds != seat->xkb_state.leds && seat->led_update) |
Daniel Stone | bbf63bf | 2012-06-04 11:40:48 +0100 | [diff] [blame] | 2337 | seat->led_update(seat, leds); |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 2338 | seat->xkb_state.leds = leds; |
| 2339 | |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2340 | if (changed) { |
| 2341 | grab->interface->modifiers(grab, |
| 2342 | serial, |
| 2343 | keyboard->modifiers.mods_depressed, |
| 2344 | keyboard->modifiers.mods_latched, |
| 2345 | keyboard->modifiers.mods_locked, |
| 2346 | keyboard->modifiers.group); |
| 2347 | } |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 2348 | } |
Kristian Høgsberg | 2cbedd1 | 2009-09-18 17:29:49 -0400 | [diff] [blame] | 2349 | |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2350 | static void |
| 2351 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2352 | enum wl_keyboard_key_state state) |
| 2353 | { |
| 2354 | enum xkb_key_direction direction; |
| 2355 | |
| 2356 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 2357 | direction = XKB_KEY_DOWN; |
| 2358 | else |
| 2359 | direction = XKB_KEY_UP; |
| 2360 | |
| 2361 | /* Offset the keycode by 8, as the evdev XKB rules reflect X's |
| 2362 | * broken keycode system, which starts at 8. */ |
| 2363 | xkb_state_update_key(seat->xkb_state.state, key + 8, direction); |
| 2364 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2365 | notify_modifiers(seat, serial); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2368 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2369 | notify_key(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 2370 | enum wl_keyboard_key_state state, |
| 2371 | enum weston_key_state_update update_state) |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 2372 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2373 | struct weston_compositor *compositor = seat->compositor; |
| 2374 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2375 | struct weston_surface *focus = |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2376 | (struct weston_surface *) keyboard->focus; |
| 2377 | struct wl_keyboard_grab *grab = keyboard->grab; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2378 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 2379 | uint32_t *k, *end; |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 2380 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 2381 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2382 | if (compositor->ping_handler && focus) |
| 2383 | compositor->ping_handler(focus, serial); |
| 2384 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2385 | weston_compositor_idle_inhibit(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2386 | keyboard->grab_key = key; |
| 2387 | keyboard->grab_time = time; |
Scott Moreau | ec286eb | 2012-02-18 05:05:30 -0700 | [diff] [blame] | 2388 | } else { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2389 | weston_compositor_idle_release(compositor); |
Scott Moreau | ec286eb | 2012-02-18 05:05:30 -0700 | [diff] [blame] | 2390 | } |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2391 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2392 | end = keyboard->keys.data + keyboard->keys.size; |
| 2393 | for (k = keyboard->keys.data; k < end; k++) { |
Daniel Stone | c6587ea | 2012-06-22 13:21:31 +0100 | [diff] [blame] | 2394 | if (*k == key) { |
| 2395 | /* Ignore server-generated repeats. */ |
| 2396 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 2397 | return; |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 2398 | *k = *--end; |
Daniel Stone | c6587ea | 2012-06-22 13:21:31 +0100 | [diff] [blame] | 2399 | } |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 2400 | } |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2401 | keyboard->keys.size = (void *) end - keyboard->keys.data; |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 2402 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2403 | k = wl_array_add(&keyboard->keys, sizeof *k); |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 2404 | *k = key; |
| 2405 | } |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 2406 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2407 | if (grab == &keyboard->default_grab) { |
| 2408 | weston_compositor_run_key_binding(compositor, seat, time, key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2409 | state); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2410 | grab = keyboard->grab; |
Scott Moreau | befa653 | 2012-06-11 14:59:31 -0600 | [diff] [blame] | 2411 | } |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 2412 | |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 2413 | grab->interface->key(grab, time, key, state); |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2414 | |
| 2415 | if (update_state == STATE_UPDATE_AUTOMATIC) { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2416 | update_modifier_state(seat, |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 2417 | wl_display_get_serial(compositor->wl_display), |
| 2418 | key, |
| 2419 | state); |
| 2420 | } |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 2421 | } |
| 2422 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2423 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2424 | notify_pointer_focus(struct weston_seat *seat, struct weston_output *output, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2425 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2426 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2427 | struct weston_compositor *compositor = seat->compositor; |
| 2428 | struct wl_pointer *pointer = seat->seat.pointer; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2429 | |
| 2430 | if (output) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2431 | weston_seat_update_drag_surface(seat, |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2432 | x - pointer->x, |
| 2433 | y - pointer->y); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2434 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2435 | pointer->x = x; |
| 2436 | pointer->y = y; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2437 | compositor->focus = 1; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 2438 | weston_compositor_repick(compositor); |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2439 | } else { |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2440 | compositor->focus = 0; |
Tiago Vignatti | cd717b5 | 2012-07-12 00:46:10 +0300 | [diff] [blame] | 2441 | /* FIXME: We should call wl_pointer_set_focus(seat, |
| 2442 | * NULL) here, but somehow that breaks re-entry... */ |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2443 | } |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2444 | } |
| 2445 | |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2446 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2447 | destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2448 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2449 | struct weston_seat *ws; |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2450 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2451 | ws = container_of(listener, struct weston_seat, |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2452 | saved_kbd_focus_listener); |
| 2453 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2454 | ws->saved_kbd_focus = NULL; |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2455 | } |
| 2456 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2457 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2458 | notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2459 | enum weston_key_state_update update_state) |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2460 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2461 | struct weston_compositor *compositor = seat->compositor; |
| 2462 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
Kristian Høgsberg | afee221 | 2012-03-20 17:28:20 -0400 | [diff] [blame] | 2463 | struct wl_surface *surface; |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2464 | uint32_t *k, serial; |
Kristian Høgsberg | f992b2f | 2011-01-28 15:53:07 -0500 | [diff] [blame] | 2465 | |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2466 | serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2467 | wl_array_copy(&keyboard->keys, keys); |
| 2468 | wl_array_for_each(k, &keyboard->keys) { |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2469 | weston_compositor_idle_inhibit(compositor); |
| 2470 | if (update_state == STATE_UPDATE_AUTOMATIC) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2471 | update_modifier_state(seat, serial, *k, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2472 | WL_KEYBOARD_KEY_STATE_PRESSED); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2473 | } |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2474 | |
Daniel Stone | ef17267 | 2012-06-22 13:21:32 +0100 | [diff] [blame] | 2475 | /* Run key bindings after we've updated the state. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2476 | wl_array_for_each(k, &keyboard->keys) { |
| 2477 | weston_compositor_run_key_binding(compositor, seat, 0, *k, |
Daniel Stone | ef17267 | 2012-06-22 13:21:32 +0100 | [diff] [blame] | 2478 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 2479 | } |
| 2480 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2481 | surface = seat->saved_kbd_focus; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2482 | |
| 2483 | if (surface) { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2484 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 2485 | wl_keyboard_set_focus(keyboard, surface); |
| 2486 | seat->saved_kbd_focus = NULL; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2491 | notify_keyboard_focus_out(struct weston_seat *seat) |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2492 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2493 | struct weston_compositor *compositor = seat->compositor; |
| 2494 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2495 | uint32_t *k, serial; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2496 | |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2497 | serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2498 | wl_array_for_each(k, &keyboard->keys) { |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2499 | weston_compositor_idle_release(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2500 | update_modifier_state(seat, serial, *k, |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2501 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 2502 | } |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2503 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2504 | seat->modifier_state = 0; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2505 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2506 | if (keyboard->focus) { |
| 2507 | seat->saved_kbd_focus = keyboard->focus; |
| 2508 | seat->saved_kbd_focus_listener.notify = |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2509 | destroy_device_saved_kbd_focus; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2510 | wl_signal_add(&keyboard->focus->resource.destroy_signal, |
| 2511 | &seat->saved_kbd_focus_listener); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2512 | } |
| 2513 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2514 | wl_keyboard_set_focus(keyboard, NULL); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2515 | /* FIXME: We really need keyboard grab cancel here to |
| 2516 | * let the grab shut down properly. As it is we leak |
| 2517 | * the grab data. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2518 | wl_keyboard_end_grab(keyboard); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2519 | } |
| 2520 | |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2521 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2522 | touch_set_focus(struct weston_seat *ws, struct wl_surface *surface) |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2523 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2524 | struct wl_seat *seat = &ws->seat; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2525 | struct wl_resource *resource; |
| 2526 | |
Pekka Paalanen | 5646425 | 2012-07-31 13:21:08 +0300 | [diff] [blame] | 2527 | if (seat->touch->focus == surface) |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2528 | return; |
| 2529 | |
Pekka Paalanen | 5646425 | 2012-07-31 13:21:08 +0300 | [diff] [blame] | 2530 | if (seat->touch->focus_resource) |
| 2531 | wl_list_remove(&seat->touch->focus_listener.link); |
| 2532 | seat->touch->focus = NULL; |
| 2533 | seat->touch->focus_resource = NULL; |
| 2534 | |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2535 | if (surface) { |
| 2536 | resource = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2537 | find_resource_for_client(&seat->touch->resource_list, |
Casey Dahlin | 96d8a75 | 2012-04-19 22:50:07 -0400 | [diff] [blame] | 2538 | surface->resource.client); |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2539 | if (!resource) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2540 | weston_log("couldn't find resource\n"); |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2541 | return; |
| 2542 | } |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2543 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2544 | seat->touch->focus = surface; |
| 2545 | seat->touch->focus_resource = resource; |
Pekka Paalanen | 5646425 | 2012-07-31 13:21:08 +0300 | [diff] [blame] | 2546 | wl_signal_add(&resource->destroy_signal, |
| 2547 | &seat->touch->focus_listener); |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2548 | } |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2549 | } |
| 2550 | |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2551 | /** |
| 2552 | * notify_touch - emulates button touches and notifies surfaces accordingly. |
| 2553 | * |
| 2554 | * It assumes always the correct cycle sequence until it gets here: touch_down |
| 2555 | * → touch_update → ... → touch_update → touch_end. The driver is responsible |
| 2556 | * for sending along such order. |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2557 | * |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2558 | */ |
| 2559 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2560 | notify_touch(struct weston_seat *seat, uint32_t time, int touch_id, |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2561 | wl_fixed_t x, wl_fixed_t y, int touch_type) |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2562 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2563 | struct weston_compositor *ec = seat->compositor; |
| 2564 | struct wl_touch *touch = seat->seat.touch; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2565 | struct weston_surface *es; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2566 | wl_fixed_t sx, sy; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2567 | uint32_t serial = 0; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2568 | |
| 2569 | switch (touch_type) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2570 | case WL_TOUCH_DOWN: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2571 | weston_compositor_idle_inhibit(ec); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2572 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2573 | seat->num_tp++; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2574 | |
| 2575 | /* the first finger down picks the surface, and all further go |
| 2576 | * to that surface for the remainder of the touch session i.e. |
| 2577 | * until all touch points are up again. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2578 | if (seat->num_tp == 1) { |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2579 | es = weston_compositor_pick_surface(ec, x, y, &sx, &sy); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2580 | touch_set_focus(seat, &es->surface); |
| 2581 | } else if (touch->focus) { |
| 2582 | es = (struct weston_surface *) touch->focus; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2583 | weston_surface_from_global_fixed(es, x, y, &sx, &sy); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2584 | } |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2585 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2586 | if (touch->focus_resource && touch->focus) |
| 2587 | wl_touch_send_down(touch->focus_resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2588 | serial, time, |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2589 | &touch->focus->resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2590 | touch_id, sx, sy); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2591 | break; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2592 | case WL_TOUCH_MOTION: |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2593 | es = (struct weston_surface *) touch->focus; |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2594 | if (!es) |
| 2595 | break; |
| 2596 | |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2597 | weston_surface_from_global_fixed(es, x, y, &sx, &sy); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2598 | if (touch->focus_resource) |
| 2599 | wl_touch_send_motion(touch->focus_resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2600 | time, touch_id, sx, sy); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2601 | break; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2602 | case WL_TOUCH_UP: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2603 | weston_compositor_idle_release(ec); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2604 | seat->num_tp--; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2605 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2606 | if (touch->focus_resource) |
| 2607 | wl_touch_send_up(touch->focus_resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2608 | serial, time, touch_id); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2609 | if (seat->num_tp == 0) |
| 2610 | touch_set_focus(seat, NULL); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2611 | break; |
| 2612 | } |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2613 | } |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2614 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 2615 | static void |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2616 | pointer_handle_sprite_destroy(struct wl_listener *listener, void *data) |
| 2617 | { |
| 2618 | struct weston_seat *seat = container_of(listener, struct weston_seat, |
| 2619 | sprite_destroy_listener); |
| 2620 | |
| 2621 | seat->sprite = NULL; |
| 2622 | } |
| 2623 | |
| 2624 | static void |
| 2625 | pointer_cursor_surface_configure(struct weston_surface *es, |
| 2626 | int32_t dx, int32_t dy) |
| 2627 | { |
| 2628 | struct weston_seat *seat = es->private; |
| 2629 | int x, y; |
| 2630 | |
| 2631 | assert(es == seat->sprite); |
| 2632 | |
| 2633 | seat->hotspot_x -= dx; |
| 2634 | seat->hotspot_y -= dy; |
| 2635 | |
| 2636 | x = wl_fixed_to_int(seat->seat.pointer->x) - seat->hotspot_x; |
| 2637 | y = wl_fixed_to_int(seat->seat.pointer->y) - seat->hotspot_y; |
| 2638 | |
| 2639 | weston_surface_configure(seat->sprite, x, y, |
| 2640 | es->buffer->width, es->buffer->height); |
| 2641 | |
Ander Conselvan de Oliveira | f1c00c0 | 2012-07-04 15:48:29 +0300 | [diff] [blame] | 2642 | empty_region(&es->input); |
| 2643 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2644 | if (!weston_surface_is_mapped(es)) { |
| 2645 | wl_list_insert(&es->compositor->cursor_layer.surface_list, |
| 2646 | &es->layer_link); |
| 2647 | weston_surface_assign_output(es); |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | static void |
| 2652 | pointer_unmap_sprite(struct weston_seat *seat) |
| 2653 | { |
| 2654 | if (weston_surface_is_mapped(seat->sprite)) |
| 2655 | weston_surface_unmap(seat->sprite); |
| 2656 | |
| 2657 | wl_list_remove(&seat->sprite_destroy_listener.link); |
| 2658 | seat->sprite->configure = NULL; |
| 2659 | seat->sprite->private = NULL; |
| 2660 | seat->sprite = NULL; |
| 2661 | } |
| 2662 | |
| 2663 | static void |
| 2664 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 2665 | uint32_t serial, struct wl_resource *surface_resource, |
| 2666 | int32_t x, int32_t y) |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2667 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2668 | struct weston_seat *seat = resource->data; |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2669 | struct weston_surface *surface = NULL; |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2670 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2671 | if (surface_resource) |
| 2672 | surface = container_of(surface_resource->data, |
| 2673 | struct weston_surface, surface); |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 2674 | |
Kristian Høgsberg | 649e1ce | 2012-08-01 09:46:12 -0400 | [diff] [blame] | 2675 | if (seat->seat.pointer->focus == NULL) |
| 2676 | return; |
| 2677 | if (seat->seat.pointer->focus->resource.client != client) |
| 2678 | return; |
Kristian Høgsberg | 2e96d3c | 2012-08-01 09:39:11 -0400 | [diff] [blame] | 2679 | if (seat->seat.pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2680 | return; |
Ander Conselvan de Oliveira | 1fbda0e | 2012-06-28 18:08:04 +0300 | [diff] [blame] | 2681 | |
| 2682 | if (surface && surface != seat->sprite) { |
Ander Conselvan de Oliveira | 1fbda0e | 2012-06-28 18:08:04 +0300 | [diff] [blame] | 2683 | if (surface->configure) { |
| 2684 | wl_resource_post_error(&surface->surface.resource, |
| 2685 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2686 | "surface->configure already " |
| 2687 | "set"); |
| 2688 | return; |
| 2689 | } |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 2690 | } |
Kristian Høgsberg | cd9ac1d | 2011-12-15 09:14:34 -0500 | [diff] [blame] | 2691 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2692 | if (seat->sprite) |
| 2693 | pointer_unmap_sprite(seat); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2694 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2695 | if (!surface) |
| 2696 | return; |
| 2697 | |
| 2698 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 2699 | &seat->sprite_destroy_listener); |
| 2700 | |
| 2701 | surface->configure = pointer_cursor_surface_configure; |
| 2702 | surface->private = seat; |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2703 | seat->sprite = surface; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2704 | seat->hotspot_x = x; |
| 2705 | seat->hotspot_y = y; |
Kristian Høgsberg | cd9ac1d | 2011-12-15 09:14:34 -0500 | [diff] [blame] | 2706 | |
Kristian Høgsberg | d3800e4 | 2012-08-13 18:14:15 -0400 | [diff] [blame] | 2707 | if (surface->buffer) |
| 2708 | pointer_cursor_surface_configure(surface, 0, 0); |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2709 | } |
| 2710 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2711 | static const struct wl_pointer_interface pointer_interface = { |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2712 | pointer_set_cursor |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2713 | }; |
| 2714 | |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2715 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2716 | handle_drag_surface_destroy(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2717 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2718 | struct weston_seat *seat; |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2719 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2720 | seat = container_of(listener, struct weston_seat, |
| 2721 | drag_surface_destroy_listener); |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2722 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2723 | seat->drag_surface = NULL; |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2724 | } |
| 2725 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2726 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2727 | { |
| 2728 | wl_list_remove(&resource->link); |
| 2729 | free(resource); |
| 2730 | } |
| 2731 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2732 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2733 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 2734 | uint32_t id) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2735 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2736 | struct weston_seat *seat = resource->data; |
| 2737 | struct wl_resource *cr; |
Kristian Høgsberg | 8e6d712 | 2011-08-29 16:04:39 -0400 | [diff] [blame] | 2738 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2739 | if (!seat->seat.pointer) |
| 2740 | return; |
| 2741 | |
| 2742 | cr = wl_client_add_object(client, &wl_pointer_interface, |
| 2743 | &pointer_interface, id, seat); |
| 2744 | wl_list_insert(&seat->seat.pointer->resource_list, &cr->link); |
Kristian Høgsberg | b93b6cf | 2012-05-16 22:32:40 -0400 | [diff] [blame] | 2745 | cr->destroy = unbind_resource; |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2746 | |
| 2747 | if (seat->seat.pointer->focus && |
| 2748 | seat->seat.pointer->focus->resource.client == client) { |
| 2749 | struct weston_surface *surface; |
| 2750 | wl_fixed_t sx, sy; |
| 2751 | |
| 2752 | surface = (struct weston_surface *) seat->seat.pointer->focus; |
| 2753 | weston_surface_from_global_fixed(surface, |
| 2754 | seat->seat.pointer->x, |
| 2755 | seat->seat.pointer->y, |
| 2756 | &sx, |
| 2757 | &sy); |
| 2758 | wl_pointer_set_focus(seat->seat.pointer, |
| 2759 | seat->seat.pointer->focus, |
| 2760 | sx, |
| 2761 | sy); |
| 2762 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | static void |
| 2766 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 2767 | uint32_t id) |
| 2768 | { |
| 2769 | struct weston_seat *seat = resource->data; |
| 2770 | struct wl_resource *cr; |
| 2771 | |
| 2772 | if (!seat->seat.keyboard) |
| 2773 | return; |
| 2774 | |
| 2775 | cr = wl_client_add_object(client, &wl_keyboard_interface, NULL, id, |
| 2776 | seat); |
| 2777 | wl_list_insert(&seat->seat.keyboard->resource_list, &cr->link); |
Kristian Høgsberg | b93b6cf | 2012-05-16 22:32:40 -0400 | [diff] [blame] | 2778 | cr->destroy = unbind_resource; |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2779 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2780 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 2781 | seat->xkb_info.keymap_fd, |
| 2782 | seat->xkb_info.keymap_size); |
| 2783 | |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2784 | if (seat->seat.keyboard->focus && |
| 2785 | seat->seat.keyboard->focus->resource.client == client) { |
| 2786 | wl_keyboard_set_focus(seat->seat.keyboard, |
| 2787 | seat->seat.keyboard->focus); |
| 2788 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | static void |
| 2792 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 2793 | uint32_t id) |
| 2794 | { |
| 2795 | struct weston_seat *seat = resource->data; |
| 2796 | struct wl_resource *cr; |
| 2797 | |
| 2798 | if (!seat->seat.touch) |
| 2799 | return; |
| 2800 | |
| 2801 | cr = wl_client_add_object(client, &wl_touch_interface, NULL, id, seat); |
| 2802 | wl_list_insert(&seat->seat.touch->resource_list, &cr->link); |
Kristian Høgsberg | b93b6cf | 2012-05-16 22:32:40 -0400 | [diff] [blame] | 2803 | cr->destroy = unbind_resource; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | static const struct wl_seat_interface seat_interface = { |
| 2807 | seat_get_pointer, |
| 2808 | seat_get_keyboard, |
| 2809 | seat_get_touch, |
| 2810 | }; |
| 2811 | |
| 2812 | static void |
| 2813 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 2814 | { |
| 2815 | struct wl_seat *seat = data; |
| 2816 | struct wl_resource *resource; |
| 2817 | enum wl_seat_capability caps = 0; |
| 2818 | |
| 2819 | resource = wl_client_add_object(client, &wl_seat_interface, |
| 2820 | &seat_interface, id, data); |
| 2821 | wl_list_insert(&seat->base_resource_list, &resource->link); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2822 | resource->destroy = unbind_resource; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2823 | |
| 2824 | if (seat->pointer) |
| 2825 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 2826 | if (seat->keyboard) |
| 2827 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 2828 | if (seat->touch) |
| 2829 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 2830 | |
| 2831 | wl_seat_send_capabilities(resource, caps); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2834 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2835 | device_handle_new_drag_icon(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2836 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2837 | struct weston_seat *seat; |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2838 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2839 | seat = container_of(listener, struct weston_seat, |
| 2840 | new_drag_icon_listener); |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2841 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2842 | weston_seat_update_drag_surface(seat, 0, 0); |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2843 | } |
| 2844 | |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2845 | static void weston_compositor_xkb_init(struct weston_compositor *ec, |
| 2846 | struct xkb_rule_names *names) |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2847 | { |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2848 | if (ec->xkb_context == NULL) { |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2849 | ec->xkb_context = xkb_context_new(0); |
| 2850 | if (ec->xkb_context == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2851 | weston_log("failed to create XKB context\n"); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2852 | exit(1); |
| 2853 | } |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | if (names) |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2857 | ec->xkb_names = *names; |
| 2858 | if (!ec->xkb_names.rules) |
| 2859 | ec->xkb_names.rules = strdup("evdev"); |
| 2860 | if (!ec->xkb_names.model) |
| 2861 | ec->xkb_names.model = strdup("pc105"); |
| 2862 | if (!ec->xkb_names.layout) |
| 2863 | ec->xkb_names.layout = strdup("us"); |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2864 | } |
| 2865 | |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2866 | static void xkb_info_destroy(struct weston_xkb_info *xkb_info) |
| 2867 | { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2868 | if (xkb_info->keymap) |
| 2869 | xkb_map_unref(xkb_info->keymap); |
| 2870 | |
| 2871 | if (xkb_info->keymap_area) |
| 2872 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 2873 | if (xkb_info->keymap_fd >= 0) |
| 2874 | close(xkb_info->keymap_fd); |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2875 | } |
| 2876 | |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2877 | static void weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 2878 | { |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2879 | free((char *) ec->xkb_names.rules); |
| 2880 | free((char *) ec->xkb_names.model); |
| 2881 | free((char *) ec->xkb_names.layout); |
| 2882 | free((char *) ec->xkb_names.variant); |
| 2883 | free((char *) ec->xkb_names.options); |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2884 | |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2885 | xkb_info_destroy(&ec->xkb_info); |
| 2886 | xkb_context_unref(ec->xkb_context); |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2887 | } |
| 2888 | |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2889 | static void |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2890 | weston_xkb_info_new_keymap(struct weston_xkb_info *xkb_info) |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2891 | { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2892 | char *keymap_str; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2893 | |
Daniel Stone | abb9dcd | 2012-06-22 13:21:33 +0100 | [diff] [blame] | 2894 | xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2895 | XKB_MOD_NAME_SHIFT); |
| 2896 | xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2897 | XKB_MOD_NAME_CAPS); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2898 | xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2899 | XKB_MOD_NAME_CTRL); |
| 2900 | xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2901 | XKB_MOD_NAME_ALT); |
Daniel Stone | abb9dcd | 2012-06-22 13:21:33 +0100 | [diff] [blame] | 2902 | xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2"); |
| 2903 | xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3"); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2904 | xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2905 | XKB_MOD_NAME_LOGO); |
Daniel Stone | abb9dcd | 2012-06-22 13:21:33 +0100 | [diff] [blame] | 2906 | xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5"); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2907 | |
| 2908 | xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap, |
| 2909 | XKB_LED_NAME_NUM); |
| 2910 | xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap, |
| 2911 | XKB_LED_NAME_CAPS); |
| 2912 | xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap, |
| 2913 | XKB_LED_NAME_SCROLL); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2914 | |
| 2915 | keymap_str = xkb_map_get_as_string(xkb_info->keymap); |
| 2916 | if (keymap_str == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2917 | weston_log("failed to get string version of keymap\n"); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2918 | exit(EXIT_FAILURE); |
| 2919 | } |
| 2920 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 2921 | |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 2922 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2923 | if (xkb_info->keymap_fd < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2924 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 2925 | (unsigned long) xkb_info->keymap_size); |
| 2926 | goto err_keymap_str; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 2930 | PROT_READ | PROT_WRITE, |
| 2931 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 2932 | if (xkb_info->keymap_area == MAP_FAILED) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2933 | weston_log("failed to mmap() %lu bytes\n", |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 2934 | (unsigned long) xkb_info->keymap_size); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2935 | goto err_dev_zero; |
| 2936 | } |
| 2937 | strcpy(xkb_info->keymap_area, keymap_str); |
| 2938 | free(keymap_str); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2939 | |
| 2940 | return; |
| 2941 | |
| 2942 | err_dev_zero: |
| 2943 | close(xkb_info->keymap_fd); |
| 2944 | xkb_info->keymap_fd = -1; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2945 | err_keymap_str: |
| 2946 | free(keymap_str); |
| 2947 | exit(EXIT_FAILURE); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | static void |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2951 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 2952 | { |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2953 | if (ec->xkb_info.keymap != NULL) |
| 2954 | return; |
| 2955 | |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2956 | ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_context, |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2957 | &ec->xkb_names, |
| 2958 | 0); |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2959 | if (ec->xkb_info.keymap == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2960 | weston_log("failed to compile global XKB keymap\n"); |
| 2961 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2962 | "options %s", |
| 2963 | ec->xkb_names.rules, ec->xkb_names.model, |
| 2964 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 2965 | ec->xkb_names.options); |
| 2966 | exit(1); |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2967 | } |
| 2968 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2969 | weston_xkb_info_new_keymap(&ec->xkb_info); |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2970 | } |
| 2971 | |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2972 | WL_EXPORT void |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2973 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2974 | { |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2975 | if (seat->has_keyboard) |
| 2976 | return; |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2977 | |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2978 | if (keymap != NULL) { |
| 2979 | seat->xkb_info.keymap = xkb_map_ref(keymap); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2980 | weston_xkb_info_new_keymap(&seat->xkb_info); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2981 | } |
| 2982 | else { |
| 2983 | weston_compositor_build_global_keymap(seat->compositor); |
| 2984 | seat->xkb_info = seat->compositor->xkb_info; |
| 2985 | seat->xkb_info.keymap = xkb_map_ref(seat->xkb_info.keymap); |
| 2986 | } |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2987 | |
| 2988 | seat->xkb_state.state = xkb_state_new(seat->xkb_info.keymap); |
| 2989 | if (seat->xkb_state.state == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2990 | weston_log("failed to initialise XKB state\n"); |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2991 | exit(1); |
| 2992 | } |
| 2993 | |
Daniel Stone | 71c3877 | 2012-06-22 13:21:30 +0100 | [diff] [blame] | 2994 | seat->xkb_state.leds = 0; |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2995 | |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2996 | wl_keyboard_init(&seat->keyboard); |
| 2997 | wl_seat_set_keyboard(&seat->seat, &seat->keyboard); |
| 2998 | |
| 2999 | seat->has_keyboard = 1; |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 3000 | } |
| 3001 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3002 | WL_EXPORT void |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 3003 | weston_seat_init_pointer(struct weston_seat *seat) |
| 3004 | { |
| 3005 | if (seat->has_pointer) |
| 3006 | return; |
| 3007 | |
| 3008 | wl_pointer_init(&seat->pointer); |
| 3009 | wl_seat_set_pointer(&seat->seat, &seat->pointer); |
| 3010 | |
| 3011 | seat->has_pointer = 1; |
| 3012 | } |
| 3013 | |
| 3014 | WL_EXPORT void |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 3015 | weston_seat_init_touch(struct weston_seat *seat) |
| 3016 | { |
| 3017 | if (seat->has_touch) |
| 3018 | return; |
| 3019 | |
| 3020 | wl_touch_init(&seat->touch); |
| 3021 | wl_seat_set_touch(&seat->seat, &seat->touch); |
| 3022 | |
| 3023 | seat->has_touch = 1; |
| 3024 | } |
| 3025 | |
| 3026 | WL_EXPORT void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3027 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 3028 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3029 | wl_seat_init(&seat->seat); |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 3030 | seat->has_pointer = 0; |
| 3031 | seat->has_keyboard = 0; |
| 3032 | seat->has_touch = 0; |
Kristian Høgsberg | 02ef1c1 | 2010-12-06 21:35:19 -0500 | [diff] [blame] | 3033 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3034 | wl_display_add_global(ec->wl_display, &wl_seat_interface, seat, |
| 3035 | bind_seat); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3036 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 3037 | seat->sprite = NULL; |
| 3038 | seat->sprite_destroy_listener.notify = pointer_handle_sprite_destroy; |
Kristian Høgsberg | 8244b44 | 2011-06-23 15:44:14 -0400 | [diff] [blame] | 3039 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3040 | seat->compositor = ec; |
| 3041 | seat->hotspot_x = 16; |
| 3042 | seat->hotspot_y = 16; |
| 3043 | seat->modifier_state = 0; |
| 3044 | seat->num_tp = 0; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 3045 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3046 | seat->drag_surface_destroy_listener.notify = |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3047 | handle_drag_surface_destroy; |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3048 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3049 | wl_list_insert(ec->seat_list.prev, &seat->link); |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 3050 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3051 | seat->new_drag_icon_listener.notify = device_handle_new_drag_icon; |
| 3052 | wl_signal_add(&seat->seat.drag_icon_signal, |
| 3053 | &seat->new_drag_icon_listener); |
Kristian Høgsberg | a7ceaff | 2012-06-03 10:20:13 -0400 | [diff] [blame] | 3054 | |
| 3055 | clipboard_create(seat); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 3056 | input_method_create(ec, seat); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 3057 | } |
| 3058 | |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 3059 | WL_EXPORT void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3060 | weston_seat_release(struct weston_seat *seat) |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 3061 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3062 | wl_list_remove(&seat->link); |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 3063 | /* The global object is destroyed at wl_display_destroy() time. */ |
| 3064 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3065 | if (seat->sprite) |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 3066 | pointer_unmap_sprite(seat); |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 3067 | |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 3068 | if (seat->xkb_state.state != NULL) |
| 3069 | xkb_state_unref(seat->xkb_state.state); |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 3070 | xkb_info_destroy(&seat->xkb_info); |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 3071 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3072 | wl_seat_release(&seat->seat); |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3075 | static void |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3076 | drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 3077 | { |
| 3078 | weston_surface_configure(es, |
| 3079 | es->geometry.x + sx, es->geometry.y + sy, |
| 3080 | es->buffer->width, es->buffer->height); |
| 3081 | } |
| 3082 | |
| 3083 | static int |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3084 | device_setup_new_drag_surface(struct weston_seat *ws, |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3085 | struct weston_surface *surface) |
| 3086 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3087 | struct wl_seat *seat = &ws->seat; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3088 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3089 | if (surface->configure) { |
| 3090 | wl_resource_post_error(&surface->surface.resource, |
| 3091 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3092 | "surface->configure already set"); |
| 3093 | return 0; |
| 3094 | } |
| 3095 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3096 | ws->drag_surface = surface; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3097 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3098 | weston_surface_set_position(ws->drag_surface, |
| 3099 | wl_fixed_to_double(seat->pointer->x), |
| 3100 | wl_fixed_to_double(seat->pointer->y)); |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3101 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3102 | surface->configure = drag_surface_configure; |
| 3103 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3104 | wl_signal_add(&surface->surface.resource.destroy_signal, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3105 | &ws->drag_surface_destroy_listener); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3106 | |
| 3107 | return 1; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3111 | device_release_drag_surface(struct weston_seat *seat) |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3112 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3113 | seat->drag_surface->configure = NULL; |
| 3114 | undef_region(&seat->drag_surface->input); |
| 3115 | wl_list_remove(&seat->drag_surface_destroy_listener.link); |
| 3116 | seat->drag_surface = NULL; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3120 | device_map_drag_surface(struct weston_seat *seat) |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3121 | { |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 3122 | struct wl_list *list; |
| 3123 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3124 | if (weston_surface_is_mapped(seat->drag_surface) || |
| 3125 | !seat->drag_surface->buffer) |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3126 | return; |
| 3127 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 3128 | if (seat->sprite && weston_surface_is_mapped(seat->sprite)) |
| 3129 | list = &seat->sprite->layer_link; |
| 3130 | else |
| 3131 | list = &seat->compositor->cursor_layer.surface_list; |
| 3132 | |
| 3133 | wl_list_insert(list, &seat->drag_surface->layer_link); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3134 | weston_surface_assign_output(seat->drag_surface); |
| 3135 | empty_region(&seat->drag_surface->input); |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3136 | } |
| 3137 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3138 | static void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3139 | weston_seat_update_drag_surface(struct weston_seat *seat, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3140 | int dx, int dy) |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3141 | { |
| 3142 | int surface_changed = 0; |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3143 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3144 | if (!seat->drag_surface && !seat->seat.drag_surface) |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3145 | return; |
| 3146 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3147 | if (seat->drag_surface && seat->seat.drag_surface && |
| 3148 | (&seat->drag_surface->surface.resource != |
| 3149 | &seat->seat.drag_surface->resource)) |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3150 | /* between calls to this funcion we got a new drag_surface */ |
| 3151 | surface_changed = 1; |
| 3152 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3153 | if (!seat->seat.drag_surface || surface_changed) { |
| 3154 | device_release_drag_surface(seat); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3155 | if (!surface_changed) |
| 3156 | return; |
| 3157 | } |
| 3158 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3159 | if (!seat->drag_surface || surface_changed) { |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3160 | struct weston_surface *surface = (struct weston_surface *) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3161 | seat->seat.drag_surface; |
| 3162 | if (!device_setup_new_drag_surface(seat, surface)) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3163 | return; |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3164 | } |
| 3165 | |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 3166 | /* the client may not have attached a buffer to the drag surface |
| 3167 | * when we setup it up, so check if map is needed on every update */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3168 | device_map_drag_surface(seat); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3169 | |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 3170 | /* the client may have attached a buffer with a different size to |
| 3171 | * the drag surface, causing the input region to be reset */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3172 | if (region_is_undefined(&seat->drag_surface->input)) |
| 3173 | empty_region(&seat->drag_surface->input); |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 3174 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3175 | if (!dx && !dy) |
| 3176 | return; |
| 3177 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3178 | weston_surface_set_position(seat->drag_surface, |
| 3179 | seat->drag_surface->geometry.x + wl_fixed_to_double(dx), |
| 3180 | seat->drag_surface->geometry.y + wl_fixed_to_double(dy)); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | WL_EXPORT void |
| 3184 | weston_compositor_update_drag_surfaces(struct weston_compositor *compositor) |
| 3185 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 3186 | struct weston_seat *seat; |
| 3187 | |
| 3188 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 3189 | weston_seat_update_drag_surface(seat, 0, 0); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 3190 | } |
| 3191 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3192 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3193 | bind_output(struct wl_client *client, |
| 3194 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 3195 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3196 | struct weston_output *output = data; |
| 3197 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 3198 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3199 | |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 3200 | resource = wl_client_add_object(client, |
| 3201 | &wl_output_interface, NULL, id, data); |
| 3202 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3203 | wl_list_insert(&output->resource_list, &resource->link); |
| 3204 | resource->destroy = unbind_resource; |
| 3205 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3206 | wl_output_send_geometry(resource, |
| 3207 | output->x, |
| 3208 | output->y, |
| 3209 | output->mm_width, |
| 3210 | output->mm_height, |
| 3211 | output->subpixel, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 3212 | output->make, output->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 3213 | output->transform); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3214 | |
| 3215 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3216 | wl_output_send_mode(resource, |
| 3217 | mode->flags, |
| 3218 | mode->width, |
| 3219 | mode->height, |
| 3220 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3221 | } |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3222 | } |
| 3223 | |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3224 | static const char vertex_shader[] = |
| 3225 | "uniform mat4 proj;\n" |
Kristian Høgsberg | fa4e2a7 | 2011-02-13 13:44:55 -0500 | [diff] [blame] | 3226 | "attribute vec2 position;\n" |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3227 | "attribute vec2 texcoord;\n" |
| 3228 | "varying vec2 v_texcoord;\n" |
| 3229 | "void main()\n" |
| 3230 | "{\n" |
Kristian Høgsberg | fa4e2a7 | 2011-02-13 13:44:55 -0500 | [diff] [blame] | 3231 | " gl_Position = proj * vec4(position, 0.0, 1.0);\n" |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3232 | " v_texcoord = texcoord;\n" |
| 3233 | "}\n"; |
| 3234 | |
Gwenole Beauchesne | 6d03049 | 2012-04-20 11:15:51 +0200 | [diff] [blame] | 3235 | /* Declare common fragment shader uniforms */ |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3236 | #define FRAGMENT_CONVERT_YUV \ |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3237 | " y *= alpha;\n" \ |
| 3238 | " u *= alpha;\n" \ |
| 3239 | " v *= alpha;\n" \ |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3240 | " gl_FragColor.r = y + 1.59602678 * v;\n" \ |
| 3241 | " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n" \ |
| 3242 | " gl_FragColor.b = y + 2.01723214 * u;\n" \ |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3243 | " gl_FragColor.a = alpha;\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3244 | |
Gwenole Beauchesne | 6d03049 | 2012-04-20 11:15:51 +0200 | [diff] [blame] | 3245 | static const char texture_fragment_shader_rgba[] = |
Kristian Høgsberg | dfce71d | 2010-12-07 20:19:10 -0500 | [diff] [blame] | 3246 | "precision mediump float;\n" |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3247 | "varying vec2 v_texcoord;\n" |
| 3248 | "uniform sampler2D tex;\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3249 | "uniform float alpha;\n" |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3250 | "void main()\n" |
| 3251 | "{\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3252 | " gl_FragColor = alpha * texture2D(tex, v_texcoord)\n;" |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3253 | "}\n"; |
| 3254 | |
Pekka Paalanen | 6b5585b | 2012-08-30 16:47:19 -0500 | [diff] [blame] | 3255 | static const char texture_fragment_shader_rgbx[] = |
| 3256 | "precision mediump float;\n" |
| 3257 | "varying vec2 v_texcoord;\n" |
| 3258 | "uniform sampler2D tex;\n" |
| 3259 | "uniform float alpha;\n" |
| 3260 | "void main()\n" |
| 3261 | "{\n" |
| 3262 | " gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb\n;" |
| 3263 | " gl_FragColor.a = alpha;\n" |
| 3264 | "}\n"; |
| 3265 | |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 3266 | static const char texture_fragment_shader_egl_external[] = |
| 3267 | "#extension GL_OES_EGL_image_external : require\n" |
| 3268 | "precision mediump float;\n" |
| 3269 | "varying vec2 v_texcoord;\n" |
| 3270 | "uniform samplerExternalOES tex;\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3271 | "uniform float alpha;\n" |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 3272 | "void main()\n" |
| 3273 | "{\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3274 | " gl_FragColor = alpha * texture2D(tex, v_texcoord)\n;" |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 3275 | "}\n"; |
| 3276 | |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3277 | static const char texture_fragment_shader_y_uv[] = |
| 3278 | "precision mediump float;\n" |
| 3279 | "uniform sampler2D tex;\n" |
| 3280 | "uniform sampler2D tex1;\n" |
| 3281 | "varying vec2 v_texcoord;\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3282 | "uniform float alpha;\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3283 | "void main() {\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3284 | " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n" |
| 3285 | " float u = texture2D(tex1, v_texcoord).r - 0.5;\n" |
| 3286 | " float v = texture2D(tex1, v_texcoord).g - 0.5;\n" |
| 3287 | FRAGMENT_CONVERT_YUV |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3288 | "}\n"; |
| 3289 | |
| 3290 | static const char texture_fragment_shader_y_u_v[] = |
| 3291 | "precision mediump float;\n" |
| 3292 | "uniform sampler2D tex;\n" |
| 3293 | "uniform sampler2D tex1;\n" |
| 3294 | "uniform sampler2D tex2;\n" |
| 3295 | "varying vec2 v_texcoord;\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3296 | "uniform float alpha;\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3297 | "void main() {\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3298 | " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n" |
| 3299 | " float u = texture2D(tex1, v_texcoord).x - 0.5;\n" |
| 3300 | " float v = texture2D(tex2, v_texcoord).x - 0.5;\n" |
| 3301 | FRAGMENT_CONVERT_YUV |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3302 | "}\n"; |
| 3303 | |
| 3304 | static const char texture_fragment_shader_y_xuxv[] = |
| 3305 | "precision mediump float;\n" |
| 3306 | "uniform sampler2D tex;\n" |
| 3307 | "uniform sampler2D tex1;\n" |
| 3308 | "varying vec2 v_texcoord;\n" |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3309 | "uniform float alpha;\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3310 | "void main() {\n" |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3311 | " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n" |
| 3312 | " float u = texture2D(tex1, v_texcoord).g - 0.5;\n" |
| 3313 | " float v = texture2D(tex1, v_texcoord).a - 0.5;\n" |
| 3314 | FRAGMENT_CONVERT_YUV |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3315 | "}\n"; |
| 3316 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 3317 | static const char solid_fragment_shader[] = |
| 3318 | "precision mediump float;\n" |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 3319 | "uniform vec4 color;\n" |
Kristian Høgsberg | dbae80e | 2012-03-29 11:34:39 -0400 | [diff] [blame] | 3320 | "uniform float alpha;\n" |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 3321 | "void main()\n" |
| 3322 | "{\n" |
Kristian Høgsberg | dbae80e | 2012-03-29 11:34:39 -0400 | [diff] [blame] | 3323 | " gl_FragColor = alpha * color\n;" |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 3324 | "}\n"; |
| 3325 | |
Kristian Høgsberg | a946821 | 2010-06-14 21:03:11 -0400 | [diff] [blame] | 3326 | static int |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3327 | compile_shader(GLenum type, const char *source) |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3328 | { |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3329 | GLuint s; |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3330 | char msg[512]; |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3331 | GLint status; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3332 | |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3333 | s = glCreateShader(type); |
| 3334 | glShaderSource(s, 1, &source, NULL); |
| 3335 | glCompileShader(s); |
| 3336 | glGetShaderiv(s, GL_COMPILE_STATUS, &status); |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3337 | if (!status) { |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3338 | glGetShaderInfoLog(s, sizeof msg, NULL, msg); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3339 | weston_log("shader info: %s\n", msg); |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3340 | return GL_NONE; |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3341 | } |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3342 | |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3343 | return s; |
| 3344 | } |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3345 | |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3346 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3347 | weston_shader_init(struct weston_shader *shader, |
| 3348 | const char *vertex_source, const char *fragment_source) |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3349 | { |
| 3350 | char msg[512]; |
| 3351 | GLint status; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3352 | |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3353 | shader->vertex_shader = |
| 3354 | compile_shader(GL_VERTEX_SHADER, vertex_source); |
| 3355 | shader->fragment_shader = |
| 3356 | compile_shader(GL_FRAGMENT_SHADER, fragment_source); |
| 3357 | |
| 3358 | shader->program = glCreateProgram(); |
| 3359 | glAttachShader(shader->program, shader->vertex_shader); |
| 3360 | glAttachShader(shader->program, shader->fragment_shader); |
| 3361 | glBindAttribLocation(shader->program, 0, "position"); |
| 3362 | glBindAttribLocation(shader->program, 1, "texcoord"); |
| 3363 | |
| 3364 | glLinkProgram(shader->program); |
| 3365 | glGetProgramiv(shader->program, GL_LINK_STATUS, &status); |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3366 | if (!status) { |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3367 | glGetProgramInfoLog(shader->program, sizeof msg, NULL, msg); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3368 | weston_log("link info: %s\n", msg); |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3369 | return -1; |
| 3370 | } |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3371 | |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3372 | shader->proj_uniform = glGetUniformLocation(shader->program, "proj"); |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 3373 | shader->tex_uniforms[0] = glGetUniformLocation(shader->program, "tex"); |
| 3374 | shader->tex_uniforms[1] = glGetUniformLocation(shader->program, "tex1"); |
| 3375 | shader->tex_uniforms[2] = glGetUniformLocation(shader->program, "tex2"); |
Kristian Høgsberg | 541e555 | 2011-12-14 09:24:11 -0500 | [diff] [blame] | 3376 | shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha"); |
Pekka Paalanen | f55f544 | 2012-02-02 16:49:05 +0200 | [diff] [blame] | 3377 | shader->color_uniform = glGetUniformLocation(shader->program, "color"); |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3378 | |
Kristian Høgsberg | 67a21bd | 2010-06-25 18:58:24 -0400 | [diff] [blame] | 3379 | return 0; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 3380 | } |
| 3381 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3382 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3383 | weston_output_destroy(struct weston_output *output) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3384 | { |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 3385 | struct weston_compositor *c = output->compositor; |
| 3386 | |
Kristian Høgsberg | e75cb7f | 2011-06-21 15:27:41 -0400 | [diff] [blame] | 3387 | pixman_region32_fini(&output->region); |
Kristian Høgsberg | 8b72f60 | 2011-06-23 20:46:34 -0400 | [diff] [blame] | 3388 | pixman_region32_fini(&output->previous_damage); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3389 | output->compositor->output_id_pool &= ~(1 << output->id); |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 3390 | |
| 3391 | wl_display_remove_global(c->wl_display, output->global); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3392 | } |
| 3393 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3394 | static void |
| 3395 | weston_output_compute_transform(struct weston_output *output) |
| 3396 | { |
| 3397 | struct weston_matrix transform; |
| 3398 | int flip; |
| 3399 | |
| 3400 | weston_matrix_init(&transform); |
| 3401 | |
| 3402 | switch(output->transform) { |
| 3403 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3404 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3405 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3406 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3407 | flip = -1; |
| 3408 | break; |
| 3409 | default: |
| 3410 | flip = 1; |
| 3411 | break; |
| 3412 | } |
| 3413 | |
| 3414 | switch(output->transform) { |
| 3415 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3416 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3417 | transform.d[0] = flip; |
| 3418 | transform.d[1] = 0; |
| 3419 | transform.d[4] = 0; |
| 3420 | transform.d[5] = 1; |
| 3421 | break; |
| 3422 | case WL_OUTPUT_TRANSFORM_90: |
| 3423 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3424 | transform.d[0] = 0; |
| 3425 | transform.d[1] = -flip; |
| 3426 | transform.d[4] = 1; |
| 3427 | transform.d[5] = 0; |
| 3428 | break; |
| 3429 | case WL_OUTPUT_TRANSFORM_180: |
| 3430 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3431 | transform.d[0] = -flip; |
| 3432 | transform.d[1] = 0; |
| 3433 | transform.d[4] = 0; |
| 3434 | transform.d[5] = -1; |
| 3435 | break; |
| 3436 | case WL_OUTPUT_TRANSFORM_270: |
| 3437 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3438 | transform.d[0] = 0; |
| 3439 | transform.d[1] = flip; |
| 3440 | transform.d[4] = -1; |
| 3441 | transform.d[5] = 0; |
| 3442 | break; |
| 3443 | default: |
| 3444 | break; |
| 3445 | } |
| 3446 | |
| 3447 | weston_matrix_multiply(&output->matrix, &transform); |
| 3448 | } |
| 3449 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3450 | WL_EXPORT void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3451 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3452 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3453 | float magnification; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3454 | struct weston_matrix camera; |
| 3455 | struct weston_matrix modelview; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 3456 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3457 | weston_matrix_init(&output->matrix); |
| 3458 | weston_matrix_translate(&output->matrix, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3459 | -(output->x + (output->border.right + output->width - output->border.left) / 2.0), |
| 3460 | -(output->y + (output->border.bottom + output->height - output->border.top) / 2.0), 0); |
Benjamin Franzke | 1b765ff | 2011-02-18 16:51:37 +0100 | [diff] [blame] | 3461 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3462 | weston_matrix_scale(&output->matrix, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3463 | 2.0 / (output->width + output->border.left + output->border.right), |
| 3464 | -2.0 / (output->height + output->border.top + output->border.bottom), 1); |
| 3465 | |
| 3466 | weston_output_compute_transform(output); |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3467 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3468 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3469 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3470 | weston_matrix_init(&camera); |
| 3471 | weston_matrix_init(&modelview); |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 3472 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3473 | weston_matrix_translate(&camera, output->zoom.trans_x, |
Kristian Høgsberg | 99fd101 | 2012-08-10 09:57:56 -0400 | [diff] [blame] | 3474 | -output->zoom.trans_y, 0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3475 | weston_matrix_invert(&modelview, &camera); |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3476 | weston_matrix_scale(&modelview, magnification, magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3477 | weston_matrix_multiply(&output->matrix, &modelview); |
| 3478 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3479 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3480 | output->dirty = 0; |
| 3481 | } |
| 3482 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3483 | static void |
| 3484 | weston_output_transform_init(struct weston_output *output, uint32_t transform) |
| 3485 | { |
| 3486 | output->transform = transform; |
| 3487 | |
| 3488 | switch (transform) { |
| 3489 | case WL_OUTPUT_TRANSFORM_90: |
| 3490 | case WL_OUTPUT_TRANSFORM_270: |
| 3491 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3492 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3493 | /* Swap width and height */ |
| 3494 | output->width = output->current->height; |
| 3495 | output->height = output->current->width; |
| 3496 | break; |
| 3497 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3498 | case WL_OUTPUT_TRANSFORM_180: |
| 3499 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3500 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3501 | output->width = output->current->width; |
| 3502 | output->height = output->current->height; |
| 3503 | break; |
| 3504 | default: |
| 3505 | break; |
| 3506 | } |
| 3507 | } |
| 3508 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3509 | WL_EXPORT void |
| 3510 | weston_output_move(struct weston_output *output, int x, int y) |
| 3511 | { |
| 3512 | output->x = x; |
| 3513 | output->y = y; |
| 3514 | |
| 3515 | pixman_region32_init(&output->previous_damage); |
| 3516 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3517 | output->width, |
| 3518 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3521 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3522 | weston_output_init(struct weston_output *output, struct weston_compositor *c, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3523 | int x, int y, int width, int height, uint32_t transform) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3524 | { |
| 3525 | output->compositor = c; |
| 3526 | output->x = x; |
| 3527 | output->y = y; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 3528 | output->border.top = 0; |
| 3529 | output->border.bottom = 0; |
| 3530 | output->border.left = 0; |
| 3531 | output->border.right = 0; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3532 | output->mm_width = width; |
| 3533 | output->mm_height = height; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3534 | output->dirty = 1; |
| 3535 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3536 | if (transform != WL_OUTPUT_TRANSFORM_NORMAL) |
| 3537 | output->disable_planes++; |
| 3538 | |
| 3539 | weston_output_transform_init(output, transform); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 3540 | weston_output_init_zoom(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3541 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3542 | weston_output_move(output, x, y); |
Benjamin Franzke | 78db848 | 2012-04-10 18:35:33 +0200 | [diff] [blame] | 3543 | weston_output_damage(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3544 | |
Kristian Høgsberg | 5fb70bf | 2012-05-24 12:29:46 -0400 | [diff] [blame] | 3545 | wl_signal_init(&output->frame_signal); |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 3546 | wl_list_init(&output->animation_list); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3547 | wl_list_init(&output->resource_list); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 3548 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 3549 | output->id = ffs(~output->compositor->output_id_pool) - 1; |
| 3550 | output->compositor->output_id_pool |= 1 << output->id; |
| 3551 | |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 3552 | output->global = |
| 3553 | wl_display_add_global(c->wl_display, &wl_output_interface, |
| 3554 | output, bind_output); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3555 | } |
| 3556 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 3557 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3558 | compositor_bind(struct wl_client *client, |
| 3559 | void *data, uint32_t version, uint32_t id) |
| 3560 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3561 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3562 | |
| 3563 | wl_client_add_object(client, &wl_compositor_interface, |
| 3564 | &compositor_interface, id, compositor); |
| 3565 | } |
| 3566 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3567 | static void |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 3568 | log_uname(void) |
| 3569 | { |
| 3570 | struct utsname usys; |
| 3571 | |
| 3572 | uname(&usys); |
| 3573 | |
| 3574 | weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release, |
| 3575 | usys.version, usys.machine); |
| 3576 | } |
| 3577 | |
| 3578 | static void |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3579 | log_extensions(const char *name, const char *extensions) |
| 3580 | { |
| 3581 | const char *p, *end; |
| 3582 | int l; |
Pekka Paalanen | f1fc10a | 2012-08-06 14:57:06 +0300 | [diff] [blame] | 3583 | int len; |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3584 | |
| 3585 | l = weston_log("%s:", name); |
| 3586 | p = extensions; |
| 3587 | while (*p) { |
| 3588 | end = strchrnul(p, ' '); |
Pekka Paalanen | f1fc10a | 2012-08-06 14:57:06 +0300 | [diff] [blame] | 3589 | len = end - p; |
| 3590 | if (l + len > 78) |
Pekka Paalanen | 4e4167d | 2012-06-11 14:06:05 +0300 | [diff] [blame] | 3591 | l = weston_log_continue("\n" STAMP_SPACE "%.*s", |
Pekka Paalanen | f1fc10a | 2012-08-06 14:57:06 +0300 | [diff] [blame] | 3592 | len, p); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3593 | else |
Pekka Paalanen | f1fc10a | 2012-08-06 14:57:06 +0300 | [diff] [blame] | 3594 | l += weston_log_continue(" %.*s", len, p); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3595 | for (p = end; isspace(*p); p++) |
| 3596 | ; |
| 3597 | } |
| 3598 | weston_log_continue("\n"); |
| 3599 | } |
| 3600 | |
Pekka Paalanen | 4e4167d | 2012-06-11 14:06:05 +0300 | [diff] [blame] | 3601 | static void |
| 3602 | log_egl_gl_info(EGLDisplay egldpy) |
| 3603 | { |
| 3604 | const char *str; |
| 3605 | |
| 3606 | str = eglQueryString(egldpy, EGL_VERSION); |
| 3607 | weston_log("EGL version: %s\n", str ? str : "(null)"); |
| 3608 | |
| 3609 | str = eglQueryString(egldpy, EGL_VENDOR); |
| 3610 | weston_log("EGL vendor: %s\n", str ? str : "(null)"); |
| 3611 | |
| 3612 | str = eglQueryString(egldpy, EGL_CLIENT_APIS); |
| 3613 | weston_log("EGL client APIs: %s\n", str ? str : "(null)"); |
| 3614 | |
| 3615 | str = eglQueryString(egldpy, EGL_EXTENSIONS); |
| 3616 | log_extensions("EGL extensions", str ? str : "(null)"); |
| 3617 | |
| 3618 | str = (char *)glGetString(GL_VERSION); |
| 3619 | weston_log("GL version: %s\n", str ? str : "(null)"); |
| 3620 | |
| 3621 | str = (char *)glGetString(GL_SHADING_LANGUAGE_VERSION); |
| 3622 | weston_log("GLSL version: %s\n", str ? str : "(null)"); |
| 3623 | |
| 3624 | str = (char *)glGetString(GL_VENDOR); |
| 3625 | weston_log("GL vendor: %s\n", str ? str : "(null)"); |
| 3626 | |
| 3627 | str = (char *)glGetString(GL_RENDERER); |
| 3628 | weston_log("GL renderer: %s\n", str ? str : "(null)"); |
| 3629 | |
| 3630 | str = (char *)glGetString(GL_EXTENSIONS); |
| 3631 | log_extensions("GL extensions", str ? str : "(null)"); |
| 3632 | } |
| 3633 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3634 | WL_EXPORT int |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 3635 | weston_compositor_init(struct weston_compositor *ec, |
| 3636 | struct wl_display *display, |
| 3637 | int argc, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 3638 | char *argv[], |
| 3639 | const char *config_file) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3640 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3641 | struct wl_event_loop *loop; |
Daniel Stone | e2ef43a | 2012-06-01 12:14:05 +0100 | [diff] [blame] | 3642 | struct xkb_rule_names xkb_names; |
| 3643 | const struct config_key keyboard_config_keys[] = { |
| 3644 | { "keymap_rules", CONFIG_KEY_STRING, &xkb_names.rules }, |
| 3645 | { "keymap_model", CONFIG_KEY_STRING, &xkb_names.model }, |
| 3646 | { "keymap_layout", CONFIG_KEY_STRING, &xkb_names.layout }, |
| 3647 | { "keymap_variant", CONFIG_KEY_STRING, &xkb_names.variant }, |
| 3648 | { "keymap_options", CONFIG_KEY_STRING, &xkb_names.options }, |
| 3649 | }; |
| 3650 | const struct config_section cs[] = { |
| 3651 | { "keyboard", |
| 3652 | keyboard_config_keys, ARRAY_LENGTH(keyboard_config_keys) }, |
| 3653 | }; |
| 3654 | |
| 3655 | memset(&xkb_names, 0, sizeof(xkb_names)); |
| 3656 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3657 | |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 3658 | ec->wl_display = display; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3659 | wl_signal_init(&ec->destroy_signal); |
| 3660 | wl_signal_init(&ec->activate_signal); |
| 3661 | wl_signal_init(&ec->lock_signal); |
| 3662 | wl_signal_init(&ec->unlock_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3663 | wl_signal_init(&ec->show_input_panel_signal); |
| 3664 | wl_signal_init(&ec->hide_input_panel_signal); |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 3665 | ec->launcher_sock = weston_environment_get_fd("WESTON_LAUNCHER_SOCK"); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3666 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 3667 | ec->output_id_pool = 0; |
| 3668 | |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3669 | if (!wl_display_add_global(display, &wl_compositor_interface, |
| 3670 | ec, compositor_bind)) |
| 3671 | return -1; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 3672 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3673 | wl_list_init(&ec->surface_list); |
| 3674 | wl_list_init(&ec->layer_list); |
| 3675 | wl_list_init(&ec->seat_list); |
| 3676 | wl_list_init(&ec->output_list); |
| 3677 | wl_list_init(&ec->key_binding_list); |
| 3678 | wl_list_init(&ec->button_binding_list); |
| 3679 | wl_list_init(&ec->axis_binding_list); |
| 3680 | wl_list_init(&ec->fade.animation.link); |
| 3681 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3682 | weston_plane_init(&ec->primary_plane, 0, 0); |
| 3683 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3684 | weston_compositor_xkb_init(ec, &xkb_names); |
| 3685 | |
| 3686 | ec->ping_handler = NULL; |
| 3687 | |
| 3688 | screenshooter_create(ec); |
| 3689 | text_cursor_position_notifier_create(ec); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3690 | |
| 3691 | wl_data_device_manager_init(ec->wl_display); |
| 3692 | |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 3693 | wl_display_init_shm(display); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3694 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3695 | loop = wl_display_get_event_loop(ec->wl_display); |
| 3696 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
| 3697 | wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000); |
| 3698 | |
| 3699 | ec->input_loop = wl_event_loop_create(); |
| 3700 | |
| 3701 | return 0; |
| 3702 | } |
| 3703 | |
| 3704 | WL_EXPORT int |
| 3705 | weston_compositor_init_gl(struct weston_compositor *ec) |
| 3706 | { |
| 3707 | const char *extensions; |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 3708 | int has_egl_image_external = 0; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3709 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 3710 | log_egl_gl_info(ec->egl_display); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3711 | |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3712 | ec->image_target_texture_2d = |
| 3713 | (void *) eglGetProcAddress("glEGLImageTargetTexture2DOES"); |
| 3714 | ec->image_target_renderbuffer_storage = (void *) |
| 3715 | eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES"); |
| 3716 | ec->create_image = (void *) eglGetProcAddress("eglCreateImageKHR"); |
| 3717 | ec->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR"); |
| 3718 | ec->bind_display = |
| 3719 | (void *) eglGetProcAddress("eglBindWaylandDisplayWL"); |
| 3720 | ec->unbind_display = |
| 3721 | (void *) eglGetProcAddress("eglUnbindWaylandDisplayWL"); |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 3722 | ec->query_buffer = |
| 3723 | (void *) eglGetProcAddress("eglQueryWaylandBufferWL"); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3724 | |
| 3725 | extensions = (const char *) glGetString(GL_EXTENSIONS); |
Pekka Paalanen | 299e58d | 2012-04-12 14:45:35 +0300 | [diff] [blame] | 3726 | if (!extensions) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3727 | weston_log("Retrieving GL extension string failed.\n"); |
Pekka Paalanen | 299e58d | 2012-04-12 14:45:35 +0300 | [diff] [blame] | 3728 | return -1; |
| 3729 | } |
| 3730 | |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3731 | if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3732 | weston_log("GL_EXT_texture_format_BGRA8888 not available\n"); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3733 | return -1; |
| 3734 | } |
| 3735 | |
Pekka Paalanen | a1d57db | 2012-04-17 15:02:08 +0300 | [diff] [blame] | 3736 | if (strstr(extensions, "GL_EXT_read_format_bgra")) |
| 3737 | ec->read_format = GL_BGRA_EXT; |
| 3738 | else |
| 3739 | ec->read_format = GL_RGBA; |
Kristian Høgsberg | f9247dd | 2012-03-27 15:25:46 -0400 | [diff] [blame] | 3740 | |
Pekka Paalanen | 52bfbaa | 2012-04-11 16:19:37 +0300 | [diff] [blame] | 3741 | if (strstr(extensions, "GL_EXT_unpack_subimage")) |
| 3742 | ec->has_unpack_subimage = 1; |
Kristian Høgsberg | fb6de22 | 2012-03-27 17:10:13 -0400 | [diff] [blame] | 3743 | |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 3744 | if (strstr(extensions, "GL_OES_EGL_image_external")) |
| 3745 | has_egl_image_external = 1; |
| 3746 | |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3747 | extensions = |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 3748 | (const char *) eglQueryString(ec->egl_display, EGL_EXTENSIONS); |
Pekka Paalanen | 299e58d | 2012-04-12 14:45:35 +0300 | [diff] [blame] | 3749 | if (!extensions) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3750 | weston_log("Retrieving EGL extension string failed.\n"); |
Pekka Paalanen | 299e58d | 2012-04-12 14:45:35 +0300 | [diff] [blame] | 3751 | return -1; |
| 3752 | } |
| 3753 | |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3754 | if (strstr(extensions, "EGL_WL_bind_wayland_display")) |
| 3755 | ec->has_bind_display = 1; |
| 3756 | if (ec->has_bind_display) |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 3757 | ec->bind_display(ec->egl_display, ec->wl_display); |
Kristian Høgsberg | 3d5bae0 | 2010-10-06 21:17:40 -0400 | [diff] [blame] | 3758 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3759 | weston_spring_init(&ec->fade.spring, 30.0, 1.0, 1.0); |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 3760 | ec->fade.animation.frame = fade_frame; |
Kristian Høgsberg | 3555d09 | 2011-04-11 13:58:13 -0400 | [diff] [blame] | 3761 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3762 | weston_layer_init(&ec->fade_layer, &ec->layer_list); |
| 3763 | weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link); |
| 3764 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 3765 | glActiveTexture(GL_TEXTURE0); |
Kristian Høgsberg | 7ffc448 | 2011-04-22 14:23:51 -0400 | [diff] [blame] | 3766 | |
Gwenole Beauchesne | 6d03049 | 2012-04-20 11:15:51 +0200 | [diff] [blame] | 3767 | if (weston_shader_init(&ec->texture_shader_rgba, |
| 3768 | vertex_shader, texture_fragment_shader_rgba) < 0) |
Kristian Høgsberg | a946821 | 2010-06-14 21:03:11 -0400 | [diff] [blame] | 3769 | return -1; |
Pekka Paalanen | 6b5585b | 2012-08-30 16:47:19 -0500 | [diff] [blame] | 3770 | if (weston_shader_init(&ec->texture_shader_rgbx, |
| 3771 | vertex_shader, texture_fragment_shader_rgbx) < 0) |
| 3772 | return -1; |
Rob Clark | e3b9591 | 2012-08-31 16:42:18 -0500 | [diff] [blame] | 3773 | if (has_egl_image_external && |
| 3774 | weston_shader_init(&ec->texture_shader_egl_external, |
| 3775 | vertex_shader, texture_fragment_shader_egl_external) < 0) |
| 3776 | return -1; |
Gwenole Beauchesne | faf9185 | 2012-04-20 11:22:16 +0200 | [diff] [blame] | 3777 | if (weston_shader_init(&ec->texture_shader_y_uv, |
| 3778 | vertex_shader, texture_fragment_shader_y_uv) < 0) |
| 3779 | return -1; |
| 3780 | if (weston_shader_init(&ec->texture_shader_y_u_v, |
| 3781 | vertex_shader, texture_fragment_shader_y_u_v) < 0) |
| 3782 | return -1; |
| 3783 | if (weston_shader_init(&ec->texture_shader_y_xuxv, |
| 3784 | vertex_shader, texture_fragment_shader_y_xuxv) < 0) |
| 3785 | return -1; |
Pekka Paalanen | f55f544 | 2012-02-02 16:49:05 +0200 | [diff] [blame] | 3786 | if (weston_shader_init(&ec->solid_shader, |
| 3787 | vertex_shader, solid_fragment_shader) < 0) |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 3788 | return -1; |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 3789 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3790 | weston_compositor_schedule_repaint(ec); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3791 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3792 | return 0; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3793 | } |
| 3794 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 3795 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3796 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3797 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3798 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3799 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3800 | wl_event_source_remove(ec->idle_source); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 3801 | if (ec->input_loop_source) |
| 3802 | wl_event_source_remove(ec->input_loop_source); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3803 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3804 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 3805 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3806 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 3807 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3808 | weston_binding_list_destroy_all(&ec->key_binding_list); |
| 3809 | weston_binding_list_destroy_all(&ec->button_binding_list); |
| 3810 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3811 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3812 | weston_plane_release(&ec->primary_plane); |
| 3813 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3814 | wl_array_release(&ec->vertices); |
| 3815 | wl_array_release(&ec->indices); |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3816 | wl_array_release(&ec->vtxcnt); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 3817 | |
| 3818 | wl_event_loop_destroy(ec->input_loop); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 3821 | static int on_term_signal(int signal_number, void *data) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3822 | { |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 3823 | struct wl_display *display = data; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3824 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3825 | weston_log("caught signal %d\n", signal_number); |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 3826 | wl_display_terminate(display); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 3827 | |
| 3828 | return 1; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3829 | } |
| 3830 | |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3831 | static void |
| 3832 | on_segv_signal(int s, siginfo_t *siginfo, void *context) |
| 3833 | { |
| 3834 | void *buffer[32]; |
| 3835 | int i, count; |
| 3836 | Dl_info info; |
| 3837 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3838 | /* This SIGSEGV handler will do a best-effort backtrace, and |
| 3839 | * then call the backend restore function, which will switch |
| 3840 | * back to the vt we launched from or ungrab X etc and then |
| 3841 | * raise SIGTRAP. If we run weston under gdb from X or a |
| 3842 | * different vt, and tell gdb "handle SIGSEGV nostop", this |
| 3843 | * will allow weston to switch back to gdb on crash and then |
| 3844 | * gdb will catch the crash with SIGTRAP. */ |
| 3845 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3846 | weston_log("caught segv\n"); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3847 | |
| 3848 | count = backtrace(buffer, ARRAY_LENGTH(buffer)); |
| 3849 | for (i = 0; i < count; i++) { |
| 3850 | dladdr(buffer[i], &info); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3851 | weston_log(" [%016lx] %s (%s)\n", |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3852 | (long) buffer[i], |
| 3853 | info.dli_sname ? info.dli_sname : "--", |
| 3854 | info.dli_fname); |
| 3855 | } |
| 3856 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3857 | segv_compositor->restore(segv_compositor); |
| 3858 | |
| 3859 | raise(SIGTRAP); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3863 | static void * |
| 3864 | load_module(const char *name, const char *entrypoint, void **handle) |
| 3865 | { |
| 3866 | char path[PATH_MAX]; |
| 3867 | void *module, *init; |
| 3868 | |
| 3869 | if (name[0] != '/') |
Chad Versace | bf38190 | 2012-05-23 23:42:15 -0700 | [diff] [blame] | 3870 | snprintf(path, sizeof path, "%s/%s", MODULEDIR, name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3871 | else |
Benjamin Franzke | b7acce6 | 2011-05-06 23:19:22 +0200 | [diff] [blame] | 3872 | snprintf(path, sizeof path, "%s", name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3873 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3874 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 3875 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3876 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3877 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3878 | return NULL; |
| 3879 | } |
| 3880 | |
| 3881 | init = dlsym(module, entrypoint); |
| 3882 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3883 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3884 | return NULL; |
| 3885 | } |
| 3886 | |
| 3887 | return init; |
| 3888 | } |
| 3889 | |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 3890 | static const char xdg_error_message[] = |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3891 | "fatal: environment variable XDG_RUNTIME_DIR is not set.\n"; |
| 3892 | |
| 3893 | static const char xdg_wrong_message[] = |
| 3894 | "fatal: environment variable XDG_RUNTIME_DIR\n" |
| 3895 | "is set to \"%s\", which is not a directory.\n"; |
| 3896 | |
| 3897 | static const char xdg_wrong_mode_message[] = |
| 3898 | "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n" |
| 3899 | "correctly. Unix access mode must be 0700 but is %o,\n" |
| 3900 | "and XDG_RUNTIME_DIR must be owned by the user, but is\n" |
Kristian Høgsberg | 3033425 | 2012-06-20 14:24:21 -0400 | [diff] [blame] | 3901 | "owned by UID %d.\n"; |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3902 | |
| 3903 | static const char xdg_detail_message[] = |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 3904 | "Refer to your distribution on how to get it, or\n" |
| 3905 | "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" |
| 3906 | "on how to implement it.\n"; |
| 3907 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3908 | static void |
| 3909 | verify_xdg_runtime_dir(void) |
| 3910 | { |
| 3911 | char *dir = getenv("XDG_RUNTIME_DIR"); |
| 3912 | struct stat s; |
| 3913 | |
| 3914 | if (!dir) { |
| 3915 | weston_log(xdg_error_message); |
| 3916 | weston_log_continue(xdg_detail_message); |
| 3917 | exit(EXIT_FAILURE); |
| 3918 | } |
| 3919 | |
| 3920 | if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { |
| 3921 | weston_log(xdg_wrong_message, dir); |
| 3922 | weston_log_continue(xdg_detail_message); |
| 3923 | exit(EXIT_FAILURE); |
| 3924 | } |
| 3925 | |
| 3926 | if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) { |
| 3927 | weston_log(xdg_wrong_mode_message, |
| 3928 | dir, s.st_mode & 0777, s.st_uid); |
| 3929 | weston_log_continue(xdg_detail_message); |
| 3930 | } |
| 3931 | } |
| 3932 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3933 | static int |
| 3934 | usage(int error_code) |
| 3935 | { |
| 3936 | fprintf(stderr, |
| 3937 | "Usage: weston [OPTIONS]\n\n" |
| 3938 | "This is weston version " VERSION ", the Wayland reference compositor.\n" |
| 3939 | "Weston supports multiple backends, and depending on which backend is in use\n" |
| 3940 | "different options will be accepted.\n\n" |
| 3941 | |
| 3942 | |
| 3943 | "Core options:\n\n" |
| 3944 | " -B, --backend=MODULE\tBackend module, one of drm-backend.so,\n" |
| 3945 | "\t\t\t\tx11-backend.so or wayland-backend.so\n" |
| 3946 | " -S, --socket=NAME\tName of socket to listen on\n" |
| 3947 | " -i, --idle-time=SECS\tIdle time in seconds\n" |
| 3948 | " --xserver\t\tEnable X server integration\n" |
| 3949 | " --module\t\tLoad the specified module\n" |
| 3950 | " --log==FILE\t\tLog to the given file\n" |
| 3951 | " -h, --help\t\tThis help message\n\n"); |
| 3952 | |
| 3953 | fprintf(stderr, |
| 3954 | "Options for drm-backend.so:\n\n" |
| 3955 | " --connector=ID\tBring up only this connector\n" |
| 3956 | " --seat=SEAT\t\tThe seat that weston should run on\n" |
| 3957 | " --tty=TTY\t\tThe tty to use\n" |
| 3958 | " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n"); |
| 3959 | |
| 3960 | fprintf(stderr, |
| 3961 | "Options for x11-backend.so:\n\n" |
| 3962 | " --width=WIDTH\t\tWidth of X window\n" |
| 3963 | " --height=HEIGHT\tHeight of X window\n" |
| 3964 | " --fullscreen\t\tRun in fullscreen mode\n" |
| 3965 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 3966 | " --no-input\t\tDont create input devices\n\n"); |
| 3967 | |
| 3968 | fprintf(stderr, |
| 3969 | "Options for wayland-backend.so:\n\n" |
| 3970 | " --width=WIDTH\t\tWidth of Wayland surface\n" |
| 3971 | " --height=HEIGHT\tHeight of Wayland surface\n" |
| 3972 | " --display=DISPLAY\tWayland display to connect to\n\n"); |
| 3973 | |
| 3974 | exit(error_code); |
| 3975 | } |
| 3976 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3977 | int main(int argc, char *argv[]) |
| 3978 | { |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 3979 | int ret = EXIT_SUCCESS; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3980 | struct wl_display *display; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3981 | struct weston_compositor *ec; |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3982 | struct wl_event_source *signals[4]; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3983 | struct wl_event_loop *loop; |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3984 | struct sigaction segv_action; |
Kristian Høgsberg | d012e9d | 2012-04-12 10:37:23 -0400 | [diff] [blame] | 3985 | void *shell_module, *backend_module, *xserver_module; |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 3986 | int (*module_init)(struct weston_compositor *ec); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3987 | struct weston_compositor |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3988 | *(*backend_init)(struct wl_display *display, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 3989 | int argc, char *argv[], const char *config_file); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3990 | int i; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3991 | char *backend = NULL; |
| 3992 | char *shell = NULL; |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 3993 | char *module = NULL; |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3994 | char *log = NULL; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3995 | int32_t idle_time = 300; |
Scott Moreau | e17f610 | 2012-04-25 10:03:06 -0600 | [diff] [blame] | 3996 | int32_t xserver = 0; |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3997 | int32_t help = 0; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3998 | char *socket_name = NULL; |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3999 | char *config_file; |
| 4000 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 4001 | const struct config_key shell_config_keys[] = { |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 4002 | { "type", CONFIG_KEY_STRING, &shell }, |
| 4003 | }; |
| 4004 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 4005 | const struct config_section cs[] = { |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 4006 | { "shell", |
| 4007 | shell_config_keys, ARRAY_LENGTH(shell_config_keys) }, |
| 4008 | }; |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 4009 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4010 | const struct weston_option core_options[] = { |
| 4011 | { WESTON_OPTION_STRING, "backend", 'B', &backend }, |
| 4012 | { WESTON_OPTION_STRING, "socket", 'S', &socket_name }, |
| 4013 | { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4014 | { WESTON_OPTION_BOOLEAN, "xserver", 0, &xserver }, |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 4015 | { WESTON_OPTION_STRING, "module", 0, &module }, |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 4016 | { WESTON_OPTION_STRING, "log", 0, &log }, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4017 | { WESTON_OPTION_BOOLEAN, "help", 'h', &help }, |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 4018 | }; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 4019 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4020 | argc = parse_options(core_options, |
| 4021 | ARRAY_LENGTH(core_options), argc, argv); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4022 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4023 | if (help) |
| 4024 | usage(EXIT_SUCCESS); |
| 4025 | |
Rafal Mielniczuk | 6e0a7d8 | 2012-06-09 15:10:28 +0200 | [diff] [blame] | 4026 | weston_log_file_open(log); |
| 4027 | |
Pekka Paalanen | bce4c2b | 2012-06-11 14:04:21 +0300 | [diff] [blame] | 4028 | weston_log("%s\n" |
| 4029 | STAMP_SPACE "%s\n" |
| 4030 | STAMP_SPACE "Bug reports to: %s\n" |
| 4031 | STAMP_SPACE "Build: %s\n", |
| 4032 | PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT, |
Kristian Høgsberg | 23cf9eb | 2012-06-11 12:06:30 -0400 | [diff] [blame] | 4033 | BUILD_ID); |
Pekka Paalanen | 7f4d1a3 | 2012-06-11 14:06:03 +0300 | [diff] [blame] | 4034 | log_uname(); |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 4035 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4036 | verify_xdg_runtime_dir(); |
| 4037 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4038 | display = wl_display_create(); |
| 4039 | |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 4040 | loop = wl_display_get_event_loop(display); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 4041 | signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, |
| 4042 | display); |
| 4043 | signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal, |
| 4044 | display); |
| 4045 | signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal, |
| 4046 | display); |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 4047 | |
| 4048 | wl_list_init(&child_process_list); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 4049 | signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler, |
| 4050 | NULL); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 4051 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4052 | if (!backend) { |
| 4053 | if (getenv("WAYLAND_DISPLAY")) |
| 4054 | backend = "wayland-backend.so"; |
| 4055 | else if (getenv("DISPLAY")) |
| 4056 | backend = "x11-backend.so"; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4057 | else |
| 4058 | backend = "drm-backend.so"; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4059 | } |
| 4060 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 4061 | config_file = config_file_path("weston.ini"); |
| 4062 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 4063 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4064 | backend_init = load_module(backend, "backend_init", &backend_module); |
| 4065 | if (!backend_init) |
| 4066 | exit(EXIT_FAILURE); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 4067 | |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 4068 | ec = backend_init(display, argc, argv, config_file); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 4069 | if (ec == NULL) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4070 | weston_log("fatal: failed to create compositor\n"); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 4071 | exit(EXIT_FAILURE); |
| 4072 | } |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 4073 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4074 | segv_action.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 4075 | segv_action.sa_sigaction = on_segv_signal; |
| 4076 | sigemptyset(&segv_action.sa_mask); |
| 4077 | sigaction(SIGSEGV, &segv_action, NULL); |
| 4078 | segv_compositor = ec; |
| 4079 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4080 | for (i = 1; argv[i]; i++) |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4081 | weston_log("fatal: unhandled option: %s\n", argv[i]); |
| 4082 | if (argv[1]) { |
| 4083 | ret = EXIT_FAILURE; |
| 4084 | goto out; |
| 4085 | } |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4086 | |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 4087 | free(config_file); |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 4088 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4089 | ec->option_idle_time = idle_time; |
| 4090 | ec->idle_time = idle_time; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 4091 | |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 4092 | module_init = NULL; |
Kristian Høgsberg | d012e9d | 2012-04-12 10:37:23 -0400 | [diff] [blame] | 4093 | if (xserver) |
Tiago Vignatti | 629ce23 | 2012-05-23 23:04:14 +0300 | [diff] [blame] | 4094 | module_init = load_module("xwayland.so", |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 4095 | "weston_xserver_init", |
| 4096 | &xserver_module); |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4097 | if (module_init && module_init(ec) < 0) { |
| 4098 | ret = EXIT_FAILURE; |
| 4099 | goto out; |
| 4100 | } |
Kristian Høgsberg | d012e9d | 2012-04-12 10:37:23 -0400 | [diff] [blame] | 4101 | |
Kristian Høgsberg | 33d7509 | 2012-08-13 13:56:03 -0400 | [diff] [blame] | 4102 | if (socket_name) |
| 4103 | setenv("WAYLAND_DISPLAY", socket_name, 1); |
| 4104 | |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 4105 | if (!shell) |
| 4106 | shell = "desktop-shell.so"; |
| 4107 | module_init = load_module(shell, "shell_init", &shell_module); |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4108 | if (!module_init || module_init(ec) < 0) { |
| 4109 | ret = EXIT_FAILURE; |
| 4110 | goto out; |
| 4111 | } |
Kristian Høgsberg | 306e361 | 2012-04-12 12:54:14 -0400 | [diff] [blame] | 4112 | |
| 4113 | |
| 4114 | module_init = NULL; |
| 4115 | if (module) |
| 4116 | module_init = load_module(module, "module_init", NULL); |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4117 | if (module_init && module_init(ec) < 0) { |
| 4118 | ret = EXIT_FAILURE; |
| 4119 | goto out; |
| 4120 | } |
Tiago Vignatti | e4faa2a | 2012-04-16 17:31:44 +0300 | [diff] [blame] | 4121 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4122 | if (wl_display_add_socket(display, socket_name)) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4123 | weston_log("fatal: failed to add socket: %m\n"); |
| 4124 | ret = EXIT_FAILURE; |
| 4125 | goto out; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4126 | } |
| 4127 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4128 | weston_compositor_dpms_on(ec); |
Pekka Paalanen | c0444e3 | 2012-01-05 16:28:21 +0200 | [diff] [blame] | 4129 | weston_compositor_wake(ec); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4130 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4131 | wl_display_run(display); |
| 4132 | |
| 4133 | out: |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 4134 | /* prevent further rendering while shutting down */ |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 4135 | ec->state = WESTON_COMPOSITOR_SLEEPING; |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 4136 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4137 | wl_signal_emit(&ec->destroy_signal, ec); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4138 | |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 4139 | if (ec->has_bind_display) |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 4140 | ec->unbind_display(ec->egl_display, display); |
Kristian Høgsberg | 2bb3ebe | 2010-12-01 15:36:20 -0500 | [diff] [blame] | 4141 | |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 4142 | for (i = ARRAY_LENGTH(signals); i;) |
| 4143 | wl_event_source_remove(signals[--i]); |
| 4144 | |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 4145 | weston_compositor_xkb_destroy(ec); |
| 4146 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 4147 | ec->destroy(ec); |
Tiago Vignatti | 9e2be08 | 2011-12-19 00:04:46 +0200 | [diff] [blame] | 4148 | wl_display_destroy(display); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 4149 | |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 4150 | weston_log_file_close(); |
| 4151 | |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 4152 | return ret; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 4153 | } |