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