Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2008-2011 Kristian Høgsberg |
| 3 | * Copyright © 2011 Intel Corporation |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 4 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 14 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 24 | #include "config.h" |
Kristian Høgsberg | 0b9334a | 2011-04-12 11:34:32 -0400 | [diff] [blame] | 25 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 26 | #include <errno.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 27 | #include <stdlib.h> |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 28 | #include <ctype.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 33 | #include <linux/vt.h> |
Ander Conselvan de Oliveira | fd1f4c6 | 2012-06-26 17:09:14 +0300 | [diff] [blame] | 34 | #include <assert.h> |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 35 | #include <sys/mman.h> |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 36 | #include <dlfcn.h> |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 37 | #include <time.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 38 | |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 39 | #include <xf86drm.h> |
| 40 | #include <xf86drmMode.h> |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 41 | #include <drm_fourcc.h> |
Benjamin Franzke | c649a92 | 2011-03-02 11:56:04 +0100 | [diff] [blame] | 42 | |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 43 | #include <gbm.h> |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 44 | #include <libudev.h> |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 45 | |
Kristian Høgsberg | 36d5fac | 2014-01-27 23:02:35 -0800 | [diff] [blame] | 46 | #include "libbacklight.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 47 | #include "compositor.h" |
John Kåre Alsaker | 30d2b1f | 2012-11-13 19:10:28 +0100 | [diff] [blame] | 48 | #include "gl-renderer.h" |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 49 | #include "pixman-renderer.h" |
Peter Hutterer | 823ad33 | 2014-11-26 07:06:31 +1000 | [diff] [blame] | 50 | #include "libinput-seat.h" |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 51 | #include "launcher-util.h" |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 52 | #include "vaapi-recorder.h" |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 53 | #include "presentation_timing-server-protocol.h" |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 54 | |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 55 | #ifndef DRM_CAP_TIMESTAMP_MONOTONIC |
| 56 | #define DRM_CAP_TIMESTAMP_MONOTONIC 0x6 |
| 57 | #endif |
| 58 | |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 59 | #ifndef DRM_CAP_CURSOR_WIDTH |
| 60 | #define DRM_CAP_CURSOR_WIDTH 0x8 |
| 61 | #endif |
| 62 | |
| 63 | #ifndef DRM_CAP_CURSOR_HEIGHT |
| 64 | #define DRM_CAP_CURSOR_HEIGHT 0x9 |
| 65 | #endif |
| 66 | |
| 67 | #ifndef GBM_BO_USE_CURSOR |
| 68 | #define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64 |
| 69 | #endif |
| 70 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 71 | static int option_current_mode = 0; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 72 | |
| 73 | enum output_config { |
| 74 | OUTPUT_CONFIG_INVALID = 0, |
| 75 | OUTPUT_CONFIG_OFF, |
| 76 | OUTPUT_CONFIG_PREFERRED, |
| 77 | OUTPUT_CONFIG_CURRENT, |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 78 | OUTPUT_CONFIG_MODE, |
| 79 | OUTPUT_CONFIG_MODELINE |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 82 | struct drm_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 83 | struct weston_compositor base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 84 | |
| 85 | struct udev *udev; |
| 86 | struct wl_event_source *drm_source; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 87 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 88 | struct udev_monitor *udev_monitor; |
| 89 | struct wl_event_source *udev_drm_source; |
| 90 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 91 | struct { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 92 | int id; |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 93 | int fd; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 94 | char *filename; |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 95 | } drm; |
Benjamin Franzke | 060cf80 | 2011-04-30 09:32:11 +0200 | [diff] [blame] | 96 | struct gbm_device *gbm; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 97 | uint32_t *crtcs; |
| 98 | int num_crtcs; |
Marty Jack | 13d9db2 | 2011-02-09 19:01:42 -0500 | [diff] [blame] | 99 | uint32_t crtc_allocator; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 100 | uint32_t connector_allocator; |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 101 | struct wl_listener session_listener; |
Kristian Høgsberg | c3ea26c | 2013-09-25 15:46:42 -0700 | [diff] [blame] | 102 | uint32_t format; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 103 | |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 104 | /* we need these parameters in order to not fail drmModeAddFB2() |
| 105 | * due to out of bounds dimensions, and then mistakenly set |
| 106 | * sprites_are_broken: |
| 107 | */ |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 108 | uint32_t min_width, max_width; |
| 109 | uint32_t min_height, max_height; |
| 110 | int no_addfb2; |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 111 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 112 | struct wl_list sprite_list; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 113 | int sprites_are_broken; |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 114 | int sprites_hidden; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 115 | |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 116 | int cursors_are_broken; |
| 117 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 118 | int use_pixman; |
| 119 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 120 | uint32_t prev_state; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 121 | |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 122 | struct udev_input input; |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 123 | |
| 124 | uint32_t cursor_width; |
| 125 | uint32_t cursor_height; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 126 | }; |
| 127 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 128 | struct drm_mode { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 129 | struct weston_mode base; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 130 | drmModeModeInfo mode_info; |
| 131 | }; |
| 132 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 133 | struct drm_output; |
| 134 | |
| 135 | struct drm_fb { |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 136 | struct drm_output *output; |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 137 | uint32_t fb_id, stride, handle, size; |
| 138 | int fd; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 139 | int is_client_buffer; |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 140 | struct weston_buffer_reference buffer_ref; |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 141 | |
| 142 | /* Used by gbm fbs */ |
| 143 | struct gbm_bo *bo; |
| 144 | |
| 145 | /* Used by dumb fbs */ |
| 146 | void *map; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 147 | }; |
| 148 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 149 | struct drm_edid { |
| 150 | char eisa_id[13]; |
| 151 | char monitor_name[13]; |
| 152 | char pnp_id[5]; |
| 153 | char serial_number[13]; |
| 154 | }; |
| 155 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 156 | struct drm_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 157 | struct weston_output base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 158 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 159 | uint32_t crtc_id; |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 160 | int pipe; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 161 | uint32_t connector_id; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 162 | drmModeCrtcPtr original_crtc; |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 163 | struct drm_edid edid; |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 164 | drmModePropertyPtr dpms_prop; |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 165 | uint32_t format; |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 166 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 167 | int vblank_pending; |
| 168 | int page_flip_pending; |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 169 | int destroy_pending; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 170 | |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 171 | struct gbm_surface *surface; |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 172 | struct gbm_bo *cursor_bo[2]; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 173 | struct weston_plane cursor_plane; |
| 174 | struct weston_plane fb_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 175 | struct weston_view *cursor_view; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 176 | int current_cursor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 177 | struct drm_fb *current, *next; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 178 | struct backlight *backlight; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 179 | |
| 180 | struct drm_fb *dumb[2]; |
| 181 | pixman_image_t *image[2]; |
| 182 | int current_image; |
| 183 | pixman_region32_t previous_damage; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 184 | |
| 185 | struct vaapi_recorder *recorder; |
| 186 | struct wl_listener recorder_frame_listener; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 187 | }; |
| 188 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 189 | /* |
| 190 | * An output has a primary display plane plus zero or more sprites for |
| 191 | * blending display contents. |
| 192 | */ |
| 193 | struct drm_sprite { |
| 194 | struct wl_list link; |
| 195 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 196 | struct weston_plane plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 197 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 198 | struct drm_fb *current, *next; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 199 | struct drm_output *output; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 200 | struct drm_compositor *compositor; |
| 201 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 202 | uint32_t possible_crtcs; |
| 203 | uint32_t plane_id; |
| 204 | uint32_t count_formats; |
| 205 | |
| 206 | int32_t src_x, src_y; |
| 207 | uint32_t src_w, src_h; |
| 208 | uint32_t dest_x, dest_y; |
| 209 | uint32_t dest_w, dest_h; |
| 210 | |
| 211 | uint32_t formats[]; |
| 212 | }; |
| 213 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 214 | struct drm_parameters { |
| 215 | int connector; |
| 216 | int tty; |
| 217 | int use_pixman; |
| 218 | const char *seat_id; |
| 219 | }; |
| 220 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 221 | static struct gl_renderer_interface *gl_renderer; |
| 222 | |
Kristian Høgsberg | 98cfea6 | 2013-02-18 16:15:53 -0500 | [diff] [blame] | 223 | static const char default_seat[] = "seat0"; |
Pekka Paalanen | 3315697 | 2012-08-03 13:30:30 -0400 | [diff] [blame] | 224 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 225 | static void |
| 226 | drm_output_set_cursor(struct drm_output *output); |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 227 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 228 | static int |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 229 | drm_sprite_crtc_supported(struct drm_output *output, uint32_t supported) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 230 | { |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 231 | struct weston_compositor *ec = output->base.compositor; |
| 232 | struct drm_compositor *c = (struct drm_compositor *)ec; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 233 | int crtc; |
| 234 | |
| 235 | for (crtc = 0; crtc < c->num_crtcs; crtc++) { |
| 236 | if (c->crtcs[crtc] != output->crtc_id) |
| 237 | continue; |
| 238 | |
| 239 | if (supported & (1 << crtc)) |
| 240 | return -1; |
| 241 | } |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 246 | static void |
| 247 | drm_fb_destroy_callback(struct gbm_bo *bo, void *data) |
| 248 | { |
| 249 | struct drm_fb *fb = data; |
| 250 | struct gbm_device *gbm = gbm_bo_get_device(bo); |
| 251 | |
| 252 | if (fb->fb_id) |
| 253 | drmModeRmFB(gbm_device_get_fd(gbm), fb->fb_id); |
| 254 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 255 | weston_buffer_reference(&fb->buffer_ref, NULL); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 256 | |
| 257 | free(data); |
| 258 | } |
| 259 | |
| 260 | static struct drm_fb * |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 261 | drm_fb_create_dumb(struct drm_compositor *ec, unsigned width, unsigned height) |
| 262 | { |
| 263 | struct drm_fb *fb; |
| 264 | int ret; |
| 265 | |
| 266 | struct drm_mode_create_dumb create_arg; |
| 267 | struct drm_mode_destroy_dumb destroy_arg; |
| 268 | struct drm_mode_map_dumb map_arg; |
| 269 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 270 | fb = zalloc(sizeof *fb); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 271 | if (!fb) |
| 272 | return NULL; |
| 273 | |
Kristian Høgsberg | ac6104e | 2013-08-21 22:14:14 -0700 | [diff] [blame] | 274 | memset(&create_arg, 0, sizeof create_arg); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 275 | create_arg.bpp = 32; |
| 276 | create_arg.width = width; |
| 277 | create_arg.height = height; |
| 278 | |
| 279 | ret = drmIoctl(ec->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg); |
| 280 | if (ret) |
| 281 | goto err_fb; |
| 282 | |
| 283 | fb->handle = create_arg.handle; |
| 284 | fb->stride = create_arg.pitch; |
| 285 | fb->size = create_arg.size; |
| 286 | fb->fd = ec->drm.fd; |
| 287 | |
| 288 | ret = drmModeAddFB(ec->drm.fd, width, height, 24, 32, |
| 289 | fb->stride, fb->handle, &fb->fb_id); |
| 290 | if (ret) |
| 291 | goto err_bo; |
| 292 | |
Kristian Høgsberg | ac6104e | 2013-08-21 22:14:14 -0700 | [diff] [blame] | 293 | memset(&map_arg, 0, sizeof map_arg); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 294 | map_arg.handle = fb->handle; |
Chris Michael | eb2074a | 2013-05-01 21:26:02 -0400 | [diff] [blame] | 295 | ret = drmIoctl(fb->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 296 | if (ret) |
| 297 | goto err_add_fb; |
| 298 | |
| 299 | fb->map = mmap(0, fb->size, PROT_WRITE, |
| 300 | MAP_SHARED, ec->drm.fd, map_arg.offset); |
| 301 | if (fb->map == MAP_FAILED) |
| 302 | goto err_add_fb; |
| 303 | |
| 304 | return fb; |
| 305 | |
| 306 | err_add_fb: |
| 307 | drmModeRmFB(ec->drm.fd, fb->fb_id); |
| 308 | err_bo: |
| 309 | memset(&destroy_arg, 0, sizeof(destroy_arg)); |
| 310 | destroy_arg.handle = create_arg.handle; |
| 311 | drmIoctl(ec->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg); |
| 312 | err_fb: |
| 313 | free(fb); |
| 314 | return NULL; |
| 315 | } |
| 316 | |
| 317 | static void |
| 318 | drm_fb_destroy_dumb(struct drm_fb *fb) |
| 319 | { |
| 320 | struct drm_mode_destroy_dumb destroy_arg; |
| 321 | |
| 322 | if (!fb->map) |
| 323 | return; |
| 324 | |
| 325 | if (fb->fb_id) |
| 326 | drmModeRmFB(fb->fd, fb->fb_id); |
| 327 | |
| 328 | weston_buffer_reference(&fb->buffer_ref, NULL); |
| 329 | |
| 330 | munmap(fb->map, fb->size); |
| 331 | |
| 332 | memset(&destroy_arg, 0, sizeof(destroy_arg)); |
| 333 | destroy_arg.handle = fb->handle; |
| 334 | drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg); |
| 335 | |
| 336 | free(fb); |
| 337 | } |
| 338 | |
| 339 | static struct drm_fb * |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 340 | drm_fb_get_from_bo(struct gbm_bo *bo, |
| 341 | struct drm_compositor *compositor, uint32_t format) |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 342 | { |
| 343 | struct drm_fb *fb = gbm_bo_get_user_data(bo); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 344 | uint32_t width, height; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 345 | uint32_t handles[4], pitches[4], offsets[4]; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 346 | int ret; |
| 347 | |
| 348 | if (fb) |
| 349 | return fb; |
| 350 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 351 | fb = zalloc(sizeof *fb); |
| 352 | if (fb == NULL) |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 353 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 354 | |
| 355 | fb->bo = bo; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 356 | |
| 357 | width = gbm_bo_get_width(bo); |
| 358 | height = gbm_bo_get_height(bo); |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 359 | fb->stride = gbm_bo_get_stride(bo); |
| 360 | fb->handle = gbm_bo_get_handle(bo).u32; |
| 361 | fb->size = fb->stride * height; |
| 362 | fb->fd = compositor->drm.fd; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 363 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 364 | if (compositor->min_width > width || width > compositor->max_width || |
| 365 | compositor->min_height > height || |
| 366 | height > compositor->max_height) { |
| 367 | weston_log("bo geometry out of bounds\n"); |
| 368 | goto err_free; |
| 369 | } |
| 370 | |
| 371 | ret = -1; |
| 372 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 373 | if (format && !compositor->no_addfb2) { |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 374 | handles[0] = fb->handle; |
| 375 | pitches[0] = fb->stride; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 376 | offsets[0] = 0; |
| 377 | |
| 378 | ret = drmModeAddFB2(compositor->drm.fd, width, height, |
| 379 | format, handles, pitches, offsets, |
| 380 | &fb->fb_id, 0); |
| 381 | if (ret) { |
| 382 | weston_log("addfb2 failed: %m\n"); |
| 383 | compositor->no_addfb2 = 1; |
| 384 | compositor->sprites_are_broken = 1; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (ret) |
| 389 | ret = drmModeAddFB(compositor->drm.fd, width, height, 24, 32, |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 390 | fb->stride, fb->handle, &fb->fb_id); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 391 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 392 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 393 | weston_log("failed to create kms fb: %m\n"); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 394 | goto err_free; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback); |
| 398 | |
| 399 | return fb; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 400 | |
| 401 | err_free: |
| 402 | free(fb); |
| 403 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 407 | drm_fb_set_buffer(struct drm_fb *fb, struct weston_buffer *buffer) |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 408 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 409 | assert(fb->buffer_ref.buffer == NULL); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 410 | |
| 411 | fb->is_client_buffer = 1; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 412 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 413 | weston_buffer_reference(&fb->buffer_ref, buffer); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 416 | static void |
| 417 | drm_output_release_fb(struct drm_output *output, struct drm_fb *fb) |
| 418 | { |
| 419 | if (!fb) |
| 420 | return; |
| 421 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 422 | if (fb->map && |
| 423 | (fb != output->dumb[0] && fb != output->dumb[1])) { |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 424 | drm_fb_destroy_dumb(fb); |
| 425 | } else if (fb->bo) { |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 426 | if (fb->is_client_buffer) |
| 427 | gbm_bo_destroy(fb->bo); |
| 428 | else |
| 429 | gbm_surface_release_buffer(output->surface, |
Jason Ekstrand | 3ec57f5 | 2013-11-14 20:52:35 -0600 | [diff] [blame] | 430 | fb->bo); |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 434 | static uint32_t |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 435 | drm_output_check_scanout_format(struct drm_output *output, |
| 436 | struct weston_surface *es, struct gbm_bo *bo) |
| 437 | { |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 438 | uint32_t format; |
| 439 | pixman_region32_t r; |
| 440 | |
| 441 | format = gbm_bo_get_format(bo); |
| 442 | |
Kristian Høgsberg | 3f97b34 | 2013-10-16 16:08:57 -0700 | [diff] [blame] | 443 | if (format == GBM_FORMAT_ARGB8888) { |
| 444 | /* We can scanout an ARGB buffer if the surface's |
| 445 | * opaque region covers the whole output, but we have |
| 446 | * to use XRGB as the KMS format code. */ |
Kristian Høgsberg | 1be87e3 | 2014-01-17 14:22:41 -0800 | [diff] [blame] | 447 | pixman_region32_init_rect(&r, 0, 0, |
| 448 | output->base.width, |
| 449 | output->base.height); |
| 450 | pixman_region32_subtract(&r, &r, &es->opaque); |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 451 | |
| 452 | if (!pixman_region32_not_empty(&r)) |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 453 | format = GBM_FORMAT_XRGB8888; |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 454 | |
| 455 | pixman_region32_fini(&r); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 456 | } |
Kristian Høgsberg | 3f97b34 | 2013-10-16 16:08:57 -0700 | [diff] [blame] | 457 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 458 | if (output->format == format) |
Kristian Høgsberg | 3f97b34 | 2013-10-16 16:08:57 -0700 | [diff] [blame] | 459 | return format; |
| 460 | |
| 461 | return 0; |
Ander Conselvan de Oliveira | e920941 | 2012-11-30 17:34:22 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 464 | static struct weston_plane * |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 465 | drm_output_prepare_scanout_view(struct drm_output *output, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 466 | struct weston_view *ev) |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 467 | { |
| 468 | struct drm_compositor *c = |
| 469 | (struct drm_compositor *) output->base.compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 470 | struct weston_buffer *buffer = ev->surface->buffer_ref.buffer; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 471 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 472 | struct gbm_bo *bo; |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 473 | uint32_t format; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 475 | if (ev->geometry.x != output->base.x || |
| 476 | ev->geometry.y != output->base.y || |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 477 | buffer == NULL || c->gbm == NULL || |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 478 | buffer->width != output->base.current_mode->width || |
| 479 | buffer->height != output->base.current_mode->height || |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 480 | output->base.transform != viewport->buffer.transform || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 481 | ev->transform.enabled) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 482 | return NULL; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 483 | |
Pekka Paalanen | 5580f22 | 2015-02-17 16:33:18 +0200 | [diff] [blame] | 484 | if (ev->geometry.scissor_enabled) |
| 485 | return NULL; |
| 486 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 487 | bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER, |
Kristian Høgsberg | 6399646 | 2013-09-03 22:27:08 -0700 | [diff] [blame] | 488 | buffer->resource, GBM_BO_USE_SCANOUT); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 489 | |
Rob Bradford | 9b10187 | 2012-09-14 23:25:41 +0100 | [diff] [blame] | 490 | /* Unable to use the buffer for scanout */ |
| 491 | if (!bo) |
| 492 | return NULL; |
| 493 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 494 | format = drm_output_check_scanout_format(output, ev->surface, bo); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 495 | if (format == 0) { |
Ander Conselvan de Oliveira | a64b15d | 2012-05-02 16:42:22 +0300 | [diff] [blame] | 496 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 497 | return NULL; |
Ander Conselvan de Oliveira | a64b15d | 2012-05-02 16:42:22 +0300 | [diff] [blame] | 498 | } |
| 499 | |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 500 | output->next = drm_fb_get_from_bo(bo, c, format); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 501 | if (!output->next) { |
| 502 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 503 | return NULL; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 504 | } |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 505 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 506 | drm_fb_set_buffer(output->next, buffer); |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 507 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 508 | return &output->fb_plane; |
Kristian Høgsberg | 5f5e42e | 2012-01-25 23:59:42 -0500 | [diff] [blame] | 509 | } |
| 510 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 511 | static void |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 512 | drm_output_render_gl(struct drm_output *output, pixman_region32_t *damage) |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 513 | { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 514 | struct drm_compositor *c = |
| 515 | (struct drm_compositor *) output->base.compositor; |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 516 | struct gbm_bo *bo; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 517 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 518 | c->base.renderer->repaint_output(&output->base, damage); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 519 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 520 | bo = gbm_surface_lock_front_buffer(output->surface); |
| 521 | if (!bo) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 522 | weston_log("failed to lock front buffer: %m\n"); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 523 | return; |
| 524 | } |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 525 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 526 | output->next = drm_fb_get_from_bo(bo, c, output->format); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 527 | if (!output->next) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 528 | weston_log("failed to get drm_fb for bo\n"); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 529 | gbm_surface_release_buffer(output->surface, bo); |
| 530 | return; |
| 531 | } |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 535 | drm_output_render_pixman(struct drm_output *output, pixman_region32_t *damage) |
| 536 | { |
| 537 | struct weston_compositor *ec = output->base.compositor; |
| 538 | pixman_region32_t total_damage, previous_damage; |
| 539 | |
| 540 | pixman_region32_init(&total_damage); |
| 541 | pixman_region32_init(&previous_damage); |
| 542 | |
| 543 | pixman_region32_copy(&previous_damage, damage); |
| 544 | |
| 545 | pixman_region32_union(&total_damage, damage, &output->previous_damage); |
| 546 | pixman_region32_copy(&output->previous_damage, &previous_damage); |
| 547 | |
| 548 | output->current_image ^= 1; |
| 549 | |
| 550 | output->next = output->dumb[output->current_image]; |
| 551 | pixman_renderer_output_set_buffer(&output->base, |
| 552 | output->image[output->current_image]); |
| 553 | |
| 554 | ec->renderer->repaint_output(&output->base, &total_damage); |
| 555 | |
| 556 | pixman_region32_fini(&total_damage); |
| 557 | pixman_region32_fini(&previous_damage); |
| 558 | } |
| 559 | |
| 560 | static void |
| 561 | drm_output_render(struct drm_output *output, pixman_region32_t *damage) |
| 562 | { |
| 563 | struct drm_compositor *c = |
| 564 | (struct drm_compositor *) output->base.compositor; |
| 565 | |
| 566 | if (c->use_pixman) |
| 567 | drm_output_render_pixman(output, damage); |
| 568 | else |
| 569 | drm_output_render_gl(output, damage); |
| 570 | |
| 571 | pixman_region32_subtract(&c->base.primary_plane.damage, |
| 572 | &c->base.primary_plane.damage, damage); |
| 573 | } |
| 574 | |
| 575 | static void |
Richard Hughes | e729996 | 2013-05-01 21:52:12 +0100 | [diff] [blame] | 576 | drm_output_set_gamma(struct weston_output *output_base, |
| 577 | uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) |
| 578 | { |
| 579 | int rc; |
| 580 | struct drm_output *output = (struct drm_output *) output_base; |
| 581 | struct drm_compositor *compositor = (struct drm_compositor *) output->base.compositor; |
| 582 | |
| 583 | /* check */ |
| 584 | if (output_base->gamma_size != size) |
| 585 | return; |
| 586 | if (!output->original_crtc) |
| 587 | return; |
| 588 | |
| 589 | rc = drmModeCrtcSetGamma(compositor->drm.fd, |
| 590 | output->crtc_id, |
| 591 | size, r, g, b); |
| 592 | if (rc) |
| 593 | weston_log("set gamma failed: %m\n"); |
| 594 | } |
| 595 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 596 | static int |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 597 | drm_output_repaint(struct weston_output *output_base, |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 598 | pixman_region32_t *damage) |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 599 | { |
| 600 | struct drm_output *output = (struct drm_output *) output_base; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 601 | struct drm_compositor *compositor = |
| 602 | (struct drm_compositor *) output->base.compositor; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 603 | struct drm_sprite *s; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 604 | struct drm_mode *mode; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 605 | int ret = 0; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 606 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 607 | if (output->destroy_pending) |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 608 | return -1; |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 609 | |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 610 | if (!output->next) |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 611 | drm_output_render(output, damage); |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 612 | if (!output->next) |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 613 | return -1; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 614 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 615 | mode = container_of(output->base.current_mode, struct drm_mode, base); |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 616 | if (!output->current || |
| 617 | output->current->stride != output->next->stride) { |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 618 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 619 | output->next->fb_id, 0, 0, |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 620 | &output->connector_id, 1, |
| 621 | &mode->mode_info); |
| 622 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 623 | weston_log("set mode failed: %m\n"); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 624 | goto err_pageflip; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 625 | } |
Ander Conselvan de Oliveira | 722a2d5 | 2013-06-04 16:24:05 +0300 | [diff] [blame] | 626 | output_base->set_dpms(output_base, WESTON_DPMS_ON); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 627 | } |
| 628 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 629 | if (drmModePageFlip(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 630 | output->next->fb_id, |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 631 | DRM_MODE_PAGE_FLIP_EVENT, output) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 632 | weston_log("queueing pageflip failed: %m\n"); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 633 | goto err_pageflip; |
Kristian Høgsberg | 54f14c3 | 2012-01-18 11:47:41 -0500 | [diff] [blame] | 634 | } |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 635 | |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 636 | output->page_flip_pending = 1; |
| 637 | |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 638 | drm_output_set_cursor(output); |
| 639 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 640 | /* |
| 641 | * Now, update all the sprite surfaces |
| 642 | */ |
| 643 | wl_list_for_each(s, &compositor->sprite_list, link) { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 644 | uint32_t flags = 0, fb_id = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 645 | drmVBlank vbl = { |
| 646 | .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT, |
| 647 | .request.sequence = 1, |
| 648 | }; |
| 649 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 650 | if ((!s->current && !s->next) || |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 651 | !drm_sprite_crtc_supported(output, s->possible_crtcs)) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 652 | continue; |
| 653 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 654 | if (s->next && !compositor->sprites_hidden) |
| 655 | fb_id = s->next->fb_id; |
| 656 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 657 | ret = drmModeSetPlane(compositor->drm.fd, s->plane_id, |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 658 | output->crtc_id, fb_id, flags, |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 659 | s->dest_x, s->dest_y, |
| 660 | s->dest_w, s->dest_h, |
| 661 | s->src_x, s->src_y, |
| 662 | s->src_w, s->src_h); |
| 663 | if (ret) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 664 | weston_log("setplane failed: %d: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 665 | ret, strerror(errno)); |
| 666 | |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 667 | if (output->pipe > 0) |
| 668 | vbl.request.type |= DRM_VBLANK_SECONDARY; |
| 669 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 670 | /* |
| 671 | * Queue a vblank signal so we know when the surface |
| 672 | * becomes active on the display or has been replaced. |
| 673 | */ |
| 674 | vbl.request.signal = (unsigned long)s; |
| 675 | ret = drmWaitVBlank(compositor->drm.fd, &vbl); |
| 676 | if (ret) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 677 | weston_log("vblank event request failed: %d: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 678 | ret, strerror(errno)); |
| 679 | } |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 680 | |
| 681 | s->output = output; |
| 682 | output->vblank_pending = 1; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 683 | } |
| 684 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 685 | return 0; |
| 686 | |
| 687 | err_pageflip: |
Kristian Høgsberg | b3955b0 | 2014-01-23 16:25:06 -0800 | [diff] [blame] | 688 | output->cursor_view = NULL; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 689 | if (output->next) { |
| 690 | drm_output_release_fb(output, output->next); |
| 691 | output->next = NULL; |
| 692 | } |
| 693 | |
| 694 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 698 | drm_output_start_repaint_loop(struct weston_output *output_base) |
| 699 | { |
| 700 | struct drm_output *output = (struct drm_output *) output_base; |
| 701 | struct drm_compositor *compositor = (struct drm_compositor *) |
| 702 | output_base->compositor; |
| 703 | uint32_t fb_id; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 704 | struct timespec ts; |
| 705 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 706 | if (output->destroy_pending) |
| 707 | return; |
| 708 | |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 709 | if (!output->current) { |
| 710 | /* We can't page flip if there's no mode set */ |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 711 | goto finish_frame; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | fb_id = output->current->fb_id; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 715 | |
| 716 | if (drmModePageFlip(compositor->drm.fd, output->crtc_id, fb_id, |
| 717 | DRM_MODE_PAGE_FLIP_EVENT, output) < 0) { |
| 718 | weston_log("queueing pageflip failed: %m\n"); |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 719 | goto finish_frame; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 720 | } |
David Herrmann | 3c688c5 | 2013-10-22 17:11:25 +0200 | [diff] [blame] | 721 | |
| 722 | return; |
| 723 | |
| 724 | finish_frame: |
| 725 | /* if we cannot page-flip, immediately finish frame */ |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 726 | weston_compositor_read_presentation_clock(&compositor->base, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 727 | weston_output_finish_frame(output_base, &ts, |
| 728 | PRESENTATION_FEEDBACK_INVALID); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | static void |
Pekka Paalanen | 641307c | 2014-09-23 22:08:47 -0400 | [diff] [blame] | 732 | drm_output_update_msc(struct drm_output *output, unsigned int seq) |
| 733 | { |
| 734 | uint64_t msc_hi = output->base.msc >> 32; |
| 735 | |
| 736 | if (seq < (output->base.msc & 0xffffffff)) |
| 737 | msc_hi++; |
| 738 | |
| 739 | output->base.msc = (msc_hi << 32) + seq; |
| 740 | } |
| 741 | |
| 742 | static void |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 743 | vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, |
| 744 | void *data) |
| 745 | { |
| 746 | struct drm_sprite *s = (struct drm_sprite *)data; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 747 | struct drm_output *output = s->output; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 748 | struct timespec ts; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 749 | uint32_t flags = PRESENTATION_FEEDBACK_KIND_HW_COMPLETION | |
| 750 | PRESENTATION_FEEDBACK_KIND_HW_CLOCK; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 751 | |
Pekka Paalanen | 641307c | 2014-09-23 22:08:47 -0400 | [diff] [blame] | 752 | drm_output_update_msc(output, frame); |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 753 | output->vblank_pending = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 754 | |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 755 | drm_output_release_fb(output, s->current); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 756 | s->current = s->next; |
| 757 | s->next = NULL; |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 758 | |
| 759 | if (!output->page_flip_pending) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 760 | ts.tv_sec = sec; |
| 761 | ts.tv_nsec = usec * 1000; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 762 | weston_output_finish_frame(&output->base, &ts, flags); |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 763 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 767 | drm_output_destroy(struct weston_output *output_base); |
| 768 | |
| 769 | static void |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 770 | page_flip_handler(int fd, unsigned int frame, |
| 771 | unsigned int sec, unsigned int usec, void *data) |
| 772 | { |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 773 | struct drm_output *output = (struct drm_output *) data; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 774 | struct timespec ts; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 775 | uint32_t flags = PRESENTATION_FEEDBACK_KIND_VSYNC | |
| 776 | PRESENTATION_FEEDBACK_KIND_HW_COMPLETION | |
| 777 | PRESENTATION_FEEDBACK_KIND_HW_CLOCK; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 778 | |
Pekka Paalanen | 641307c | 2014-09-23 22:08:47 -0400 | [diff] [blame] | 779 | drm_output_update_msc(output, frame); |
| 780 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 781 | /* We don't set page_flip_pending on start_repaint_loop, in that case |
| 782 | * we just want to page flip to the current buffer to get an accurate |
| 783 | * timestamp */ |
| 784 | if (output->page_flip_pending) { |
| 785 | drm_output_release_fb(output, output->current); |
| 786 | output->current = output->next; |
| 787 | output->next = NULL; |
| 788 | } |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 789 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 790 | output->page_flip_pending = 0; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 791 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 792 | if (output->destroy_pending) |
| 793 | drm_output_destroy(&output->base); |
| 794 | else if (!output->vblank_pending) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 795 | ts.tv_sec = sec; |
| 796 | ts.tv_nsec = usec * 1000; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 797 | weston_output_finish_frame(&output->base, &ts, flags); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 798 | |
| 799 | /* We can't call this from frame_notify, because the output's |
| 800 | * repaint needed flag is cleared just after that */ |
| 801 | if (output->recorder) |
| 802 | weston_output_schedule_repaint(&output->base); |
Ander Conselvan de Oliveira | a732696 | 2012-06-26 17:09:13 +0300 | [diff] [blame] | 803 | } |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 804 | } |
| 805 | |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 806 | static uint32_t |
| 807 | drm_output_check_sprite_format(struct drm_sprite *s, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 808 | struct weston_view *ev, struct gbm_bo *bo) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 809 | { |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 810 | uint32_t i, format; |
| 811 | |
| 812 | format = gbm_bo_get_format(bo); |
| 813 | |
| 814 | if (format == GBM_FORMAT_ARGB8888) { |
| 815 | pixman_region32_t r; |
| 816 | |
Kristian Høgsberg | 63093a3 | 2013-03-01 14:29:16 -0500 | [diff] [blame] | 817 | pixman_region32_init_rect(&r, 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 818 | ev->surface->width, |
| 819 | ev->surface->height); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 820 | pixman_region32_subtract(&r, &r, &ev->surface->opaque); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 821 | |
| 822 | if (!pixman_region32_not_empty(&r)) |
| 823 | format = GBM_FORMAT_XRGB8888; |
| 824 | |
| 825 | pixman_region32_fini(&r); |
| 826 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 827 | |
| 828 | for (i = 0; i < s->count_formats; i++) |
| 829 | if (s->formats[i] == format) |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 830 | return format; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 836 | drm_view_transform_supported(struct weston_view *ev) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 837 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 838 | return !ev->transform.enabled || |
| 839 | (ev->transform.matrix.type < WESTON_MATRIX_TRANSFORM_ROTATE); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 840 | } |
| 841 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 842 | static struct weston_plane * |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 843 | drm_output_prepare_overlay_view(struct drm_output *output, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 844 | struct weston_view *ev) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 845 | { |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 846 | struct weston_compositor *ec = output->base.compositor; |
| 847 | struct drm_compositor *c = (struct drm_compositor *)ec; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 848 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 849 | struct drm_sprite *s; |
| 850 | int found = 0; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 851 | struct gbm_bo *bo; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 852 | pixman_region32_t dest_rect, src_rect; |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 853 | pixman_box32_t *box, tbox; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 854 | uint32_t format; |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 855 | wl_fixed_t sx1, sy1, sx2, sy2; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 856 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 857 | if (c->gbm == NULL) |
| 858 | return NULL; |
| 859 | |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 860 | if (viewport->buffer.transform != output->base.transform) |
Ander Conselvan de Oliveira | 2908a3d | 2012-11-27 17:03:43 +0200 | [diff] [blame] | 861 | return NULL; |
| 862 | |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 863 | if (viewport->buffer.scale != output->base.current_scale) |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 864 | return NULL; |
| 865 | |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 866 | if (c->sprites_are_broken) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 867 | return NULL; |
Kristian Høgsberg | 65bec24 | 2012-03-05 19:57:35 -0500 | [diff] [blame] | 868 | |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 869 | if (ev->output_mask != (1u << output->base.id)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 870 | return NULL; |
Ander Conselvan de Oliveira | d450b19 | 2012-06-26 17:09:12 +0300 | [diff] [blame] | 871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 872 | if (ev->surface->buffer_ref.buffer == NULL) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 873 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 874 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 875 | if (ev->alpha != 1.0f) |
Ville Syrjälä | 5a84f31 | 2012-11-16 11:48:46 +0200 | [diff] [blame] | 876 | return NULL; |
| 877 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 878 | if (wl_shm_buffer_get(ev->surface->buffer_ref.buffer->resource)) |
Rob Clark | 702ffae | 2012-08-09 14:18:27 -0500 | [diff] [blame] | 879 | return NULL; |
| 880 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 881 | if (!drm_view_transform_supported(ev)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 882 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 883 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 884 | wl_list_for_each(s, &c->sprite_list, link) { |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 885 | if (!drm_sprite_crtc_supported(output, s->possible_crtcs)) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 886 | continue; |
| 887 | |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 888 | if (!s->next) { |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 889 | found = 1; |
| 890 | break; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | /* No sprites available */ |
| 895 | if (!found) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 896 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 897 | |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 898 | bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 899 | ev->surface->buffer_ref.buffer->resource, |
Kristian Høgsberg | 6399646 | 2013-09-03 22:27:08 -0700 | [diff] [blame] | 900 | GBM_BO_USE_SCANOUT); |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 901 | if (!bo) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 902 | return NULL; |
Kristian Høgsberg | 2763a2e | 2012-07-13 22:54:43 -0400 | [diff] [blame] | 903 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 904 | format = drm_output_check_sprite_format(s, ev, bo); |
Kristian Høgsberg | a2f84cc | 2012-12-07 12:37:58 -0500 | [diff] [blame] | 905 | if (format == 0) { |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 906 | gbm_bo_destroy(bo); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 907 | return NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 908 | } |
| 909 | |
Ander Conselvan de Oliveira | ca5c6ae | 2012-12-07 13:18:11 +0200 | [diff] [blame] | 910 | s->next = drm_fb_get_from_bo(bo, c, format); |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 911 | if (!s->next) { |
| 912 | gbm_bo_destroy(bo); |
| 913 | return NULL; |
| 914 | } |
| 915 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 916 | drm_fb_set_buffer(s->next, ev->surface->buffer_ref.buffer); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 917 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 918 | box = pixman_region32_extents(&ev->transform.boundingbox); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 919 | s->plane.x = box->x1; |
| 920 | s->plane.y = box->y1; |
| 921 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 922 | /* |
| 923 | * Calculate the source & dest rects properly based on actual |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 924 | * position (note the caller has called weston_view_update_transform() |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 925 | * for us already). |
| 926 | */ |
| 927 | pixman_region32_init(&dest_rect); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 928 | pixman_region32_intersect(&dest_rect, &ev->transform.boundingbox, |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 929 | &output->base.region); |
| 930 | pixman_region32_translate(&dest_rect, -output->base.x, -output->base.y); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 931 | box = pixman_region32_extents(&dest_rect); |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 932 | tbox = weston_transformed_rect(output->base.width, |
| 933 | output->base.height, |
| 934 | output->base.transform, |
| 935 | output->base.current_scale, |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 936 | *box); |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 937 | s->dest_x = tbox.x1; |
| 938 | s->dest_y = tbox.y1; |
| 939 | s->dest_w = tbox.x2 - tbox.x1; |
| 940 | s->dest_h = tbox.y2 - tbox.y1; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 941 | pixman_region32_fini(&dest_rect); |
| 942 | |
| 943 | pixman_region32_init(&src_rect); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 944 | pixman_region32_intersect(&src_rect, &ev->transform.boundingbox, |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 945 | &output->base.region); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 946 | box = pixman_region32_extents(&src_rect); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 947 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 948 | weston_view_from_global_fixed(ev, |
| 949 | wl_fixed_from_int(box->x1), |
| 950 | wl_fixed_from_int(box->y1), |
| 951 | &sx1, &sy1); |
| 952 | weston_view_from_global_fixed(ev, |
| 953 | wl_fixed_from_int(box->x2), |
| 954 | wl_fixed_from_int(box->y2), |
| 955 | &sx2, &sy2); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 956 | |
| 957 | if (sx1 < 0) |
| 958 | sx1 = 0; |
| 959 | if (sy1 < 0) |
| 960 | sy1 = 0; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 961 | if (sx2 > wl_fixed_from_int(ev->surface->width)) |
| 962 | sx2 = wl_fixed_from_int(ev->surface->width); |
| 963 | if (sy2 > wl_fixed_from_int(ev->surface->height)) |
| 964 | sy2 = wl_fixed_from_int(ev->surface->height); |
Kristian Høgsberg | 3b00bae | 2012-07-13 15:25:07 -0400 | [diff] [blame] | 965 | |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 966 | tbox.x1 = sx1; |
| 967 | tbox.y1 = sy1; |
| 968 | tbox.x2 = sx2; |
| 969 | tbox.y2 = sy2; |
| 970 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 971 | tbox = weston_transformed_rect(wl_fixed_from_int(ev->surface->width), |
| 972 | wl_fixed_from_int(ev->surface->height), |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 973 | viewport->buffer.transform, |
| 974 | viewport->buffer.scale, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 975 | tbox); |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 976 | |
| 977 | s->src_x = tbox.x1 << 8; |
| 978 | s->src_y = tbox.y1 << 8; |
| 979 | s->src_w = (tbox.x2 - tbox.x1) << 8; |
| 980 | s->src_h = (tbox.y2 - tbox.y1) << 8; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 981 | pixman_region32_fini(&src_rect); |
| 982 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 983 | return &s->plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 984 | } |
| 985 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 986 | static struct weston_plane * |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 987 | drm_output_prepare_cursor_view(struct drm_output *output, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 988 | struct weston_view *ev) |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 989 | { |
Kristian Høgsberg | 8a01580 | 2012-08-09 17:19:23 -0400 | [diff] [blame] | 990 | struct drm_compositor *c = |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 991 | (struct drm_compositor *)output->base.compositor; |
Neil Roberts | f37f82c | 2014-05-01 18:00:41 +0100 | [diff] [blame] | 992 | struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 993 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 994 | if (c->gbm == NULL) |
| 995 | return NULL; |
Ander Conselvan de Oliveira | 2908a3d | 2012-11-27 17:03:43 +0200 | [diff] [blame] | 996 | if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL) |
| 997 | return NULL; |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 998 | if (viewport->buffer.scale != output->base.current_scale) |
Neil Roberts | f37f82c | 2014-05-01 18:00:41 +0100 | [diff] [blame] | 999 | return NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1000 | if (output->cursor_view) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1001 | return NULL; |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 1002 | if (ev->output_mask != (1u << output->base.id)) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1003 | return NULL; |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1004 | if (c->cursors_are_broken) |
Kristian Høgsberg | 8a01580 | 2012-08-09 17:19:23 -0400 | [diff] [blame] | 1005 | return NULL; |
Pekka Paalanen | 5580f22 | 2015-02-17 16:33:18 +0200 | [diff] [blame] | 1006 | if (ev->geometry.scissor_enabled) |
| 1007 | return NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1008 | if (ev->surface->buffer_ref.buffer == NULL || |
| 1009 | !wl_shm_buffer_get(ev->surface->buffer_ref.buffer->resource) || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1010 | ev->surface->width > 64 || ev->surface->height > 64) |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1011 | return NULL; |
| 1012 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1013 | output->cursor_view = ev; |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1014 | |
| 1015 | return &output->cursor_plane; |
| 1016 | } |
| 1017 | |
| 1018 | static void |
| 1019 | drm_output_set_cursor(struct drm_output *output) |
| 1020 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1021 | struct weston_view *ev = output->cursor_view; |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1022 | struct weston_buffer *buffer; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1023 | struct drm_compositor *c = |
| 1024 | (struct drm_compositor *) output->base.compositor; |
| 1025 | EGLint handle, stride; |
| 1026 | struct gbm_bo *bo; |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1027 | uint32_t buf[c->cursor_width * c->cursor_height]; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1028 | unsigned char *s; |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 1029 | int i, x, y; |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1030 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1031 | output->cursor_view = NULL; |
| 1032 | if (ev == NULL) { |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1033 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
| 1034 | return; |
| 1035 | } |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1036 | |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1037 | buffer = ev->surface->buffer_ref.buffer; |
| 1038 | |
| 1039 | if (buffer && |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1040 | pixman_region32_not_empty(&output->cursor_plane.damage)) { |
Kristian Høgsberg | 5626d34 | 2012-08-03 11:50:05 -0400 | [diff] [blame] | 1041 | pixman_region32_fini(&output->cursor_plane.damage); |
| 1042 | pixman_region32_init(&output->cursor_plane.damage); |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 1043 | output->current_cursor ^= 1; |
| 1044 | bo = output->cursor_bo[output->current_cursor]; |
| 1045 | memset(buf, 0, sizeof buf); |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1046 | stride = wl_shm_buffer_get_stride(buffer->shm_buffer); |
| 1047 | s = wl_shm_buffer_get_data(buffer->shm_buffer); |
| 1048 | wl_shm_buffer_begin_access(buffer->shm_buffer); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1049 | for (i = 0; i < ev->surface->height; i++) |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1050 | memcpy(buf + i * c->cursor_width, s + i * stride, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1051 | ev->surface->width * 4); |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 1052 | wl_shm_buffer_end_access(buffer->shm_buffer); |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1053 | |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 1054 | if (gbm_bo_write(bo, buf, sizeof buf) < 0) |
Pekka Paalanen | ae29da2 | 2012-08-06 14:57:05 +0300 | [diff] [blame] | 1055 | weston_log("failed update cursor: %m\n"); |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1056 | |
Kristian Høgsberg | 1f5de35 | 2012-07-18 12:09:58 -0400 | [diff] [blame] | 1057 | handle = gbm_bo_get_handle(bo).s32; |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1058 | if (drmModeSetCursor(c->drm.fd, output->crtc_id, handle, |
| 1059 | c->cursor_width, c->cursor_height)) { |
Pekka Paalanen | ae29da2 | 2012-08-06 14:57:05 +0300 | [diff] [blame] | 1060 | weston_log("failed to set cursor: %m\n"); |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1061 | c->cursors_are_broken = 1; |
| 1062 | } |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1063 | } |
| 1064 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1065 | x = (ev->geometry.x - output->base.x) * output->base.current_scale; |
| 1066 | y = (ev->geometry.y - output->base.y) * output->base.current_scale; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1067 | if (output->cursor_plane.x != x || output->cursor_plane.y != y) { |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1068 | if (drmModeMoveCursor(c->drm.fd, output->crtc_id, x, y)) { |
Kristian Høgsberg | 24e4275 | 2012-07-18 12:08:37 -0400 | [diff] [blame] | 1069 | weston_log("failed to move cursor: %m\n"); |
Rob Clark | ab5b1e3 | 2012-08-09 13:24:45 -0500 | [diff] [blame] | 1070 | c->cursors_are_broken = 1; |
| 1071 | } |
| 1072 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1073 | output->cursor_plane.x = x; |
| 1074 | output->cursor_plane.y = y; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1075 | } |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 1076 | } |
| 1077 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1078 | static void |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 1079 | drm_assign_planes(struct weston_output *output_base) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1080 | { |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1081 | struct drm_compositor *c = |
Pekka Paalanen | 050c1ba | 2014-12-17 16:20:38 +0200 | [diff] [blame] | 1082 | (struct drm_compositor *)output_base->compositor; |
| 1083 | struct drm_output *output = (struct drm_output *)output_base; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1084 | struct weston_view *ev, *next; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1085 | pixman_region32_t overlap, surface_overlap; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1086 | struct weston_plane *primary, *next_plane; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1087 | |
| 1088 | /* |
| 1089 | * Find a surface for each sprite in the output using some heuristics: |
| 1090 | * 1) size |
| 1091 | * 2) frequency of update |
| 1092 | * 3) opacity (though some hw might support alpha blending) |
| 1093 | * 4) clipping (this can be fixed with color keys) |
| 1094 | * |
| 1095 | * The idea is to save on blitting since this should save power. |
| 1096 | * If we can get a large video surface on the sprite for example, |
| 1097 | * the main display surface may not need to update at all, and |
| 1098 | * the client buffer can be used directly for the sprite surface |
| 1099 | * as we do for flipping full screen surfaces. |
| 1100 | */ |
| 1101 | pixman_region32_init(&overlap); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1102 | primary = &c->base.primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1103 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1104 | wl_list_for_each_safe(ev, next, &c->base.view_list, link) { |
Ander Conselvan de Oliveira | 895b1fd | 2013-11-19 15:22:05 +0200 | [diff] [blame] | 1105 | struct weston_surface *es = ev->surface; |
| 1106 | |
| 1107 | /* Test whether this buffer can ever go into a plane: |
| 1108 | * non-shm, or small enough to be a cursor. |
| 1109 | * |
| 1110 | * Also, keep a reference when using the pixman renderer. |
| 1111 | * That makes it possible to do a seamless switch to the GL |
| 1112 | * renderer and since the pixman renderer keeps a reference |
| 1113 | * to the buffer anyway, there is no side effects. |
Pekka Paalanen | ccfeae2 | 2012-12-04 15:58:14 +0200 | [diff] [blame] | 1114 | */ |
Ander Conselvan de Oliveira | 895b1fd | 2013-11-19 15:22:05 +0200 | [diff] [blame] | 1115 | if (c->use_pixman || |
| 1116 | (es->buffer_ref.buffer && |
| 1117 | (!wl_shm_buffer_get(es->buffer_ref.buffer->resource) || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1118 | (ev->surface->width <= 64 && ev->surface->height <= 64)))) |
Derek Foreman | 0fd6d4e | 2014-10-10 09:36:45 -0500 | [diff] [blame] | 1119 | es->keep_buffer = true; |
Ander Conselvan de Oliveira | 895b1fd | 2013-11-19 15:22:05 +0200 | [diff] [blame] | 1120 | else |
Derek Foreman | 0fd6d4e | 2014-10-10 09:36:45 -0500 | [diff] [blame] | 1121 | es->keep_buffer = false; |
Pekka Paalanen | ccfeae2 | 2012-12-04 15:58:14 +0200 | [diff] [blame] | 1122 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1123 | pixman_region32_init(&surface_overlap); |
| 1124 | pixman_region32_intersect(&surface_overlap, &overlap, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1125 | &ev->transform.boundingbox); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1126 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1127 | next_plane = NULL; |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 1128 | if (pixman_region32_not_empty(&surface_overlap)) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1129 | next_plane = primary; |
| 1130 | if (next_plane == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1131 | next_plane = drm_output_prepare_cursor_view(output, ev); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1132 | if (next_plane == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1133 | next_plane = drm_output_prepare_scanout_view(output, ev); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1134 | if (next_plane == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1135 | next_plane = drm_output_prepare_overlay_view(output, ev); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1136 | if (next_plane == NULL) |
| 1137 | next_plane = primary; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 1138 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1139 | weston_view_move_to_plane(ev, next_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 1140 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1141 | if (next_plane == primary) |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1142 | pixman_region32_union(&overlap, &overlap, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1143 | &ev->transform.boundingbox); |
Kristian Høgsberg | 6143f7d | 2012-07-14 00:31:32 -0400 | [diff] [blame] | 1144 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 1145 | if (next_plane == primary || |
| 1146 | next_plane == &output->cursor_plane) { |
| 1147 | /* cursor plane involves a copy */ |
| 1148 | ev->psf_flags = 0; |
| 1149 | } else { |
| 1150 | /* All other planes are a direct scanout of a |
| 1151 | * single client buffer. |
| 1152 | */ |
| 1153 | ev->psf_flags = PRESENTATION_FEEDBACK_KIND_ZERO_COPY; |
| 1154 | } |
| 1155 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1156 | pixman_region32_fini(&surface_overlap); |
| 1157 | } |
| 1158 | pixman_region32_fini(&overlap); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1159 | } |
| 1160 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1161 | static void |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1162 | drm_output_fini_pixman(struct drm_output *output); |
| 1163 | |
| 1164 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1165 | drm_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1166 | { |
| 1167 | struct drm_output *output = (struct drm_output *) output_base; |
| 1168 | struct drm_compositor *c = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1169 | (struct drm_compositor *) output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1170 | drmModeCrtcPtr origcrtc = output->original_crtc; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1171 | |
Xiong Zhang | abd5d47 | 2013-10-11 14:43:07 +0800 | [diff] [blame] | 1172 | if (output->page_flip_pending) { |
| 1173 | output->destroy_pending = 1; |
| 1174 | weston_log("destroy output while page flip pending\n"); |
| 1175 | return; |
| 1176 | } |
| 1177 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1178 | if (output->backlight) |
| 1179 | backlight_destroy(output->backlight); |
| 1180 | |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 1181 | drmModeFreeProperty(output->dpms_prop); |
| 1182 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1183 | /* Turn off hardware cursor */ |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 1184 | drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1185 | |
| 1186 | /* Restore original CRTC state */ |
| 1187 | drmModeSetCrtc(c->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id, |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 1188 | origcrtc->x, origcrtc->y, |
| 1189 | &output->connector_id, 1, &origcrtc->mode); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1190 | drmModeFreeCrtc(origcrtc); |
| 1191 | |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 1192 | c->crtc_allocator &= ~(1 << output->crtc_id); |
| 1193 | c->connector_allocator &= ~(1 << output->connector_id); |
| 1194 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1195 | if (c->use_pixman) { |
| 1196 | drm_output_fini_pixman(output); |
| 1197 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1198 | gl_renderer->output_destroy(output_base); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1199 | gbm_surface_destroy(output->surface); |
| 1200 | } |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1201 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1202 | weston_plane_release(&output->fb_plane); |
| 1203 | weston_plane_release(&output->cursor_plane); |
| 1204 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1205 | weston_output_destroy(&output->base); |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 1206 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1207 | free(output); |
| 1208 | } |
| 1209 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1210 | static struct drm_mode * |
| 1211 | choose_mode (struct drm_output *output, struct weston_mode *target_mode) |
| 1212 | { |
| 1213 | struct drm_mode *tmp_mode = NULL, *mode; |
| 1214 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1215 | if (output->base.current_mode->width == target_mode->width && |
| 1216 | output->base.current_mode->height == target_mode->height && |
| 1217 | (output->base.current_mode->refresh == target_mode->refresh || |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1218 | target_mode->refresh == 0)) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1219 | return (struct drm_mode *)output->base.current_mode; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1220 | |
| 1221 | wl_list_for_each(mode, &output->base.mode_list, base.link) { |
| 1222 | if (mode->mode_info.hdisplay == target_mode->width && |
| 1223 | mode->mode_info.vdisplay == target_mode->height) { |
| 1224 | if (mode->mode_info.vrefresh == target_mode->refresh || |
| 1225 | target_mode->refresh == 0) { |
| 1226 | return mode; |
| 1227 | } else if (!tmp_mode) |
| 1228 | tmp_mode = mode; |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | return tmp_mode; |
| 1233 | } |
| 1234 | |
| 1235 | static int |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1236 | drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1237 | static int |
| 1238 | drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c); |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1239 | |
| 1240 | static int |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1241 | drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode) |
| 1242 | { |
| 1243 | struct drm_output *output; |
| 1244 | struct drm_mode *drm_mode; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1245 | struct drm_compositor *ec; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1246 | |
| 1247 | if (output_base == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1248 | weston_log("output is NULL.\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1249 | return -1; |
| 1250 | } |
| 1251 | |
| 1252 | if (mode == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1253 | weston_log("mode is NULL.\n"); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1254 | return -1; |
| 1255 | } |
| 1256 | |
| 1257 | ec = (struct drm_compositor *)output_base->compositor; |
| 1258 | output = (struct drm_output *)output_base; |
| 1259 | drm_mode = choose_mode (output, mode); |
| 1260 | |
| 1261 | if (!drm_mode) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1262 | weston_log("%s, invalid resolution:%dx%d\n", __func__, mode->width, mode->height); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1263 | return -1; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1264 | } |
| 1265 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1266 | if (&drm_mode->base == output->base.current_mode) |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1267 | return 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1268 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1269 | output->base.current_mode->flags = 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1270 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1271 | output->base.current_mode = &drm_mode->base; |
| 1272 | output->base.current_mode->flags = |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1273 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 1274 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1275 | /* reset rendering stuff. */ |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 1276 | drm_output_release_fb(output, output->current); |
| 1277 | drm_output_release_fb(output, output->next); |
| 1278 | output->current = output->next = NULL; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1279 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1280 | if (ec->use_pixman) { |
| 1281 | drm_output_fini_pixman(output); |
| 1282 | if (drm_output_init_pixman(output, ec) < 0) { |
| 1283 | weston_log("failed to init output pixman state with " |
| 1284 | "new mode\n"); |
| 1285 | return -1; |
| 1286 | } |
| 1287 | } else { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1288 | gl_renderer->output_destroy(&output->base); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1289 | gbm_surface_destroy(output->surface); |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1290 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1291 | if (drm_output_init_egl(output, ec) < 0) { |
| 1292 | weston_log("failed to init output egl state with " |
| 1293 | "new mode"); |
| 1294 | return -1; |
| 1295 | } |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1296 | } |
| 1297 | |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1298 | return 0; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 1299 | } |
| 1300 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1301 | static int |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1302 | on_drm_input(int fd, uint32_t mask, void *data) |
| 1303 | { |
| 1304 | drmEventContext evctx; |
| 1305 | |
| 1306 | memset(&evctx, 0, sizeof evctx); |
| 1307 | evctx.version = DRM_EVENT_CONTEXT_VERSION; |
| 1308 | evctx.page_flip_handler = page_flip_handler; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 1309 | evctx.vblank_handler = vblank_handler; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1310 | drmHandleEvent(fd, &evctx); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1311 | |
| 1312 | return 1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static int |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1316 | init_drm(struct drm_compositor *ec, struct udev_device *device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1317 | { |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 1318 | const char *filename, *sysnum; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 1319 | uint64_t cap; |
| 1320 | int fd, ret; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 1321 | clockid_t clk_id; |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1322 | |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1323 | sysnum = udev_device_get_sysnum(device); |
| 1324 | if (sysnum) |
| 1325 | ec->drm.id = atoi(sysnum); |
| 1326 | if (!sysnum || ec->drm.id < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1327 | weston_log("cannot get device sysnum\n"); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1328 | return -1; |
| 1329 | } |
| 1330 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1331 | filename = udev_device_get_devnode(device); |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 1332 | fd = weston_launcher_open(ec->base.launcher, filename, O_RDWR); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1333 | if (fd < 0) { |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1334 | /* Probably permissions error */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1335 | weston_log("couldn't open %s, skipping\n", |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1336 | udev_device_get_devnode(device)); |
| 1337 | return -1; |
| 1338 | } |
| 1339 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1340 | weston_log("using %s\n", filename); |
| 1341 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 1342 | ec->drm.fd = fd; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 1343 | ec->drm.filename = strdup(filename); |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1344 | |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 1345 | ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap); |
| 1346 | if (ret == 0 && cap == 1) |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 1347 | clk_id = CLOCK_MONOTONIC; |
Ander Conselvan de Oliveira | 95eb3a2 | 2013-05-07 14:16:59 +0300 | [diff] [blame] | 1348 | else |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 1349 | clk_id = CLOCK_REALTIME; |
| 1350 | |
| 1351 | if (weston_compositor_set_presentation_clock(&ec->base, clk_id) < 0) { |
| 1352 | weston_log("Error: failed to set presentation clock %d.\n", |
| 1353 | clk_id); |
| 1354 | return -1; |
| 1355 | } |
Ander Conselvan de Oliveira | 1d41ad4 | 2013-01-25 15:13:04 +0200 | [diff] [blame] | 1356 | |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1357 | ret = drmGetCap(fd, DRM_CAP_CURSOR_WIDTH, &cap); |
| 1358 | if (ret == 0) |
| 1359 | ec->cursor_width = cap; |
| 1360 | else |
| 1361 | ec->cursor_width = 64; |
| 1362 | |
| 1363 | ret = drmGetCap(fd, DRM_CAP_CURSOR_HEIGHT, &cap); |
| 1364 | if (ret == 0) |
| 1365 | ec->cursor_height = cap; |
| 1366 | else |
| 1367 | ec->cursor_height = 64; |
| 1368 | |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1369 | return 0; |
| 1370 | } |
| 1371 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1372 | static struct gbm_device * |
| 1373 | create_gbm_device(int fd) |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 1374 | { |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1375 | struct gbm_device *gbm; |
Alexandru DAMIAN | be0ac5b | 2013-10-02 17:51:05 +0100 | [diff] [blame] | 1376 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1377 | gl_renderer = weston_load_module("gl-renderer.so", |
| 1378 | "gl_renderer_interface"); |
| 1379 | if (!gl_renderer) |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1380 | return NULL; |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1381 | |
| 1382 | /* GBM will load a dri driver, but even though they need symbols from |
| 1383 | * libglapi, in some version of Mesa they are not linked to it. Since |
| 1384 | * only the gl-renderer module links to it, the call above won't make |
| 1385 | * these symbols globally available, and loading the DRI driver fails. |
| 1386 | * Workaround this by dlopen()'ing libglapi with RTLD_GLOBAL. */ |
| 1387 | dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL); |
| 1388 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1389 | gbm = gbm_create_device(fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1390 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1391 | return gbm; |
| 1392 | } |
| 1393 | |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1394 | /* When initializing EGL, if the preferred buffer format isn't availble |
| 1395 | * we may be able to susbstitute an ARGB format for an XRGB one. |
| 1396 | * |
| 1397 | * This returns 0 if substitution isn't possible, but 0 might be a |
| 1398 | * legitimate format for other EGL platforms, so the caller is |
| 1399 | * responsible for checking for 0 before calling gl_renderer->create(). |
| 1400 | * |
| 1401 | * This works around https://bugs.freedesktop.org/show_bug.cgi?id=89689 |
| 1402 | * but it's entirely possible we'll see this again on other implementations. |
| 1403 | */ |
| 1404 | static int |
| 1405 | fallback_format_for(uint32_t format) |
| 1406 | { |
| 1407 | switch (format) { |
| 1408 | case GBM_FORMAT_XRGB8888: |
| 1409 | return GBM_FORMAT_ARGB8888; |
| 1410 | case GBM_FORMAT_XRGB2101010: |
| 1411 | return GBM_FORMAT_ARGB2101010; |
| 1412 | default: |
| 1413 | return 0; |
| 1414 | } |
| 1415 | } |
| 1416 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1417 | static int |
| 1418 | drm_compositor_create_gl_renderer(struct drm_compositor *ec) |
| 1419 | { |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1420 | EGLint format[2] = { |
| 1421 | ec->format, |
| 1422 | fallback_format_for(ec->format), |
| 1423 | }; |
| 1424 | int n_formats = 1; |
John Kåre Alsaker | ef591aa | 2013-03-02 12:27:39 +0100 | [diff] [blame] | 1425 | |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1426 | if (format[1]) |
| 1427 | n_formats = 2; |
| 1428 | if (gl_renderer->create(&ec->base, |
| 1429 | EGL_PLATFORM_GBM_KHR, |
| 1430 | (void *)ec->gbm, |
| 1431 | gl_renderer->opaque_attribs, |
| 1432 | format, |
| 1433 | n_formats) < 0) { |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 1434 | return -1; |
| 1435 | } |
| 1436 | |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
| 1440 | static int |
| 1441 | init_egl(struct drm_compositor *ec) |
| 1442 | { |
| 1443 | ec->gbm = create_gbm_device(ec->drm.fd); |
| 1444 | |
| 1445 | if (!ec->gbm) |
| 1446 | return -1; |
| 1447 | |
| 1448 | if (drm_compositor_create_gl_renderer(ec) < 0) { |
John Kåre Alsaker | 1b7ad16 | 2012-11-13 19:10:19 +0100 | [diff] [blame] | 1449 | gbm_device_destroy(ec->gbm); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 1450 | return -1; |
| 1451 | } |
| 1452 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1453 | return 0; |
| 1454 | } |
| 1455 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1456 | static int |
| 1457 | init_pixman(struct drm_compositor *ec) |
| 1458 | { |
| 1459 | return pixman_renderer_init(&ec->base); |
| 1460 | } |
| 1461 | |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1462 | static struct drm_mode * |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1463 | drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info) |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1464 | { |
| 1465 | struct drm_mode *mode; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 1466 | uint64_t refresh; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1467 | |
| 1468 | mode = malloc(sizeof *mode); |
| 1469 | if (mode == NULL) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1470 | return NULL; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1471 | |
| 1472 | mode->base.flags = 0; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1473 | mode->base.width = info->hdisplay; |
| 1474 | mode->base.height = info->vdisplay; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 1475 | |
| 1476 | /* Calculate higher precision (mHz) refresh rate */ |
| 1477 | refresh = (info->clock * 1000000LL / info->htotal + |
| 1478 | info->vtotal / 2) / info->vtotal; |
| 1479 | |
| 1480 | if (info->flags & DRM_MODE_FLAG_INTERLACE) |
| 1481 | refresh *= 2; |
| 1482 | if (info->flags & DRM_MODE_FLAG_DBLSCAN) |
| 1483 | refresh /= 2; |
| 1484 | if (info->vscan > 1) |
| 1485 | refresh /= info->vscan; |
| 1486 | |
| 1487 | mode->base.refresh = refresh; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1488 | mode->mode_info = *info; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1489 | |
| 1490 | if (info->type & DRM_MODE_TYPE_PREFERRED) |
| 1491 | mode->base.flags |= WL_OUTPUT_MODE_PREFERRED; |
| 1492 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1493 | wl_list_insert(output->base.mode_list.prev, &mode->base.link); |
| 1494 | |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1495 | return mode; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | static int |
| 1499 | drm_subpixel_to_wayland(int drm_value) |
| 1500 | { |
| 1501 | switch (drm_value) { |
| 1502 | default: |
| 1503 | case DRM_MODE_SUBPIXEL_UNKNOWN: |
| 1504 | return WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 1505 | case DRM_MODE_SUBPIXEL_NONE: |
| 1506 | return WL_OUTPUT_SUBPIXEL_NONE; |
| 1507 | case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB: |
| 1508 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB; |
| 1509 | case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR: |
| 1510 | return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR; |
| 1511 | case DRM_MODE_SUBPIXEL_VERTICAL_RGB: |
| 1512 | return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB; |
| 1513 | case DRM_MODE_SUBPIXEL_VERTICAL_BGR: |
| 1514 | return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR; |
| 1515 | } |
| 1516 | } |
| 1517 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1518 | /* returns a value between 0-255 range, where higher is brighter */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1519 | static uint32_t |
| 1520 | drm_get_backlight(struct drm_output *output) |
| 1521 | { |
| 1522 | long brightness, max_brightness, norm; |
| 1523 | |
| 1524 | brightness = backlight_get_brightness(output->backlight); |
| 1525 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 1526 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1527 | /* convert it on a scale of 0 to 255 */ |
| 1528 | norm = (brightness * 255)/(max_brightness); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1529 | |
| 1530 | return (uint32_t) norm; |
| 1531 | } |
| 1532 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1533 | /* values accepted are between 0-255 range */ |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1534 | static void |
| 1535 | drm_set_backlight(struct weston_output *output_base, uint32_t value) |
| 1536 | { |
| 1537 | struct drm_output *output = (struct drm_output *) output_base; |
| 1538 | long max_brightness, new_brightness; |
| 1539 | |
| 1540 | if (!output->backlight) |
| 1541 | return; |
| 1542 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1543 | if (value > 255) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1544 | return; |
| 1545 | |
| 1546 | max_brightness = backlight_get_max_brightness(output->backlight); |
| 1547 | |
| 1548 | /* get denormalized value */ |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1549 | new_brightness = (value * max_brightness) / 255; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1550 | |
| 1551 | backlight_set_brightness(output->backlight, new_brightness); |
| 1552 | } |
| 1553 | |
| 1554 | static drmModePropertyPtr |
| 1555 | drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name) |
| 1556 | { |
| 1557 | drmModePropertyPtr props; |
| 1558 | int i; |
| 1559 | |
| 1560 | for (i = 0; i < connector->count_props; i++) { |
| 1561 | props = drmModeGetProperty(fd, connector->props[i]); |
| 1562 | if (!props) |
| 1563 | continue; |
| 1564 | |
| 1565 | if (!strcmp(props->name, name)) |
| 1566 | return props; |
| 1567 | |
| 1568 | drmModeFreeProperty(props); |
| 1569 | } |
| 1570 | |
| 1571 | return NULL; |
| 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | drm_set_dpms(struct weston_output *output_base, enum dpms_enum level) |
| 1576 | { |
| 1577 | struct drm_output *output = (struct drm_output *) output_base; |
| 1578 | struct weston_compositor *ec = output_base->compositor; |
| 1579 | struct drm_compositor *c = (struct drm_compositor *) ec; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1580 | |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 1581 | if (!output->dpms_prop) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1582 | return; |
| 1583 | |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 1584 | drmModeConnectorSetProperty(c->drm.fd, output->connector_id, |
| 1585 | output->dpms_prop->prop_id, level); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1586 | } |
| 1587 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1588 | static const char *connector_type_names[] = { |
| 1589 | "None", |
| 1590 | "VGA", |
| 1591 | "DVI", |
| 1592 | "DVI", |
| 1593 | "DVI", |
| 1594 | "Composite", |
| 1595 | "TV", |
| 1596 | "LVDS", |
| 1597 | "CTV", |
| 1598 | "DIN", |
| 1599 | "DP", |
| 1600 | "HDMI", |
| 1601 | "HDMI", |
| 1602 | "TV", |
| 1603 | "eDP", |
| 1604 | }; |
| 1605 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1606 | static int |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1607 | find_crtc_for_connector(struct drm_compositor *ec, |
| 1608 | drmModeRes *resources, drmModeConnector *connector) |
| 1609 | { |
| 1610 | drmModeEncoder *encoder; |
| 1611 | uint32_t possible_crtcs; |
| 1612 | int i, j; |
| 1613 | |
| 1614 | for (j = 0; j < connector->count_encoders; j++) { |
| 1615 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[j]); |
| 1616 | if (encoder == NULL) { |
| 1617 | weston_log("Failed to get encoder.\n"); |
| 1618 | return -1; |
| 1619 | } |
| 1620 | possible_crtcs = encoder->possible_crtcs; |
| 1621 | drmModeFreeEncoder(encoder); |
| 1622 | |
| 1623 | for (i = 0; i < resources->count_crtcs; i++) { |
| 1624 | if (possible_crtcs & (1 << i) && |
| 1625 | !(ec->crtc_allocator & (1 << resources->crtcs[i]))) |
| 1626 | return i; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | return -1; |
| 1631 | } |
| 1632 | |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1633 | /* Init output state that depends on gl or gbm */ |
| 1634 | static int |
| 1635 | drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec) |
| 1636 | { |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1637 | EGLint format[2] = { |
| 1638 | output->format, |
| 1639 | fallback_format_for(output->format), |
| 1640 | }; |
| 1641 | int i, flags, n_formats = 1; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1642 | |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1643 | output->surface = gbm_surface_create(ec->gbm, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1644 | output->base.current_mode->width, |
| 1645 | output->base.current_mode->height, |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1646 | format[0], |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1647 | GBM_BO_USE_SCANOUT | |
| 1648 | GBM_BO_USE_RENDERING); |
| 1649 | if (!output->surface) { |
| 1650 | weston_log("failed to create gbm surface\n"); |
| 1651 | return -1; |
| 1652 | } |
| 1653 | |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1654 | if (format[1]) |
| 1655 | n_formats = 2; |
Jonny Lamb | 671148f | 2015-03-20 15:26:52 +0100 | [diff] [blame] | 1656 | if (gl_renderer->output_create(&output->base, |
Jonny Lamb | 445fb69 | 2015-03-24 13:12:01 +0100 | [diff] [blame] | 1657 | (EGLNativeDisplayType)output->surface, |
| 1658 | output->surface, |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1659 | gl_renderer->opaque_attribs, |
Derek Foreman | c4cfe85 | 2015-05-15 12:12:40 -0500 | [diff] [blame^] | 1660 | format, |
| 1661 | n_formats) < 0) { |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1662 | weston_log("failed to create gl renderer output state\n"); |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1663 | gbm_surface_destroy(output->surface); |
| 1664 | return -1; |
| 1665 | } |
| 1666 | |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1667 | flags = GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE; |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1668 | |
| 1669 | for (i = 0; i < 2; i++) { |
| 1670 | if (output->cursor_bo[i]) |
| 1671 | continue; |
| 1672 | |
| 1673 | output->cursor_bo[i] = |
Alvaro Fernando García | dce7c6e | 2014-07-28 18:30:17 -0300 | [diff] [blame] | 1674 | gbm_bo_create(ec->gbm, ec->cursor_width, ec->cursor_height, |
| 1675 | GBM_FORMAT_ARGB8888, flags); |
Ander Conselvan de Oliveira | 6c01c9c | 2012-12-14 13:37:30 -0200 | [diff] [blame] | 1676 | } |
| 1677 | |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 1678 | if (output->cursor_bo[0] == NULL || output->cursor_bo[1] == NULL) { |
| 1679 | weston_log("cursor buffers unavailable, using gl cursors\n"); |
| 1680 | ec->cursors_are_broken = 1; |
| 1681 | } |
| 1682 | |
| 1683 | return 0; |
| 1684 | } |
| 1685 | |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1686 | static int |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1687 | drm_output_init_pixman(struct drm_output *output, struct drm_compositor *c) |
| 1688 | { |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 1689 | int w = output->base.current_mode->width; |
| 1690 | int h = output->base.current_mode->height; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1691 | unsigned int i; |
| 1692 | |
| 1693 | /* FIXME error checking */ |
| 1694 | |
| 1695 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1696 | output->dumb[i] = drm_fb_create_dumb(c, w, h); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1697 | if (!output->dumb[i]) |
| 1698 | goto err; |
| 1699 | |
| 1700 | output->image[i] = |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1701 | pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1702 | output->dumb[i]->map, |
| 1703 | output->dumb[i]->stride); |
| 1704 | if (!output->image[i]) |
| 1705 | goto err; |
| 1706 | } |
| 1707 | |
| 1708 | if (pixman_renderer_output_create(&output->base) < 0) |
| 1709 | goto err; |
| 1710 | |
| 1711 | pixman_region32_init_rect(&output->previous_damage, |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 1712 | output->base.x, output->base.y, output->base.width, output->base.height); |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1713 | |
| 1714 | return 0; |
| 1715 | |
| 1716 | err: |
| 1717 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
| 1718 | if (output->dumb[i]) |
| 1719 | drm_fb_destroy_dumb(output->dumb[i]); |
| 1720 | if (output->image[i]) |
| 1721 | pixman_image_unref(output->image[i]); |
| 1722 | |
| 1723 | output->dumb[i] = NULL; |
| 1724 | output->image[i] = NULL; |
| 1725 | } |
| 1726 | |
| 1727 | return -1; |
| 1728 | } |
| 1729 | |
| 1730 | static void |
| 1731 | drm_output_fini_pixman(struct drm_output *output) |
| 1732 | { |
| 1733 | unsigned int i; |
| 1734 | |
| 1735 | pixman_renderer_output_destroy(&output->base); |
| 1736 | pixman_region32_fini(&output->previous_damage); |
| 1737 | |
| 1738 | for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) { |
| 1739 | drm_fb_destroy_dumb(output->dumb[i]); |
| 1740 | pixman_image_unref(output->image[i]); |
| 1741 | output->dumb[i] = NULL; |
| 1742 | output->image[i] = NULL; |
| 1743 | } |
| 1744 | } |
| 1745 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 1746 | static void |
| 1747 | edid_parse_string(const uint8_t *data, char text[]) |
| 1748 | { |
| 1749 | int i; |
| 1750 | int replaced = 0; |
| 1751 | |
| 1752 | /* this is always 12 bytes, but we can't guarantee it's null |
| 1753 | * terminated or not junk. */ |
| 1754 | strncpy(text, (const char *) data, 12); |
| 1755 | |
| 1756 | /* remove insane chars */ |
| 1757 | for (i = 0; text[i] != '\0'; i++) { |
| 1758 | if (text[i] == '\n' || |
| 1759 | text[i] == '\r') { |
| 1760 | text[i] = '\0'; |
| 1761 | break; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | /* ensure string is printable */ |
| 1766 | for (i = 0; text[i] != '\0'; i++) { |
| 1767 | if (!isprint(text[i])) { |
| 1768 | text[i] = '-'; |
| 1769 | replaced++; |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | /* if the string is random junk, ignore the string */ |
| 1774 | if (replaced > 4) |
| 1775 | text[0] = '\0'; |
| 1776 | } |
| 1777 | |
| 1778 | #define EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe |
| 1779 | #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc |
| 1780 | #define EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff |
| 1781 | #define EDID_OFFSET_DATA_BLOCKS 0x36 |
| 1782 | #define EDID_OFFSET_LAST_BLOCK 0x6c |
| 1783 | #define EDID_OFFSET_PNPID 0x08 |
| 1784 | #define EDID_OFFSET_SERIAL 0x0c |
| 1785 | |
| 1786 | static int |
| 1787 | edid_parse(struct drm_edid *edid, const uint8_t *data, size_t length) |
| 1788 | { |
| 1789 | int i; |
| 1790 | uint32_t serial_number; |
| 1791 | |
| 1792 | /* check header */ |
| 1793 | if (length < 128) |
| 1794 | return -1; |
| 1795 | if (data[0] != 0x00 || data[1] != 0xff) |
| 1796 | return -1; |
| 1797 | |
| 1798 | /* decode the PNP ID from three 5 bit words packed into 2 bytes |
| 1799 | * /--08--\/--09--\ |
| 1800 | * 7654321076543210 |
| 1801 | * |\---/\---/\---/ |
| 1802 | * R C1 C2 C3 */ |
| 1803 | edid->pnp_id[0] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x7c) / 4) - 1; |
| 1804 | edid->pnp_id[1] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x3) * 8) + ((data[EDID_OFFSET_PNPID + 1] & 0xe0) / 32) - 1; |
| 1805 | edid->pnp_id[2] = 'A' + (data[EDID_OFFSET_PNPID + 1] & 0x1f) - 1; |
| 1806 | edid->pnp_id[3] = '\0'; |
| 1807 | |
| 1808 | /* maybe there isn't a ASCII serial number descriptor, so use this instead */ |
| 1809 | serial_number = (uint32_t) data[EDID_OFFSET_SERIAL + 0]; |
| 1810 | serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 1] * 0x100; |
| 1811 | serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 2] * 0x10000; |
| 1812 | serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 3] * 0x1000000; |
| 1813 | if (serial_number > 0) |
| 1814 | sprintf(edid->serial_number, "%lu", (unsigned long) serial_number); |
| 1815 | |
| 1816 | /* parse EDID data */ |
| 1817 | for (i = EDID_OFFSET_DATA_BLOCKS; |
| 1818 | i <= EDID_OFFSET_LAST_BLOCK; |
| 1819 | i += 18) { |
| 1820 | /* ignore pixel clock data */ |
| 1821 | if (data[i] != 0) |
| 1822 | continue; |
| 1823 | if (data[i+2] != 0) |
| 1824 | continue; |
| 1825 | |
| 1826 | /* any useful blocks? */ |
| 1827 | if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME) { |
| 1828 | edid_parse_string(&data[i+5], |
| 1829 | edid->monitor_name); |
| 1830 | } else if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) { |
| 1831 | edid_parse_string(&data[i+5], |
| 1832 | edid->serial_number); |
| 1833 | } else if (data[i+3] == EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) { |
| 1834 | edid_parse_string(&data[i+5], |
| 1835 | edid->eisa_id); |
| 1836 | } |
| 1837 | } |
| 1838 | return 0; |
| 1839 | } |
| 1840 | |
| 1841 | static void |
| 1842 | find_and_parse_output_edid(struct drm_compositor *ec, |
| 1843 | struct drm_output *output, |
| 1844 | drmModeConnector *connector) |
| 1845 | { |
| 1846 | drmModePropertyBlobPtr edid_blob = NULL; |
| 1847 | drmModePropertyPtr property; |
| 1848 | int i; |
| 1849 | int rc; |
| 1850 | |
| 1851 | for (i = 0; i < connector->count_props && !edid_blob; i++) { |
| 1852 | property = drmModeGetProperty(ec->drm.fd, connector->props[i]); |
| 1853 | if (!property) |
| 1854 | continue; |
| 1855 | if ((property->flags & DRM_MODE_PROP_BLOB) && |
| 1856 | !strcmp(property->name, "EDID")) { |
| 1857 | edid_blob = drmModeGetPropertyBlob(ec->drm.fd, |
| 1858 | connector->prop_values[i]); |
| 1859 | } |
| 1860 | drmModeFreeProperty(property); |
| 1861 | } |
| 1862 | if (!edid_blob) |
| 1863 | return; |
| 1864 | |
| 1865 | rc = edid_parse(&output->edid, |
| 1866 | edid_blob->data, |
| 1867 | edid_blob->length); |
| 1868 | if (!rc) { |
| 1869 | weston_log("EDID data '%s', '%s', '%s'\n", |
| 1870 | output->edid.pnp_id, |
| 1871 | output->edid.monitor_name, |
| 1872 | output->edid.serial_number); |
| 1873 | if (output->edid.pnp_id[0] != '\0') |
| 1874 | output->base.make = output->edid.pnp_id; |
| 1875 | if (output->edid.monitor_name[0] != '\0') |
| 1876 | output->base.model = output->edid.monitor_name; |
| 1877 | if (output->edid.serial_number[0] != '\0') |
| 1878 | output->base.serial_number = output->edid.serial_number; |
| 1879 | } |
| 1880 | drmModeFreePropertyBlob(edid_blob); |
| 1881 | } |
| 1882 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1883 | |
| 1884 | |
| 1885 | static int |
| 1886 | parse_modeline(const char *s, drmModeModeInfo *mode) |
| 1887 | { |
| 1888 | char hsync[16]; |
| 1889 | char vsync[16]; |
| 1890 | float fclock; |
| 1891 | |
| 1892 | mode->type = DRM_MODE_TYPE_USERDEF; |
| 1893 | mode->hskew = 0; |
| 1894 | mode->vscan = 0; |
| 1895 | mode->vrefresh = 0; |
| 1896 | mode->flags = 0; |
| 1897 | |
Rob Bradford | 307e09e | 2013-07-26 16:29:40 +0100 | [diff] [blame] | 1898 | if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s", |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1899 | &fclock, |
| 1900 | &mode->hdisplay, |
| 1901 | &mode->hsync_start, |
| 1902 | &mode->hsync_end, |
| 1903 | &mode->htotal, |
| 1904 | &mode->vdisplay, |
| 1905 | &mode->vsync_start, |
| 1906 | &mode->vsync_end, |
| 1907 | &mode->vtotal, hsync, vsync) != 11) |
| 1908 | return -1; |
| 1909 | |
| 1910 | mode->clock = fclock * 1000; |
| 1911 | if (strcmp(hsync, "+hsync") == 0) |
| 1912 | mode->flags |= DRM_MODE_FLAG_PHSYNC; |
| 1913 | else if (strcmp(hsync, "-hsync") == 0) |
| 1914 | mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 1915 | else |
| 1916 | return -1; |
| 1917 | |
| 1918 | if (strcmp(vsync, "+vsync") == 0) |
| 1919 | mode->flags |= DRM_MODE_FLAG_PVSYNC; |
| 1920 | else if (strcmp(vsync, "-vsync") == 0) |
| 1921 | mode->flags |= DRM_MODE_FLAG_NVSYNC; |
| 1922 | else |
| 1923 | return -1; |
| 1924 | |
| 1925 | return 0; |
| 1926 | } |
| 1927 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1928 | static void |
| 1929 | setup_output_seat_constraint(struct drm_compositor *ec, |
| 1930 | struct weston_output *output, |
| 1931 | const char *s) |
| 1932 | { |
| 1933 | if (strcmp(s, "") != 0) { |
| 1934 | struct udev_seat *seat; |
| 1935 | |
Jonas Ådahl | 58e1586 | 2014-03-12 22:08:40 +0100 | [diff] [blame] | 1936 | seat = udev_seat_get_named(&ec->input, s); |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1937 | if (seat) |
| 1938 | seat->base.output = output; |
| 1939 | |
| 1940 | if (seat && seat->base.pointer) |
| 1941 | weston_pointer_clamp(seat->base.pointer, |
| 1942 | &seat->base.pointer->x, |
| 1943 | &seat->base.pointer->y); |
| 1944 | } |
| 1945 | } |
| 1946 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 1947 | static int |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 1948 | get_gbm_format_from_section(struct weston_config_section *section, |
| 1949 | uint32_t default_value, |
| 1950 | uint32_t *format) |
| 1951 | { |
| 1952 | char *s; |
| 1953 | int ret = 0; |
| 1954 | |
| 1955 | weston_config_section_get_string(section, |
| 1956 | "gbm-format", &s, NULL); |
| 1957 | |
| 1958 | if (s == NULL) |
| 1959 | *format = default_value; |
| 1960 | else if (strcmp(s, "xrgb8888") == 0) |
| 1961 | *format = GBM_FORMAT_XRGB8888; |
| 1962 | else if (strcmp(s, "rgb565") == 0) |
| 1963 | *format = GBM_FORMAT_RGB565; |
| 1964 | else if (strcmp(s, "xrgb2101010") == 0) |
| 1965 | *format = GBM_FORMAT_XRGB2101010; |
| 1966 | else { |
| 1967 | weston_log("fatal: unrecognized pixel format: %s\n", s); |
| 1968 | ret = -1; |
| 1969 | } |
| 1970 | |
| 1971 | free(s); |
| 1972 | |
| 1973 | return ret; |
| 1974 | } |
| 1975 | |
| 1976 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1977 | create_output_for_connector(struct drm_compositor *ec, |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1978 | drmModeRes *resources, |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1979 | drmModeConnector *connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1980 | int x, int y, struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1981 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1982 | struct drm_output *output; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 1983 | struct drm_mode *drm_mode, *next, *preferred, *current, *configured, *best; |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 1984 | struct weston_mode *m; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1985 | struct weston_config_section *section; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1986 | drmModeEncoder *encoder; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1987 | drmModeModeInfo crtc_mode, modeline; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 1988 | drmModeCrtc *crtc; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1989 | int i, width, height, scale; |
| 1990 | char name[32], *s; |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 1991 | const char *type_name; |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 1992 | enum output_config config; |
| 1993 | uint32_t transform; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1994 | |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 1995 | i = find_crtc_for_connector(ec, resources, connector); |
| 1996 | if (i < 0) { |
| 1997 | weston_log("No usable crtc/encoder pair for connector.\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 1998 | return -1; |
| 1999 | } |
| 2000 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2001 | output = zalloc(sizeof *output); |
Kristian Høgsberg | 9ca3846 | 2012-07-26 22:44:55 -0400 | [diff] [blame] | 2002 | if (output == NULL) |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2003 | return -1; |
| 2004 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2005 | output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel); |
| 2006 | output->base.make = "unknown"; |
| 2007 | output->base.model = "unknown"; |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 2008 | output->base.serial_number = "unknown"; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2009 | wl_list_init(&output->base.mode_list); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2010 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 2011 | if (connector->connector_type < ARRAY_LENGTH(connector_type_names)) |
| 2012 | type_name = connector_type_names[connector->connector_type]; |
| 2013 | else |
| 2014 | type_name = "UNKNOWN"; |
| 2015 | snprintf(name, 32, "%s%d", type_name, connector->connector_type_id); |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 2016 | output->base.name = strdup(name); |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 2017 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2018 | section = weston_config_get_section(ec->base.config, "output", "name", |
| 2019 | output->base.name); |
| 2020 | weston_config_section_get_string(section, "mode", &s, "preferred"); |
| 2021 | if (strcmp(s, "off") == 0) |
| 2022 | config = OUTPUT_CONFIG_OFF; |
| 2023 | else if (strcmp(s, "preferred") == 0) |
| 2024 | config = OUTPUT_CONFIG_PREFERRED; |
| 2025 | else if (strcmp(s, "current") == 0) |
| 2026 | config = OUTPUT_CONFIG_CURRENT; |
| 2027 | else if (sscanf(s, "%dx%d", &width, &height) == 2) |
| 2028 | config = OUTPUT_CONFIG_MODE; |
| 2029 | else if (parse_modeline(s, &modeline) == 0) |
| 2030 | config = OUTPUT_CONFIG_MODELINE; |
| 2031 | else { |
| 2032 | weston_log("Invalid mode \"%s\" for output %s\n", |
| 2033 | s, output->base.name); |
| 2034 | config = OUTPUT_CONFIG_PREFERRED; |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 2035 | } |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2036 | free(s); |
| 2037 | |
| 2038 | weston_config_section_get_int(section, "scale", &scale, 1); |
| 2039 | weston_config_section_get_string(section, "transform", &s, "normal"); |
Derek Foreman | 64a3df0 | 2014-10-23 12:24:18 -0500 | [diff] [blame] | 2040 | if (weston_parse_transform(s, &transform) < 0) |
| 2041 | weston_log("Invalid transform \"%s\" for output %s\n", |
| 2042 | s, output->base.name); |
| 2043 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2044 | free(s); |
Alexander Larsson | d9a7bb7 | 2013-05-22 14:41:39 +0200 | [diff] [blame] | 2045 | |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 2046 | if (get_gbm_format_from_section(section, |
| 2047 | ec->format, |
| 2048 | &output->format) == -1) |
| 2049 | output->format = ec->format; |
| 2050 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 2051 | weston_config_section_get_string(section, "seat", &s, ""); |
| 2052 | setup_output_seat_constraint(ec, &output->base, s); |
| 2053 | free(s); |
| 2054 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2055 | output->crtc_id = resources->crtcs[i]; |
Rob Clark | 5ca1a47 | 2012-08-08 20:27:37 -0500 | [diff] [blame] | 2056 | output->pipe = i; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2057 | ec->crtc_allocator |= (1 << output->crtc_id); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2058 | output->connector_id = connector->connector_id; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2059 | ec->connector_allocator |= (1 << output->connector_id); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2060 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2061 | output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id); |
Ander Conselvan de Oliveira | a0a433a | 2013-06-04 16:24:04 +0300 | [diff] [blame] | 2062 | output->dpms_prop = drm_get_prop(ec->drm.fd, connector, "DPMS"); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2063 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2064 | /* Get the current mode on the crtc that's currently driving |
| 2065 | * this connector. */ |
| 2066 | encoder = drmModeGetEncoder(ec->drm.fd, connector->encoder_id); |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2067 | memset(&crtc_mode, 0, sizeof crtc_mode); |
| 2068 | if (encoder != NULL) { |
| 2069 | crtc = drmModeGetCrtc(ec->drm.fd, encoder->crtc_id); |
| 2070 | drmModeFreeEncoder(encoder); |
| 2071 | if (crtc == NULL) |
| 2072 | goto err_free; |
| 2073 | if (crtc->mode_valid) |
| 2074 | crtc_mode = crtc->mode; |
| 2075 | drmModeFreeCrtc(crtc); |
| 2076 | } |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2077 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2078 | for (i = 0; i < connector->count_modes; i++) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2079 | drm_mode = drm_output_add_mode(output, &connector->modes[i]); |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2080 | if (!drm_mode) |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2081 | goto err_free; |
| 2082 | } |
| 2083 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2084 | if (config == OUTPUT_CONFIG_OFF) { |
| 2085 | weston_log("Disabling output %s\n", output->base.name); |
| 2086 | drmModeSetCrtc(ec->drm.fd, output->crtc_id, |
| 2087 | 0, 0, 0, 0, 0, NULL); |
| 2088 | goto err_free; |
| 2089 | } |
| 2090 | |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2091 | preferred = NULL; |
| 2092 | current = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2093 | configured = NULL; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 2094 | best = NULL; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2095 | |
Giulio Camuffo | c0b9487 | 2013-06-19 15:19:19 +0200 | [diff] [blame] | 2096 | wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) { |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2097 | if (config == OUTPUT_CONFIG_MODE && |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2098 | width == drm_mode->base.width && |
| 2099 | height == drm_mode->base.height) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2100 | configured = drm_mode; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2101 | if (!memcmp(&crtc_mode, &drm_mode->mode_info, sizeof crtc_mode)) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2102 | current = drm_mode; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2103 | if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED) |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2104 | preferred = drm_mode; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 2105 | best = drm_mode; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2106 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2107 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2108 | if (config == OUTPUT_CONFIG_MODELINE) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2109 | configured = drm_output_add_mode(output, &modeline); |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2110 | if (!configured) |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 2111 | goto err_free; |
Scott Moreau | 8f37e0b | 2012-07-31 15:30:41 -0600 | [diff] [blame] | 2112 | } |
| 2113 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2114 | if (current == NULL && crtc_mode.clock != 0) { |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2115 | current = drm_output_add_mode(output, &crtc_mode); |
Ander Conselvan de Oliveira | 42c4646 | 2012-08-09 16:45:00 +0300 | [diff] [blame] | 2116 | if (!current) |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2117 | goto err_free; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2118 | } |
| 2119 | |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2120 | if (config == OUTPUT_CONFIG_CURRENT) |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2121 | configured = current; |
| 2122 | |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2123 | if (option_current_mode && current) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2124 | output->base.current_mode = ¤t->base; |
Scott Moreau | 8ab5d45 | 2012-07-30 19:51:08 -0600 | [diff] [blame] | 2125 | else if (configured) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2126 | output->base.current_mode = &configured->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2127 | else if (preferred) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2128 | output->base.current_mode = &preferred->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2129 | else if (current) |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2130 | output->base.current_mode = ¤t->base; |
Fabien DESSENNE | 4b25587 | 2013-12-12 17:13:56 +0100 | [diff] [blame] | 2131 | else if (best) |
| 2132 | output->base.current_mode = &best->base; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2133 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2134 | if (output->base.current_mode == NULL) { |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 2135 | weston_log("no available modes for %s\n", output->base.name); |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2136 | goto err_free; |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2137 | } |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2138 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2139 | output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT; |
Wang Quanxian | acb805a | 2012-07-30 18:09:46 -0400 | [diff] [blame] | 2140 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2141 | weston_output_init(&output->base, &ec->base, x, y, |
| 2142 | connector->mmWidth, connector->mmHeight, |
Kristian Høgsberg | a30989a | 2013-05-23 17:23:15 -0400 | [diff] [blame] | 2143 | transform, scale); |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2144 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2145 | if (ec->use_pixman) { |
| 2146 | if (drm_output_init_pixman(output, ec) < 0) { |
| 2147 | weston_log("Failed to init output pixman state\n"); |
| 2148 | goto err_output; |
| 2149 | } |
| 2150 | } else if (drm_output_init_egl(output, ec) < 0) { |
Ander Conselvan de Oliveira | 475cf15 | 2012-12-14 13:37:29 -0200 | [diff] [blame] | 2151 | weston_log("Failed to init output gl state\n"); |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2152 | goto err_output; |
Kristian Høgsberg | 1d1e0a5 | 2012-10-21 13:29:26 -0400 | [diff] [blame] | 2153 | } |
Kristian Høgsberg | 8e1f77f | 2012-05-03 11:39:35 -0400 | [diff] [blame] | 2154 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2155 | output->backlight = backlight_init(drm_device, |
| 2156 | connector->connector_type); |
| 2157 | if (output->backlight) { |
Kristian Høgsberg | 220819f | 2013-05-23 20:29:40 -0400 | [diff] [blame] | 2158 | weston_log("Initialized backlight, device %s\n", |
| 2159 | output->backlight->path); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2160 | output->base.set_backlight = drm_set_backlight; |
| 2161 | output->base.backlight_current = drm_get_backlight(output); |
Kristian Høgsberg | 220819f | 2013-05-23 20:29:40 -0400 | [diff] [blame] | 2162 | } else { |
| 2163 | weston_log("Failed to initialize backlight\n"); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2164 | } |
| 2165 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 2166 | weston_compositor_add_output(&ec->base, &output->base); |
Kristian Høgsberg | a4b7e20 | 2011-10-24 13:26:32 -0400 | [diff] [blame] | 2167 | |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 2168 | find_and_parse_output_edid(ec, output, connector); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 2169 | if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) |
| 2170 | output->base.connection_internal = 1; |
Richard Hughes | 2b2092a | 2013-04-24 14:58:02 +0100 | [diff] [blame] | 2171 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2172 | output->base.start_repaint_loop = drm_output_start_repaint_loop; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 2173 | output->base.repaint = drm_output_repaint; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2174 | output->base.destroy = drm_output_destroy; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2175 | output->base.assign_planes = drm_assign_planes; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2176 | output->base.set_dpms = drm_set_dpms; |
Alex Wu | b7b8bda | 2012-04-17 17:20:48 +0800 | [diff] [blame] | 2177 | output->base.switch_mode = drm_output_switch_mode; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2178 | |
Richard Hughes | e729996 | 2013-05-01 21:52:12 +0100 | [diff] [blame] | 2179 | output->base.gamma_size = output->original_crtc->gamma_size; |
| 2180 | output->base.set_gamma = drm_output_set_gamma; |
| 2181 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2182 | weston_plane_init(&output->cursor_plane, &ec->base, 0, 0); |
| 2183 | weston_plane_init(&output->fb_plane, &ec->base, 0, 0); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2184 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2185 | weston_compositor_stack_plane(&ec->base, &output->cursor_plane, NULL); |
| 2186 | weston_compositor_stack_plane(&ec->base, &output->fb_plane, |
| 2187 | &ec->base.primary_plane); |
| 2188 | |
Kristian Høgsberg | 2f9ed71 | 2012-07-26 17:57:15 -0400 | [diff] [blame] | 2189 | weston_log("Output %s, (connector %d, crtc %d)\n", |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 2190 | output->base.name, output->connector_id, output->crtc_id); |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2191 | wl_list_for_each(m, &output->base.mode_list, link) |
U. Artie Eoff | d3ed6cb | 2014-01-10 10:15:17 -0800 | [diff] [blame] | 2192 | weston_log_continue(STAMP_SPACE "mode %dx%d@%.1f%s%s%s\n", |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2193 | m->width, m->height, m->refresh / 1000.0, |
| 2194 | m->flags & WL_OUTPUT_MODE_PREFERRED ? |
| 2195 | ", preferred" : "", |
| 2196 | m->flags & WL_OUTPUT_MODE_CURRENT ? |
| 2197 | ", current" : "", |
| 2198 | connector->count_modes == 0 ? |
| 2199 | ", built-in" : ""); |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2200 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2201 | return 0; |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2202 | |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 2203 | err_output: |
| 2204 | weston_output_destroy(&output->base); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2205 | err_free: |
| 2206 | wl_list_for_each_safe(drm_mode, next, &output->base.mode_list, |
| 2207 | base.link) { |
| 2208 | wl_list_remove(&drm_mode->base.link); |
| 2209 | free(drm_mode); |
| 2210 | } |
| 2211 | |
| 2212 | drmModeFreeCrtc(output->original_crtc); |
| 2213 | ec->crtc_allocator &= ~(1 << output->crtc_id); |
| 2214 | ec->connector_allocator &= ~(1 << output->connector_id); |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2215 | free(output); |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 2216 | |
David Herrmann | 0f0d54e | 2011-12-08 17:05:45 +0100 | [diff] [blame] | 2217 | return -1; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2218 | } |
| 2219 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2220 | static void |
| 2221 | create_sprites(struct drm_compositor *ec) |
| 2222 | { |
| 2223 | struct drm_sprite *sprite; |
| 2224 | drmModePlaneRes *plane_res; |
| 2225 | drmModePlane *plane; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2226 | uint32_t i; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2227 | |
| 2228 | plane_res = drmModeGetPlaneResources(ec->drm.fd); |
| 2229 | if (!plane_res) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2230 | weston_log("failed to get plane resources: %s\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2231 | strerror(errno)); |
| 2232 | return; |
| 2233 | } |
| 2234 | |
| 2235 | for (i = 0; i < plane_res->count_planes; i++) { |
| 2236 | plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]); |
| 2237 | if (!plane) |
| 2238 | continue; |
| 2239 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2240 | sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) * |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2241 | plane->count_formats)); |
| 2242 | if (!sprite) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2243 | weston_log("%s: out of memory\n", |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2244 | __func__); |
Chris Michael | 8b37687 | 2014-01-02 11:39:40 +0000 | [diff] [blame] | 2245 | drmModeFreePlane(plane); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2246 | continue; |
| 2247 | } |
| 2248 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2249 | sprite->possible_crtcs = plane->possible_crtcs; |
| 2250 | sprite->plane_id = plane->plane_id; |
Ander Conselvan de Oliveira | 8d360b4 | 2012-11-09 14:19:05 +0200 | [diff] [blame] | 2251 | sprite->current = NULL; |
| 2252 | sprite->next = NULL; |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2253 | sprite->compositor = ec; |
| 2254 | sprite->count_formats = plane->count_formats; |
| 2255 | memcpy(sprite->formats, plane->formats, |
Rob Clark | 8efbc8e | 2012-03-11 19:48:44 -0500 | [diff] [blame] | 2256 | plane->count_formats * sizeof(plane->formats[0])); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2257 | drmModeFreePlane(plane); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2258 | weston_plane_init(&sprite->plane, &ec->base, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2259 | weston_compositor_stack_plane(&ec->base, &sprite->plane, |
| 2260 | &ec->base.primary_plane); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2261 | |
| 2262 | wl_list_insert(&ec->sprite_list, &sprite->link); |
| 2263 | } |
| 2264 | |
Samuel Iglesias Gonsalvez | de46673 | 2013-06-13 10:03:33 +0200 | [diff] [blame] | 2265 | drmModeFreePlaneResources(plane_res); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2266 | } |
| 2267 | |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2268 | static void |
| 2269 | destroy_sprites(struct drm_compositor *compositor) |
| 2270 | { |
| 2271 | struct drm_sprite *sprite, *next; |
| 2272 | struct drm_output *output; |
| 2273 | |
| 2274 | output = container_of(compositor->base.output_list.next, |
| 2275 | struct drm_output, base.link); |
| 2276 | |
| 2277 | wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) { |
| 2278 | drmModeSetPlane(compositor->drm.fd, |
| 2279 | sprite->plane_id, |
| 2280 | output->crtc_id, 0, 0, |
| 2281 | 0, 0, 0, 0, 0, 0, 0, 0); |
Ander Conselvan de Oliveira | 526d461 | 2013-01-25 15:13:03 +0200 | [diff] [blame] | 2282 | drm_output_release_fb(output, sprite->current); |
| 2283 | drm_output_release_fb(output, sprite->next); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2284 | weston_plane_release(&sprite->plane); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2285 | free(sprite); |
| 2286 | } |
| 2287 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2288 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2289 | static int |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2290 | create_outputs(struct drm_compositor *ec, uint32_t option_connector, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2291 | struct udev_device *drm_device) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2292 | { |
| 2293 | drmModeConnector *connector; |
| 2294 | drmModeRes *resources; |
| 2295 | int i; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2296 | int x = 0, y = 0; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2297 | |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 2298 | resources = drmModeGetResources(ec->drm.fd); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2299 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2300 | weston_log("drmModeGetResources failed\n"); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2301 | return -1; |
| 2302 | } |
| 2303 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2304 | ec->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t)); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 2305 | if (!ec->crtcs) { |
| 2306 | drmModeFreeResources(resources); |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2307 | return -1; |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 2308 | } |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2309 | |
Rob Clark | 4339add | 2012-08-09 14:18:28 -0500 | [diff] [blame] | 2310 | ec->min_width = resources->min_width; |
| 2311 | ec->max_width = resources->max_width; |
| 2312 | ec->min_height = resources->min_height; |
| 2313 | ec->max_height = resources->max_height; |
| 2314 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2315 | ec->num_crtcs = resources->count_crtcs; |
| 2316 | memcpy(ec->crtcs, resources->crtcs, sizeof(uint32_t) * ec->num_crtcs); |
| 2317 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2318 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2319 | connector = drmModeGetConnector(ec->drm.fd, |
| 2320 | resources->connectors[i]); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2321 | if (connector == NULL) |
| 2322 | continue; |
| 2323 | |
| 2324 | if (connector->connection == DRM_MODE_CONNECTED && |
| 2325 | (option_connector == 0 || |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 2326 | connector->connector_id == option_connector)) { |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2327 | if (create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2328 | connector, x, y, |
| 2329 | drm_device) < 0) { |
Benjamin Franzke | 439d986 | 2011-10-07 08:20:53 +0200 | [diff] [blame] | 2330 | drmModeFreeConnector(connector); |
| 2331 | continue; |
| 2332 | } |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2333 | |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 2334 | x += container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2335 | struct weston_output, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2336 | link)->width; |
Benjamin Franzke | 9eaee35 | 2011-08-02 13:03:54 +0200 | [diff] [blame] | 2337 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 2338 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2339 | drmModeFreeConnector(connector); |
| 2340 | } |
| 2341 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2342 | if (wl_list_empty(&ec->base.output_list)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2343 | weston_log("No currently active connector found.\n"); |
Christopher Michael | eb866cd | 2012-03-07 14:55:21 -0500 | [diff] [blame] | 2344 | drmModeFreeResources(resources); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2345 | return -1; |
| 2346 | } |
| 2347 | |
| 2348 | drmModeFreeResources(resources); |
| 2349 | |
| 2350 | return 0; |
| 2351 | } |
| 2352 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2353 | static void |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2354 | update_outputs(struct drm_compositor *ec, struct udev_device *drm_device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2355 | { |
| 2356 | drmModeConnector *connector; |
| 2357 | drmModeRes *resources; |
| 2358 | struct drm_output *output, *next; |
| 2359 | int x = 0, y = 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2360 | uint32_t connected = 0, disconnects = 0; |
| 2361 | int i; |
| 2362 | |
| 2363 | resources = drmModeGetResources(ec->drm.fd); |
| 2364 | if (!resources) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2365 | weston_log("drmModeGetResources failed\n"); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2366 | return; |
| 2367 | } |
| 2368 | |
| 2369 | /* collect new connects */ |
| 2370 | for (i = 0; i < resources->count_connectors; i++) { |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2371 | int connector_id = resources->connectors[i]; |
| 2372 | |
| 2373 | connector = drmModeGetConnector(ec->drm.fd, connector_id); |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 2374 | if (connector == NULL) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2375 | continue; |
| 2376 | |
David Herrmann | 7551cff | 2011-12-08 17:05:43 +0100 | [diff] [blame] | 2377 | if (connector->connection != DRM_MODE_CONNECTED) { |
| 2378 | drmModeFreeConnector(connector); |
| 2379 | continue; |
| 2380 | } |
| 2381 | |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2382 | connected |= (1 << connector_id); |
| 2383 | |
| 2384 | if (!(ec->connector_allocator & (1 << connector_id))) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2385 | struct weston_output *last = |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2386 | container_of(ec->base.output_list.prev, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2387 | struct weston_output, link); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2388 | |
| 2389 | /* XXX: not yet needed, we die with 0 outputs */ |
| 2390 | if (!wl_list_empty(&ec->base.output_list)) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2391 | x = last->x + last->width; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2392 | else |
| 2393 | x = 0; |
| 2394 | y = 0; |
| 2395 | create_output_for_connector(ec, resources, |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2396 | connector, x, y, |
| 2397 | drm_device); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2398 | weston_log("connector %d connected\n", connector_id); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2399 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2400 | } |
| 2401 | drmModeFreeConnector(connector); |
| 2402 | } |
| 2403 | drmModeFreeResources(resources); |
| 2404 | |
| 2405 | disconnects = ec->connector_allocator & ~connected; |
| 2406 | if (disconnects) { |
| 2407 | wl_list_for_each_safe(output, next, &ec->base.output_list, |
| 2408 | base.link) { |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2409 | if (disconnects & (1 << output->connector_id)) { |
| 2410 | disconnects &= ~(1 << output->connector_id); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2411 | weston_log("connector %d disconnected\n", |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2412 | output->connector_id); |
Benjamin Franzke | 48c4ea2 | 2011-08-30 11:44:56 +0200 | [diff] [blame] | 2413 | drm_output_destroy(&output->base); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | /* FIXME: handle zero outputs, without terminating */ |
| 2419 | if (ec->connector_allocator == 0) |
| 2420 | wl_display_terminate(ec->base.wl_display); |
| 2421 | } |
| 2422 | |
| 2423 | static int |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2424 | udev_event_is_hotplug(struct drm_compositor *ec, struct udev_device *device) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2425 | { |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2426 | const char *sysnum; |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2427 | const char *val; |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2428 | |
| 2429 | sysnum = udev_device_get_sysnum(device); |
| 2430 | if (!sysnum || atoi(sysnum) != ec->drm.id) |
| 2431 | return 0; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2432 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2433 | val = udev_device_get_property_value(device, "HOTPLUG"); |
| 2434 | if (!val) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2435 | return 0; |
| 2436 | |
David Herrmann | 6ac52db | 2012-03-11 20:05:22 +0100 | [diff] [blame] | 2437 | return strcmp(val, "1") == 0; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2438 | } |
| 2439 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2440 | static int |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2441 | udev_drm_event(int fd, uint32_t mask, void *data) |
| 2442 | { |
| 2443 | struct drm_compositor *ec = data; |
| 2444 | struct udev_device *event; |
| 2445 | |
| 2446 | event = udev_monitor_receive_device(ec->udev_monitor); |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2447 | |
David Herrmann | d7488c2 | 2012-03-11 20:05:21 +0100 | [diff] [blame] | 2448 | if (udev_event_is_hotplug(ec, event)) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2449 | update_outputs(ec, event); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2450 | |
| 2451 | udev_device_unref(event); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2452 | |
| 2453 | return 1; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2454 | } |
| 2455 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2456 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2457 | drm_restore(struct weston_compositor *ec) |
| 2458 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2459 | weston_launcher_restore(ec->launcher); |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2463 | drm_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2464 | { |
| 2465 | struct drm_compositor *d = (struct drm_compositor *) ec; |
| 2466 | |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 2467 | udev_input_destroy(&d->input); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 2468 | |
| 2469 | wl_event_source_remove(d->udev_drm_source); |
| 2470 | wl_event_source_remove(d->drm_source); |
| 2471 | |
Kristian Høgsberg | 3d64a3e | 2013-05-10 12:36:04 -0400 | [diff] [blame] | 2472 | destroy_sprites(d); |
| 2473 | |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 2474 | weston_compositor_shutdown(ec); |
| 2475 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2476 | if (d->gbm) |
| 2477 | gbm_device_destroy(d->gbm); |
| 2478 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2479 | weston_launcher_destroy(d->base.launcher); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2480 | |
Rob Bradford | 45c15b8 | 2013-07-26 16:29:35 +0100 | [diff] [blame] | 2481 | close(d->drm.fd); |
| 2482 | |
Kristian Høgsberg | e4762a6 | 2011-01-14 14:59:13 -0500 | [diff] [blame] | 2483 | free(d); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2484 | } |
| 2485 | |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2486 | static void |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2487 | drm_compositor_set_modes(struct drm_compositor *compositor) |
| 2488 | { |
| 2489 | struct drm_output *output; |
| 2490 | struct drm_mode *drm_mode; |
| 2491 | int ret; |
| 2492 | |
| 2493 | wl_list_for_each(output, &compositor->base.output_list, base.link) { |
Ander Conselvan de Oliveira | 2002f88 | 2013-02-26 13:44:58 +0200 | [diff] [blame] | 2494 | if (!output->current) { |
| 2495 | /* If something that would cause the output to |
| 2496 | * switch mode happened while in another vt, we |
| 2497 | * might not have a current drm_fb. In that case, |
| 2498 | * schedule a repaint and let drm_output_repaint |
| 2499 | * handle setting the mode. */ |
| 2500 | weston_output_schedule_repaint(&output->base); |
| 2501 | continue; |
| 2502 | } |
| 2503 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2504 | drm_mode = (struct drm_mode *) output->base.current_mode; |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2505 | ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id, |
Ander Conselvan de Oliveira | 555c17d | 2012-05-02 16:42:21 +0300 | [diff] [blame] | 2506 | output->current->fb_id, 0, 0, |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2507 | &output->connector_id, 1, |
| 2508 | &drm_mode->mode_info); |
| 2509 | if (ret < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2510 | weston_log( |
Kristian Høgsberg | cbcd047 | 2012-03-11 18:27:41 -0400 | [diff] [blame] | 2511 | "failed to set mode %dx%d for output at %d,%d: %m\n", |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2512 | drm_mode->base.width, drm_mode->base.height, |
| 2513 | output->base.x, output->base.y); |
| 2514 | } |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | static void |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2519 | session_notify(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2520 | { |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2521 | struct weston_compositor *compositor = data; |
| 2522 | struct drm_compositor *ec = data; |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2523 | struct drm_sprite *sprite; |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2524 | struct drm_output *output; |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2525 | |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2526 | if (ec->base.session_active) { |
| 2527 | weston_log("activating session\n"); |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2528 | compositor->state = ec->prev_state; |
Kristian Høgsberg | 835cd49 | 2012-01-18 11:48:46 -0500 | [diff] [blame] | 2529 | drm_compositor_set_modes(ec); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2530 | weston_compositor_damage_all(compositor); |
Jonas Ådahl | 0feb32e | 2014-03-12 22:08:41 +0100 | [diff] [blame] | 2531 | udev_input_enable(&ec->input); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2532 | } else { |
| 2533 | weston_log("deactivating session\n"); |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 2534 | udev_input_disable(&ec->input); |
Kristian Høgsberg | 4014a6b | 2012-04-10 00:08:45 -0400 | [diff] [blame] | 2535 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2536 | ec->prev_state = compositor->state; |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2537 | weston_compositor_offscreen(compositor); |
Kristian Høgsberg | d8e181b | 2011-05-06 15:38:28 -0400 | [diff] [blame] | 2538 | |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2539 | /* If we have a repaint scheduled (either from a |
| 2540 | * pending pageflip or the idle handler), make sure we |
| 2541 | * cancel that so we don't try to pageflip when we're |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2542 | * vt switched away. The OFFSCREEN state will prevent |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2543 | * further attemps at repainting. When we switch |
| 2544 | * back, we schedule a repaint, which will process |
| 2545 | * pending frame callbacks. */ |
| 2546 | |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2547 | wl_list_for_each(output, &ec->base.output_list, base.link) { |
| 2548 | output->base.repaint_needed = 0; |
| 2549 | drmModeSetCursor(ec->drm.fd, output->crtc_id, 0, 0, 0); |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2550 | } |
| 2551 | |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2552 | output = container_of(ec->base.output_list.next, |
| 2553 | struct drm_output, base.link); |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2554 | |
| 2555 | wl_list_for_each(sprite, &ec->sprite_list, link) |
| 2556 | drmModeSetPlane(ec->drm.fd, |
| 2557 | sprite->plane_id, |
Kristian Høgsberg | a6edab3 | 2012-07-14 01:06:28 -0400 | [diff] [blame] | 2558 | output->crtc_id, 0, 0, |
Kristian Høgsberg | 85fd327 | 2012-02-23 21:45:32 -0500 | [diff] [blame] | 2559 | 0, 0, 0, 0, 0, 0, 0, 0); |
Kristian Høgsberg | 9396fc5 | 2011-05-06 15:15:37 -0400 | [diff] [blame] | 2560 | }; |
| 2561 | } |
| 2562 | |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2563 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2564 | switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2565 | { |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2566 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2567 | |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2568 | weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2571 | /* |
| 2572 | * Find primary GPU |
| 2573 | * Some systems may have multiple DRM devices attached to a single seat. This |
| 2574 | * function loops over all devices and tries to find a PCI device with the |
| 2575 | * boot_vga sysfs attribute set to 1. |
| 2576 | * If no such device is found, the first DRM device reported by udev is used. |
| 2577 | */ |
| 2578 | static struct udev_device* |
| 2579 | find_primary_gpu(struct drm_compositor *ec, const char *seat) |
| 2580 | { |
| 2581 | struct udev_enumerate *e; |
| 2582 | struct udev_list_entry *entry; |
| 2583 | const char *path, *device_seat, *id; |
| 2584 | struct udev_device *device, *drm_device, *pci; |
| 2585 | |
| 2586 | e = udev_enumerate_new(ec->udev); |
| 2587 | udev_enumerate_add_match_subsystem(e, "drm"); |
| 2588 | udev_enumerate_add_match_sysname(e, "card[0-9]*"); |
| 2589 | |
| 2590 | udev_enumerate_scan_devices(e); |
| 2591 | drm_device = NULL; |
| 2592 | udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { |
| 2593 | path = udev_list_entry_get_name(entry); |
| 2594 | device = udev_device_new_from_syspath(ec->udev, path); |
| 2595 | if (!device) |
| 2596 | continue; |
| 2597 | device_seat = udev_device_get_property_value(device, "ID_SEAT"); |
| 2598 | if (!device_seat) |
| 2599 | device_seat = default_seat; |
| 2600 | if (strcmp(device_seat, seat)) { |
| 2601 | udev_device_unref(device); |
| 2602 | continue; |
| 2603 | } |
| 2604 | |
| 2605 | pci = udev_device_get_parent_with_subsystem_devtype(device, |
| 2606 | "pci", NULL); |
| 2607 | if (pci) { |
| 2608 | id = udev_device_get_sysattr_value(pci, "boot_vga"); |
| 2609 | if (id && !strcmp(id, "1")) { |
| 2610 | if (drm_device) |
| 2611 | udev_device_unref(drm_device); |
| 2612 | drm_device = device; |
| 2613 | break; |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | if (!drm_device) |
| 2618 | drm_device = device; |
| 2619 | else |
| 2620 | udev_device_unref(device); |
| 2621 | } |
| 2622 | |
| 2623 | udev_enumerate_unref(e); |
| 2624 | return drm_device; |
| 2625 | } |
| 2626 | |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2627 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2628 | planes_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2629 | { |
| 2630 | struct drm_compositor *c = data; |
| 2631 | |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2632 | switch (key) { |
| 2633 | case KEY_C: |
| 2634 | c->cursors_are_broken ^= 1; |
| 2635 | break; |
| 2636 | case KEY_V: |
| 2637 | c->sprites_are_broken ^= 1; |
| 2638 | break; |
| 2639 | case KEY_O: |
| 2640 | c->sprites_hidden ^= 1; |
| 2641 | break; |
| 2642 | default: |
| 2643 | break; |
| 2644 | } |
Ander Conselvan de Oliveira | 180f42a | 2012-11-21 15:11:37 +0200 | [diff] [blame] | 2645 | } |
| 2646 | |
Kristian Høgsberg | 0eac34a | 2013-08-30 14:28:22 -0700 | [diff] [blame] | 2647 | #ifdef BUILD_VAAPI_RECORDER |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2648 | static void |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2649 | recorder_destroy(struct drm_output *output) |
| 2650 | { |
| 2651 | vaapi_recorder_destroy(output->recorder); |
| 2652 | output->recorder = NULL; |
| 2653 | |
| 2654 | output->base.disable_planes--; |
| 2655 | |
| 2656 | wl_list_remove(&output->recorder_frame_listener.link); |
| 2657 | weston_log("[libva recorder] done\n"); |
| 2658 | } |
| 2659 | |
| 2660 | static void |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2661 | recorder_frame_notify(struct wl_listener *listener, void *data) |
| 2662 | { |
| 2663 | struct drm_output *output; |
| 2664 | struct drm_compositor *c; |
| 2665 | int fd, ret; |
| 2666 | |
| 2667 | output = container_of(listener, struct drm_output, |
| 2668 | recorder_frame_listener); |
| 2669 | c = (struct drm_compositor *) output->base.compositor; |
| 2670 | |
| 2671 | if (!output->recorder) |
| 2672 | return; |
| 2673 | |
| 2674 | ret = drmPrimeHandleToFD(c->drm.fd, output->current->handle, |
| 2675 | DRM_CLOEXEC, &fd); |
| 2676 | if (ret) { |
| 2677 | weston_log("[libva recorder] " |
| 2678 | "failed to create prime fd for front buffer\n"); |
| 2679 | return; |
| 2680 | } |
| 2681 | |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2682 | ret = vaapi_recorder_frame(output->recorder, fd, |
| 2683 | output->current->stride); |
| 2684 | if (ret < 0) { |
| 2685 | weston_log("[libva recorder] aborted: %m\n"); |
| 2686 | recorder_destroy(output); |
| 2687 | } |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | static void * |
| 2691 | create_recorder(struct drm_compositor *c, int width, int height, |
| 2692 | const char *filename) |
| 2693 | { |
| 2694 | int fd; |
| 2695 | drm_magic_t magic; |
| 2696 | |
| 2697 | fd = open(c->drm.filename, O_RDWR | O_CLOEXEC); |
| 2698 | if (fd < 0) |
| 2699 | return NULL; |
| 2700 | |
| 2701 | drmGetMagic(fd, &magic); |
| 2702 | drmAuthMagic(c->drm.fd, magic); |
| 2703 | |
| 2704 | return vaapi_recorder_create(fd, width, height, filename); |
| 2705 | } |
| 2706 | |
| 2707 | static void |
| 2708 | recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 2709 | void *data) |
| 2710 | { |
| 2711 | struct drm_compositor *c = data; |
| 2712 | struct drm_output *output; |
| 2713 | int width, height; |
| 2714 | |
| 2715 | output = container_of(c->base.output_list.next, |
| 2716 | struct drm_output, base.link); |
| 2717 | |
| 2718 | if (!output->recorder) { |
Ander Conselvan de Oliveira | 2ef1cd1 | 2014-05-06 16:49:06 +0300 | [diff] [blame] | 2719 | if (output->format != GBM_FORMAT_XRGB8888) { |
| 2720 | weston_log("failed to start vaapi recorder: " |
| 2721 | "output format not supported\n"); |
| 2722 | return; |
| 2723 | } |
| 2724 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 2725 | width = output->base.current_mode->width; |
| 2726 | height = output->base.current_mode->height; |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2727 | |
| 2728 | output->recorder = |
| 2729 | create_recorder(c, width, height, "capture.h264"); |
| 2730 | if (!output->recorder) { |
| 2731 | weston_log("failed to create vaapi recorder\n"); |
| 2732 | return; |
| 2733 | } |
| 2734 | |
| 2735 | output->base.disable_planes++; |
| 2736 | |
| 2737 | output->recorder_frame_listener.notify = recorder_frame_notify; |
| 2738 | wl_signal_add(&output->base.frame_signal, |
| 2739 | &output->recorder_frame_listener); |
| 2740 | |
| 2741 | weston_output_schedule_repaint(&output->base); |
| 2742 | |
| 2743 | weston_log("[libva recorder] initialized\n"); |
| 2744 | } else { |
Ander Conselvan de Oliveira | 2d13fde | 2014-05-09 15:57:38 +0300 | [diff] [blame] | 2745 | recorder_destroy(output); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2746 | } |
| 2747 | } |
| 2748 | #else |
| 2749 | static void |
| 2750 | recorder_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 2751 | void *data) |
| 2752 | { |
| 2753 | weston_log("Compiled without libva support\n"); |
| 2754 | } |
| 2755 | #endif |
| 2756 | |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 2757 | static void |
| 2758 | switch_to_gl_renderer(struct drm_compositor *c) |
| 2759 | { |
| 2760 | struct drm_output *output; |
| 2761 | |
| 2762 | if (!c->use_pixman) |
| 2763 | return; |
| 2764 | |
| 2765 | weston_log("Switching to GL renderer\n"); |
| 2766 | |
| 2767 | c->gbm = create_gbm_device(c->drm.fd); |
| 2768 | if (!c->gbm) { |
| 2769 | weston_log("Failed to create gbm device. " |
| 2770 | "Aborting renderer switch\n"); |
| 2771 | return; |
| 2772 | } |
| 2773 | |
| 2774 | wl_list_for_each(output, &c->base.output_list, base.link) |
| 2775 | pixman_renderer_output_destroy(&output->base); |
| 2776 | |
| 2777 | c->base.renderer->destroy(&c->base); |
| 2778 | |
| 2779 | if (drm_compositor_create_gl_renderer(c) < 0) { |
| 2780 | gbm_device_destroy(c->gbm); |
| 2781 | weston_log("Failed to create GL renderer. Quitting.\n"); |
| 2782 | /* FIXME: we need a function to shutdown cleanly */ |
| 2783 | assert(0); |
| 2784 | } |
| 2785 | |
| 2786 | wl_list_for_each(output, &c->base.output_list, base.link) |
| 2787 | drm_output_init_egl(output, c); |
| 2788 | |
| 2789 | c->use_pixman = 0; |
| 2790 | } |
| 2791 | |
| 2792 | static void |
| 2793 | renderer_switch_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 2794 | void *data) |
| 2795 | { |
| 2796 | struct drm_compositor *c = (struct drm_compositor *) seat->compositor; |
| 2797 | |
| 2798 | switch_to_gl_renderer(c); |
| 2799 | } |
| 2800 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2801 | static struct weston_compositor * |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2802 | drm_compositor_create(struct wl_display *display, |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2803 | struct drm_parameters *param, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2804 | int *argc, char *argv[], |
| 2805 | struct weston_config *config) |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2806 | { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2807 | struct drm_compositor *ec; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2808 | struct weston_config_section *section; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2809 | struct udev_device *drm_device; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2810 | struct wl_event_loop *loop; |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2811 | const char *path; |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2812 | uint32_t key; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2813 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2814 | weston_log("initializing drm backend\n"); |
| 2815 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2816 | ec = zalloc(sizeof *ec); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2817 | if (ec == NULL) |
| 2818 | return NULL; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2819 | |
Kristian Høgsberg | de37d67 | 2012-11-02 10:14:40 -0400 | [diff] [blame] | 2820 | /* KMS support for sprites is not complete yet, so disable the |
| 2821 | * functionality for now. */ |
| 2822 | ec->sprites_are_broken = 1; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2823 | |
| 2824 | section = weston_config_get_section(config, "core", NULL, NULL); |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 2825 | if (get_gbm_format_from_section(section, |
| 2826 | GBM_FORMAT_XRGB8888, |
| 2827 | &ec->format) == -1) |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2828 | goto err_base; |
Kristian Høgsberg | 8e6f376 | 2013-10-16 16:31:42 -0700 | [diff] [blame] | 2829 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2830 | ec->use_pixman = param->use_pixman; |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2831 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2832 | if (weston_compositor_init(&ec->base, display, argc, argv, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2833 | config) < 0) { |
Scott Moreau | 8eb6748 | 2013-02-23 12:04:56 -0700 | [diff] [blame] | 2834 | weston_log("%s failed\n", __func__); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2835 | goto err_base; |
| 2836 | } |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2837 | |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 2838 | /* Check if we run drm-backend using weston-launch */ |
David Herrmann | cc5b2ed | 2013-10-22 00:28:09 +0200 | [diff] [blame] | 2839 | ec->base.launcher = weston_launcher_connect(&ec->base, param->tty, |
David Herrmann | 2ecb84a | 2014-12-30 14:33:22 +0100 | [diff] [blame] | 2840 | param->seat_id, true); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2841 | if (ec->base.launcher == NULL) { |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 2842 | weston_log("fatal: drm backend should be run " |
Kristian Høgsberg | b76237e | 2013-04-04 21:36:20 -0400 | [diff] [blame] | 2843 | "using weston-launch binary or as root\n"); |
Rafal Mielniczuk | 32069c0 | 2013-03-27 18:39:28 +0100 | [diff] [blame] | 2844 | goto err_compositor; |
| 2845 | } |
| 2846 | |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2847 | ec->udev = udev_new(); |
| 2848 | if (ec->udev == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2849 | weston_log("failed to initialize udev context\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2850 | goto err_launcher; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2851 | } |
| 2852 | |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 2853 | ec->base.wl_display = display; |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 2854 | ec->session_listener.notify = session_notify; |
| 2855 | wl_signal_add(&ec->base.session_signal, &ec->session_listener); |
Kristian Høgsberg | c5b9ddb | 2012-01-15 14:29:09 -0500 | [diff] [blame] | 2856 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2857 | drm_device = find_primary_gpu(ec, param->seat_id); |
Kristian Høgsberg | 8d51f14 | 2011-07-15 21:28:38 -0400 | [diff] [blame] | 2858 | if (drm_device == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2859 | weston_log("no drm device found\n"); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2860 | goto err_udev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2861 | } |
David Herrmann | 0af066f | 2012-10-29 19:21:16 +0100 | [diff] [blame] | 2862 | path = udev_device_get_syspath(drm_device); |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2863 | |
Ander Conselvan de Oliveira | 2292917 | 2013-01-25 15:13:02 +0200 | [diff] [blame] | 2864 | if (init_drm(ec, drm_device) < 0) { |
| 2865 | weston_log("failed to initialize kms\n"); |
| 2866 | goto err_udev_dev; |
| 2867 | } |
| 2868 | |
Ander Conselvan de Oliveira | 5fb4414 | 2013-01-25 15:13:05 +0200 | [diff] [blame] | 2869 | if (ec->use_pixman) { |
| 2870 | if (init_pixman(ec) < 0) { |
| 2871 | weston_log("failed to initialize pixman renderer\n"); |
| 2872 | goto err_udev_dev; |
| 2873 | } |
| 2874 | } else { |
| 2875 | if (init_egl(ec) < 0) { |
| 2876 | weston_log("failed to initialize egl\n"); |
| 2877 | goto err_udev_dev; |
| 2878 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2879 | } |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 2880 | |
| 2881 | ec->base.destroy = drm_destroy; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2882 | ec->base.restore = drm_restore; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 2883 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2884 | ec->prev_state = WESTON_COMPOSITOR_ACTIVE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2885 | |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2886 | for (key = KEY_F1; key < KEY_F9; key++) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2887 | weston_compositor_add_key_binding(&ec->base, key, |
| 2888 | MODIFIER_CTRL | MODIFIER_ALT, |
| 2889 | switch_vt_binding, ec); |
Kristian Høgsberg | 5d1c0c5 | 2012-04-10 00:11:50 -0400 | [diff] [blame] | 2890 | |
Jesse Barnes | 58ef379 | 2012-02-23 09:45:49 -0500 | [diff] [blame] | 2891 | wl_list_init(&ec->sprite_list); |
| 2892 | create_sprites(ec); |
| 2893 | |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 2894 | if (udev_input_init(&ec->input, |
| 2895 | &ec->base, ec->udev, param->seat_id) < 0) { |
| 2896 | weston_log("failed to create input devices\n"); |
| 2897 | goto err_sprite; |
| 2898 | } |
| 2899 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2900 | if (create_outputs(ec, param->connector, drm_device) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2901 | weston_log("failed to create output for %s\n", path); |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 2902 | goto err_udev_input; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2903 | } |
| 2904 | |
Jason Ekstrand | 9fc7151 | 2014-04-02 19:53:46 -0500 | [diff] [blame] | 2905 | /* A this point we have some idea of whether or not we have a working |
| 2906 | * cursor plane. */ |
| 2907 | if (!ec->cursors_are_broken) |
| 2908 | ec->base.capabilities |= WESTON_CAP_CURSOR_PLANE; |
| 2909 | |
Benjamin Franzke | 02dee2c | 2011-10-07 08:27:26 +0200 | [diff] [blame] | 2910 | path = NULL; |
| 2911 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2912 | loop = wl_display_get_event_loop(ec->base.wl_display); |
| 2913 | ec->drm_source = |
Benjamin Franzke | 2af7f10 | 2011-03-02 11:14:59 +0100 | [diff] [blame] | 2914 | wl_event_loop_add_fd(loop, ec->drm.fd, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2915 | WL_EVENT_READABLE, on_drm_input, ec); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2916 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2917 | ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev"); |
| 2918 | if (ec->udev_monitor == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2919 | weston_log("failed to intialize udev monitor\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2920 | goto err_drm_source; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2921 | } |
| 2922 | udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor, |
| 2923 | "drm", NULL); |
| 2924 | ec->udev_drm_source = |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2925 | wl_event_loop_add_fd(loop, |
| 2926 | udev_monitor_get_fd(ec->udev_monitor), |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2927 | WL_EVENT_READABLE, udev_drm_event, ec); |
| 2928 | |
| 2929 | if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2930 | weston_log("failed to enable udev-monitor receiving\n"); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2931 | goto err_udev_monitor; |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2932 | } |
| 2933 | |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2934 | udev_device_unref(drm_device); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2935 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 2936 | weston_compositor_add_debug_binding(&ec->base, KEY_O, |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2937 | planes_binding, ec); |
Ander Conselvan de Oliveira | 180f42a | 2012-11-21 15:11:37 +0200 | [diff] [blame] | 2938 | weston_compositor_add_debug_binding(&ec->base, KEY_C, |
Ander Conselvan de Oliveira | 7e918da | 2012-11-22 15:56:59 +0200 | [diff] [blame] | 2939 | planes_binding, ec); |
| 2940 | weston_compositor_add_debug_binding(&ec->base, KEY_V, |
| 2941 | planes_binding, ec); |
Ander Conselvan de Oliveira | 6aae4d3 | 2013-08-23 17:15:48 +0300 | [diff] [blame] | 2942 | weston_compositor_add_debug_binding(&ec->base, KEY_Q, |
| 2943 | recorder_binding, ec); |
Ander Conselvan de Oliveira | 6579681 | 2013-11-19 15:22:04 +0200 | [diff] [blame] | 2944 | weston_compositor_add_debug_binding(&ec->base, KEY_W, |
| 2945 | renderer_switch_binding, ec); |
Ander Conselvan de Oliveira | da1c908 | 2012-10-31 17:55:46 +0200 | [diff] [blame] | 2946 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2947 | return &ec->base; |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2948 | |
| 2949 | err_udev_monitor: |
| 2950 | wl_event_source_remove(ec->udev_drm_source); |
| 2951 | udev_monitor_unref(ec->udev_monitor); |
| 2952 | err_drm_source: |
| 2953 | wl_event_source_remove(ec->drm_source); |
Ander Conselvan de Oliveira | 4ade0e4 | 2014-04-17 13:08:45 +0300 | [diff] [blame] | 2954 | err_udev_input: |
Rob Bradford | d355b80 | 2013-05-31 18:09:55 +0100 | [diff] [blame] | 2955 | udev_input_destroy(&ec->input); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 2956 | err_sprite: |
Vasily Khoruzhick | 52cfd61 | 2013-01-08 19:09:01 +0300 | [diff] [blame] | 2957 | ec->base.renderer->destroy(&ec->base); |
John Kåre Alsaker | 1b7ad16 | 2012-11-13 19:10:19 +0100 | [diff] [blame] | 2958 | gbm_device_destroy(ec->gbm); |
Kristian Høgsberg | 2bc5e8e | 2012-09-06 20:51:00 -0400 | [diff] [blame] | 2959 | destroy_sprites(ec); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2960 | err_udev_dev: |
| 2961 | udev_device_unref(drm_device); |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 2962 | err_launcher: |
| 2963 | weston_launcher_destroy(ec->base.launcher); |
Daniel Stone | a96b93c | 2012-06-22 14:04:37 +0100 | [diff] [blame] | 2964 | err_udev: |
| 2965 | udev_unref(ec->udev); |
| 2966 | err_compositor: |
| 2967 | weston_compositor_shutdown(&ec->base); |
| 2968 | err_base: |
| 2969 | free(ec); |
| 2970 | return NULL; |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 2971 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2972 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2973 | WL_EXPORT struct weston_compositor * |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 2974 | backend_init(struct wl_display *display, int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2975 | struct weston_config *config) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2976 | { |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2977 | struct drm_parameters param = { 0, }; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2978 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2979 | const struct weston_option drm_options[] = { |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2980 | { WESTON_OPTION_INTEGER, "connector", 0, ¶m.connector }, |
| 2981 | { WESTON_OPTION_STRING, "seat", 0, ¶m.seat_id }, |
| 2982 | { WESTON_OPTION_INTEGER, "tty", 0, ¶m.tty }, |
Kristian Høgsberg | 061c425 | 2012-06-28 11:28:15 -0400 | [diff] [blame] | 2983 | { WESTON_OPTION_BOOLEAN, "current-mode", 0, &option_current_mode }, |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2984 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, ¶m.use_pixman }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2985 | }; |
Benjamin Franzke | 117483d | 2011-08-30 11:38:26 +0200 | [diff] [blame] | 2986 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2987 | param.seat_id = default_seat; |
| 2988 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 2989 | parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2990 | |
Kristian Høgsberg | d8e9833 | 2013-10-16 16:15:11 -0700 | [diff] [blame] | 2991 | return drm_compositor_create(display, ¶m, argc, argv, config); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2992 | } |