Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/stat.h> |
| 30 | #include <unistd.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <xcb/xcb.h> |
| 33 | #include <xcb/dri3.h> |
| 34 | #include <xcb/present.h> |
| 35 | |
| 36 | #include "kmd/winsys.h" |
| 37 | #include "dev.h" |
| 38 | #include "fence.h" |
| 39 | #include "gpu.h" |
| 40 | #include "img.h" |
| 41 | #include "mem.h" |
| 42 | #include "queue.h" |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 43 | #include "wsi.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 44 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 45 | struct intel_wsi_x11_window { |
| 46 | xcb_window_t window_id; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 47 | |
| 48 | xcb_present_event_t present_special_event_id; |
| 49 | xcb_special_event_t *present_special_event; |
| 50 | |
| 51 | struct { |
| 52 | uint32_t serial; |
| 53 | } local; |
| 54 | |
| 55 | struct { |
| 56 | uint32_t serial; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 57 | uint64_t msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 58 | } remote; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 59 | |
| 60 | struct intel_wsi_x11_window *next; |
| 61 | }; |
| 62 | |
| 63 | struct intel_wsi_x11 { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 64 | struct intel_handle handle; |
| 65 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 66 | xcb_connection_t *c; |
| 67 | xcb_window_t root; |
| 68 | xcb_randr_provider_t provider; |
| 69 | int root_depth; |
| 70 | |
| 71 | int dri3_major, dri3_minor; |
| 72 | int present_major, present_minor; |
| 73 | |
| 74 | int fd; |
| 75 | |
| 76 | struct intel_wsi_x11_window *windows; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 77 | }; |
| 78 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 79 | struct intel_x11_img_data { |
| 80 | struct intel_mem *mem; |
| 81 | int prime_fd; |
| 82 | uint32_t pixmap; |
| 83 | }; |
| 84 | |
| 85 | struct intel_x11_fence_data { |
| 86 | struct intel_wsi_x11 *x11; |
| 87 | struct intel_wsi_x11_window *win; |
| 88 | uint32_t serial; |
| 89 | }; |
| 90 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 91 | /** |
| 92 | * Return true if DRI3 and Present are supported by the server. |
| 93 | */ |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 94 | static bool wsi_x11_has_dri3_and_present(struct intel_wsi_x11 *x11) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 95 | { |
| 96 | const xcb_query_extension_reply_t *ext; |
| 97 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 98 | xcb_prefetch_extension_data(x11->c, &xcb_dri3_id); |
| 99 | xcb_prefetch_extension_data(x11->c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 100 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 101 | ext = xcb_get_extension_data(x11->c, &xcb_dri3_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 102 | if (!ext || !ext->present) |
| 103 | return false; |
| 104 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 105 | ext = xcb_get_extension_data(x11->c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 106 | if (!ext || !ext->present) |
| 107 | return false; |
| 108 | |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Return the depth of the root window. |
| 114 | */ |
| 115 | static int wsi_x11_get_root_depth(struct intel_wsi_x11 *x11) |
| 116 | { |
| 117 | const xcb_setup_t *setup; |
| 118 | xcb_screen_iterator_t iter; |
| 119 | |
| 120 | setup = xcb_get_setup(x11->c); |
| 121 | |
| 122 | iter = xcb_setup_roots_iterator(setup); |
| 123 | for (; iter.rem; xcb_screen_next(&iter)) { |
| 124 | if (iter.data->root == x11->root) |
| 125 | return iter.data->root_depth; |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /** |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 132 | * Send DRI3QueryVersion and PresentQueryVersion to query extension versions. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 133 | */ |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 134 | static bool wsi_x11_dri3_and_present_query_version(struct intel_wsi_x11 *x11) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 135 | { |
| 136 | xcb_dri3_query_version_cookie_t dri3_cookie; |
| 137 | xcb_dri3_query_version_reply_t *dri3_reply; |
| 138 | xcb_present_query_version_cookie_t present_cookie; |
| 139 | xcb_present_query_version_reply_t *present_reply; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 140 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 141 | dri3_cookie = xcb_dri3_query_version(x11->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 142 | XCB_DRI3_MAJOR_VERSION, XCB_DRI3_MINOR_VERSION); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 143 | present_cookie = xcb_present_query_version(x11->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 144 | XCB_PRESENT_MAJOR_VERSION, XCB_PRESENT_MINOR_VERSION); |
| 145 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 146 | dri3_reply = xcb_dri3_query_version_reply(x11->c, dri3_cookie, NULL); |
| 147 | if (!dri3_reply) |
| 148 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 149 | |
| 150 | x11->dri3_major = dri3_reply->major_version; |
| 151 | x11->dri3_minor = dri3_reply->minor_version; |
| 152 | free(dri3_reply); |
| 153 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 154 | present_reply = xcb_present_query_version_reply(x11->c, present_cookie, NULL); |
| 155 | if (!present_reply) |
| 156 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 157 | |
| 158 | x11->present_major = present_reply->major_version; |
| 159 | x11->present_minor = present_reply->minor_version; |
| 160 | free(present_reply); |
| 161 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 162 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Return true if x11->fd points to the primary or render node of the GPU. |
| 167 | */ |
| 168 | static bool wsi_x11_uses_gpu(const struct intel_wsi_x11 *x11, |
| 169 | const struct intel_gpu *gpu) |
| 170 | { |
| 171 | struct stat x11_stat, gpu_stat; |
| 172 | |
| 173 | if (fstat(x11->fd, &x11_stat)) |
| 174 | return false; |
| 175 | |
| 176 | /* is it the primary node? */ |
| 177 | if (!stat(gpu->primary_node, &gpu_stat) && |
| 178 | !memcmp(&x11_stat, &gpu_stat, sizeof(x11_stat))) |
| 179 | return true; |
| 180 | |
| 181 | /* is it the render node? */ |
| 182 | if (gpu->render_node && !stat(gpu->render_node, &gpu_stat) && |
| 183 | !memcmp(&x11_stat, &gpu_stat, sizeof(x11_stat))) |
| 184 | return true; |
| 185 | |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Send a DRI3Open to get the server GPU fd. |
| 191 | */ |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 192 | static bool wsi_x11_dri3_open(struct intel_wsi_x11 *x11) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 193 | { |
| 194 | xcb_dri3_open_cookie_t cookie; |
| 195 | xcb_dri3_open_reply_t *reply; |
| 196 | int fd; |
| 197 | |
| 198 | cookie = xcb_dri3_open(x11->c, x11->root, x11->provider); |
| 199 | reply = xcb_dri3_open_reply(x11->c, cookie, NULL); |
| 200 | if (!reply) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 201 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 202 | |
| 203 | fd = (reply->nfd == 1) ? xcb_dri3_open_reply_fds(x11->c, reply)[0] : -1; |
| 204 | free(reply); |
| 205 | |
| 206 | if (fd < 0) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 207 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 208 | |
| 209 | fcntl(fd, F_SETFD, FD_CLOEXEC); |
| 210 | x11->fd = fd; |
| 211 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 212 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Send a DRI3PixmapFromBuffer to create a Pixmap from \p mem for \p img. |
| 217 | */ |
| 218 | static XGL_RESULT wsi_x11_dri3_pixmap_from_buffer(struct intel_wsi_x11 *x11, |
| 219 | struct intel_dev *dev, |
| 220 | struct intel_img *img, |
| 221 | struct intel_mem *mem) |
| 222 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 223 | struct intel_x11_img_data *data = |
| 224 | (struct intel_x11_img_data *) img->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 225 | struct intel_winsys_handle export; |
Chia-I Wu | d1eb90c | 2015-03-07 06:01:45 +0800 | [diff] [blame] | 226 | enum intel_tiling_mode tiling; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 227 | xcb_pixmap_t pixmap; |
| 228 | |
Chia-I Wu | d1eb90c | 2015-03-07 06:01:45 +0800 | [diff] [blame] | 229 | switch (img->layout.tiling) { |
| 230 | case GEN6_TILING_X: |
| 231 | tiling = INTEL_TILING_X; |
| 232 | break; |
| 233 | case GEN6_TILING_Y: |
| 234 | tiling = INTEL_TILING_Y; |
| 235 | break; |
| 236 | default: |
| 237 | assert(img->layout.tiling == GEN6_TILING_NONE); |
| 238 | tiling = INTEL_TILING_NONE; |
| 239 | break; |
| 240 | } |
| 241 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 242 | /* get prime fd of the bo first */ |
Chia-I Wu | d1eb90c | 2015-03-07 06:01:45 +0800 | [diff] [blame] | 243 | if (intel_bo_set_tiling(mem->bo, tiling, img->layout.bo_stride)) |
Chia-I Wu | 3d0f59c | 2015-03-07 06:00:46 +0800 | [diff] [blame] | 244 | return XGL_ERROR_UNKNOWN; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 245 | export.type = INTEL_WINSYS_HANDLE_FD; |
Chia-I Wu | d1eb90c | 2015-03-07 06:01:45 +0800 | [diff] [blame] | 246 | if (intel_winsys_export_handle(dev->winsys, mem->bo, tiling, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 247 | img->layout.bo_stride, img->layout.bo_height, &export)) |
| 248 | return XGL_ERROR_UNKNOWN; |
| 249 | |
| 250 | pixmap = xcb_generate_id(x11->c); |
| 251 | |
| 252 | /* create a pixmap from the prime fd */ |
| 253 | xcb_dri3_pixmap_from_buffer(x11->c, pixmap, |
| 254 | x11->root, img->total_size, |
| 255 | img->layout.width0, img->layout.height0, |
| 256 | img->layout.bo_stride, x11->root_depth, |
| 257 | img->layout.block_size * 8, export.handle); |
| 258 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 259 | data->mem = mem; |
| 260 | data->prime_fd = export.handle; |
| 261 | data->pixmap = pixmap; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 262 | |
| 263 | return XGL_SUCCESS; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Send a PresentSelectInput to select interested events. |
| 268 | */ |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 269 | static XGL_RESULT wsi_x11_present_select_input(struct intel_wsi_x11 *x11, |
| 270 | struct intel_wsi_x11_window *win) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 271 | { |
| 272 | xcb_void_cookie_t cookie; |
| 273 | xcb_generic_error_t *error; |
| 274 | |
| 275 | /* create the event queue */ |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 276 | win->present_special_event_id = xcb_generate_id(x11->c); |
| 277 | win->present_special_event = xcb_register_for_special_xge(x11->c, |
| 278 | &xcb_present_id, win->present_special_event_id, NULL); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 279 | |
| 280 | cookie = xcb_present_select_input_checked(x11->c, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 281 | win->present_special_event_id, win->window_id, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 282 | XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY); |
| 283 | |
| 284 | error = xcb_request_check(x11->c, cookie); |
| 285 | if (error) { |
| 286 | free(error); |
| 287 | return XGL_ERROR_UNKNOWN; |
| 288 | } |
| 289 | |
| 290 | return XGL_SUCCESS; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Send a PresentPixmap. |
| 295 | */ |
| 296 | static XGL_RESULT wsi_x11_present_pixmap(struct intel_wsi_x11 *x11, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 297 | struct intel_wsi_x11_window *win, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 298 | const XGL_WSI_X11_PRESENT_INFO *info) |
| 299 | { |
| 300 | struct intel_img *img = intel_img(info->srcImage); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 301 | struct intel_x11_img_data *data = |
| 302 | (struct intel_x11_img_data *) img->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 303 | uint32_t options = XCB_PRESENT_OPTION_NONE; |
| 304 | xcb_void_cookie_t cookie; |
| 305 | xcb_generic_error_t *err; |
| 306 | |
| 307 | if (info->async) |
| 308 | options |= XCB_PRESENT_OPTION_ASYNC; |
| 309 | if (!info->flip) |
| 310 | options |= XCB_PRESENT_OPTION_COPY; |
| 311 | |
| 312 | cookie = xcb_present_pixmap(x11->c, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 313 | win->window_id, |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 314 | data->pixmap, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 315 | ++win->local.serial, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 316 | 0, /* valid-area */ |
| 317 | 0, /* update-area */ |
| 318 | 0, /* x-off */ |
| 319 | 0, /* y-off */ |
| 320 | info->crtc, |
| 321 | 0, /* wait-fence */ |
| 322 | 0, /* idle-fence */ |
| 323 | options, |
| 324 | info->target_msc, |
| 325 | info->divisor, |
| 326 | info->remainder, |
| 327 | 0, NULL); |
| 328 | |
| 329 | err = xcb_request_check(x11->c, cookie); |
| 330 | if (err) { |
| 331 | free(err); |
| 332 | return XGL_ERROR_UNKNOWN; |
| 333 | } |
| 334 | |
| 335 | return XGL_SUCCESS; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Send a PresentNotifyMSC for the current MSC. |
| 340 | */ |
| 341 | static void wsi_x11_present_notify_msc(struct intel_wsi_x11 *x11, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 342 | struct intel_wsi_x11_window *win) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 343 | { |
| 344 | /* cannot specify CRTC? */ |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 345 | xcb_present_notify_msc(x11->c, win->window_id, ++win->local.serial, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 346 | 0, 0, 0); |
| 347 | |
| 348 | xcb_flush(x11->c); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Handle a Present event. |
| 353 | */ |
| 354 | static void wsi_x11_present_event(struct intel_wsi_x11 *x11, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 355 | struct intel_wsi_x11_window *win, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 356 | const xcb_present_generic_event_t *ev) |
| 357 | { |
| 358 | union { |
| 359 | const xcb_present_generic_event_t *ev; |
| 360 | const xcb_present_complete_notify_event_t *complete; |
| 361 | } u = { .ev = ev }; |
| 362 | |
| 363 | switch (u.ev->evtype) { |
| 364 | case XCB_PRESENT_COMPLETE_NOTIFY: |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 365 | win->remote.serial = u.complete->serial; |
| 366 | win->remote.msc = u.complete->msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 367 | break; |
| 368 | default: |
| 369 | break; |
| 370 | } |
| 371 | } |
| 372 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 373 | static struct intel_wsi_x11_window *wsi_x11_create_window(struct intel_wsi_x11 *x11, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 374 | xcb_window_t win_id) |
| 375 | { |
| 376 | struct intel_wsi_x11_window *win; |
| 377 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 378 | win = intel_alloc(x11, sizeof(*win), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 379 | if (!win) |
| 380 | return NULL; |
| 381 | |
| 382 | memset(win, 0, sizeof(*win)); |
| 383 | |
| 384 | win->window_id = win_id; |
| 385 | |
| 386 | if (wsi_x11_present_select_input(x11, win) != XGL_SUCCESS) { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 387 | intel_free(x11, win); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 388 | return NULL; |
| 389 | } |
| 390 | |
| 391 | return win; |
| 392 | } |
| 393 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 394 | static void wsi_x11_destroy_window(struct intel_wsi_x11 *x11, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 395 | struct intel_wsi_x11_window *win) |
| 396 | { |
| 397 | if (win->present_special_event) |
| 398 | xcb_unregister_for_special_event(x11->c, win->present_special_event); |
| 399 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 400 | intel_free(x11, win); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 401 | } |
| 402 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 403 | static struct intel_wsi_x11_window *wsi_x11_lookup_window(struct intel_wsi_x11 *x11, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 404 | xcb_window_t win_id) |
| 405 | { |
| 406 | struct intel_wsi_x11_window *win = x11->windows; |
| 407 | |
| 408 | while (win) { |
| 409 | if (win->window_id == win_id) |
| 410 | break; |
| 411 | win = win->next; |
| 412 | } |
| 413 | |
| 414 | /* lookup failed */ |
| 415 | if (!win) { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 416 | win = wsi_x11_create_window(x11, win_id); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 417 | if (win) { |
| 418 | win->next = x11->windows; |
| 419 | x11->windows = win; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | return win; |
| 424 | } |
| 425 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 426 | static XGL_RESULT wsi_x11_wait_window(struct intel_wsi_x11 *x11, |
| 427 | struct intel_wsi_x11_window *win, |
| 428 | uint32_t serial, int64_t timeout) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 429 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 430 | const bool wait = (timeout != 0); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 431 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 432 | while (win->remote.serial < serial) { |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 433 | xcb_present_generic_event_t *ev; |
| 434 | |
| 435 | if (wait) { |
| 436 | ev = (xcb_present_generic_event_t *) |
| 437 | xcb_wait_for_special_event(x11->c, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 438 | win->present_special_event); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 439 | if (!ev) |
| 440 | return XGL_ERROR_UNKNOWN; |
| 441 | } else { |
| 442 | ev = (xcb_present_generic_event_t *) |
| 443 | xcb_poll_for_special_event(x11->c, |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 444 | win->present_special_event); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 445 | if (!ev) |
| 446 | return XGL_NOT_READY; |
| 447 | } |
| 448 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 449 | wsi_x11_present_event(x11, win, ev); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 450 | |
| 451 | free(ev); |
| 452 | } |
| 453 | |
| 454 | return XGL_SUCCESS; |
| 455 | } |
| 456 | |
Chia-I Wu | c505a6f | 2014-11-13 00:04:01 +0800 | [diff] [blame] | 457 | static bool wsi_x11_is_format_presentable(struct intel_wsi_x11 *x11, |
| 458 | struct intel_dev *dev, |
| 459 | XGL_FORMAT format) |
| 460 | { |
| 461 | /* this is what DDX expects */ |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 462 | switch (format) { |
| 463 | case XGL_FMT_B5G6R5_UNORM: |
| 464 | case XGL_FMT_B8G8R8A8_UNORM: |
| 465 | case XGL_FMT_B8G8R8A8_SRGB: |
| 466 | return true; |
Chia-I Wu | c505a6f | 2014-11-13 00:04:01 +0800 | [diff] [blame] | 467 | default: |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 468 | return false; |
Chia-I Wu | c505a6f | 2014-11-13 00:04:01 +0800 | [diff] [blame] | 469 | } |
Chia-I Wu | c505a6f | 2014-11-13 00:04:01 +0800 | [diff] [blame] | 470 | } |
| 471 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 472 | /** |
| 473 | * Create a presentable image. |
| 474 | */ |
| 475 | static XGL_RESULT wsi_x11_img_create(struct intel_wsi_x11 *x11, |
| 476 | struct intel_dev *dev, |
| 477 | const XGL_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO *info, |
| 478 | struct intel_img **img_ret) |
| 479 | { |
| 480 | XGL_IMAGE_CREATE_INFO img_info; |
| 481 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 482 | struct intel_img *img; |
| 483 | struct intel_mem *mem; |
| 484 | XGL_RESULT ret; |
| 485 | |
Chia-I Wu | c505a6f | 2014-11-13 00:04:01 +0800 | [diff] [blame] | 486 | if (!wsi_x11_is_format_presentable(x11, dev, info->format)) { |
| 487 | intel_dev_log(dev, XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, |
| 488 | XGL_NULL_HANDLE, 0, 0, "invalid presentable image format"); |
| 489 | return XGL_ERROR_INVALID_VALUE; |
| 490 | } |
| 491 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 492 | /* create image */ |
| 493 | memset(&img_info, 0, sizeof(img_info)); |
| 494 | img_info.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 495 | img_info.imageType = XGL_IMAGE_2D; |
| 496 | img_info.format = info->format; |
| 497 | img_info.extent.width = info->extent.width; |
| 498 | img_info.extent.height = info->extent.height; |
| 499 | img_info.extent.depth = 1; |
| 500 | img_info.mipLevels = 1; |
| 501 | img_info.arraySize = 1; |
| 502 | img_info.samples = 1; |
| 503 | img_info.tiling = XGL_OPTIMAL_TILING; |
| 504 | img_info.usage = info->usage; |
| 505 | img_info.flags = 0; |
| 506 | |
| 507 | ret = intel_img_create(dev, &img_info, true, &img); |
| 508 | if (ret != XGL_SUCCESS) |
| 509 | return ret; |
| 510 | |
| 511 | /* allocate memory */ |
| 512 | memset(&mem_info, 0, sizeof(mem_info)); |
| 513 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 514 | mem_info.allocationSize = img->total_size; |
Jon Ashburn | 542cd09 | 2015-01-20 13:55:32 -0700 | [diff] [blame] | 515 | mem_info.memProps = 0; |
Jon Ashburn | 3276917 | 2015-01-20 15:06:59 -0700 | [diff] [blame] | 516 | mem_info.memType = XGL_MEMORY_TYPE_IMAGE; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 517 | mem_info.memPriority = XGL_MEMORY_PRIORITY_HIGH; |
| 518 | |
| 519 | ret = intel_mem_alloc(dev, &mem_info, &mem); |
| 520 | if (ret != XGL_SUCCESS) { |
| 521 | intel_img_destroy(img); |
| 522 | return ret; |
| 523 | } |
| 524 | |
| 525 | ret = wsi_x11_dri3_pixmap_from_buffer(x11, dev, img, mem); |
| 526 | if (ret != XGL_SUCCESS) { |
| 527 | intel_mem_free(mem); |
| 528 | intel_img_destroy(img); |
| 529 | return ret; |
| 530 | } |
| 531 | |
| 532 | intel_obj_bind_mem(&img->obj, mem, 0); |
| 533 | |
| 534 | *img_ret = img; |
| 535 | |
| 536 | return XGL_SUCCESS; |
| 537 | } |
| 538 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 539 | static void wsi_x11_destroy(struct intel_wsi_x11 *x11) |
| 540 | { |
| 541 | struct intel_wsi_x11_window *win = x11->windows; |
| 542 | |
| 543 | while (win) { |
| 544 | struct intel_wsi_x11_window *next = win->next; |
| 545 | wsi_x11_destroy_window(x11, win); |
| 546 | win = next; |
| 547 | } |
| 548 | |
| 549 | if (x11->fd >= 0) |
| 550 | close(x11->fd); |
| 551 | |
| 552 | intel_free(x11, x11); |
| 553 | } |
| 554 | |
| 555 | static struct intel_wsi_x11 *wsi_x11_create(struct intel_gpu *gpu, |
| 556 | const XGL_WSI_X11_CONNECTION_INFO *info) |
| 557 | { |
| 558 | struct intel_wsi_x11 *x11; |
| 559 | |
| 560 | x11 = intel_alloc(gpu, sizeof(*x11), 0, XGL_SYSTEM_ALLOC_API_OBJECT); |
| 561 | if (!x11) |
| 562 | return NULL; |
| 563 | |
| 564 | memset(x11, 0, sizeof(*x11)); |
| 565 | /* there is no XGL_DBG_OBJECT_WSI_DISPLAY */ |
| 566 | intel_handle_init(&x11->handle, XGL_DBG_OBJECT_UNKNOWN, gpu->handle.icd); |
| 567 | x11->fd = -1; |
| 568 | |
| 569 | x11->c = info->pConnection; |
| 570 | x11->root = info->root; |
| 571 | x11->provider = info->provider; |
| 572 | |
| 573 | x11->root_depth = wsi_x11_get_root_depth(x11); |
| 574 | |
| 575 | if (!wsi_x11_has_dri3_and_present(x11) || |
| 576 | !wsi_x11_dri3_and_present_query_version(x11) || |
| 577 | !wsi_x11_dri3_open(x11) || |
| 578 | !wsi_x11_uses_gpu(x11, gpu)) { |
| 579 | wsi_x11_destroy(x11); |
| 580 | return NULL; |
| 581 | } |
| 582 | |
| 583 | return x11; |
| 584 | } |
| 585 | |
| 586 | static XGL_RESULT intel_wsi_gpu_init(struct intel_gpu *gpu, |
| 587 | const XGL_WSI_X11_CONNECTION_INFO *info) |
| 588 | { |
| 589 | struct intel_wsi_x11 *x11; |
| 590 | |
| 591 | x11 = wsi_x11_create(gpu, info); |
| 592 | if (!x11) |
| 593 | return XGL_ERROR_UNKNOWN; |
| 594 | |
| 595 | gpu->wsi_data = x11; |
| 596 | |
| 597 | return XGL_SUCCESS; |
| 598 | } |
| 599 | |
| 600 | XGL_RESULT intel_wsi_gpu_get_info(struct intel_gpu *gpu, |
| 601 | XGL_PHYSICAL_GPU_INFO_TYPE type, |
| 602 | size_t *size, void *data) |
| 603 | { |
| 604 | return XGL_ERROR_INVALID_VALUE; |
| 605 | } |
| 606 | |
| 607 | void intel_wsi_gpu_cleanup(struct intel_gpu *gpu) |
| 608 | { |
| 609 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) gpu->wsi_data; |
| 610 | |
| 611 | wsi_x11_destroy(x11); |
| 612 | } |
| 613 | |
| 614 | XGL_RESULT intel_wsi_img_init(struct intel_img *img) |
| 615 | { |
| 616 | struct intel_x11_img_data *data; |
| 617 | |
| 618 | data = intel_alloc(img, sizeof(*data), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 619 | if (!data) |
| 620 | return XGL_ERROR_OUT_OF_MEMORY; |
| 621 | |
| 622 | memset(data, 0, sizeof(*data)); |
| 623 | |
| 624 | assert(!img->wsi_data); |
| 625 | img->wsi_data = data; |
| 626 | |
| 627 | return XGL_SUCCESS; |
| 628 | } |
| 629 | |
| 630 | void intel_wsi_img_cleanup(struct intel_img *img) |
| 631 | { |
| 632 | struct intel_x11_img_data *data = |
| 633 | (struct intel_x11_img_data *) img->wsi_data; |
| 634 | |
| 635 | if (data->mem) { |
| 636 | close(data->prime_fd); |
| 637 | intel_mem_free(data->mem); |
| 638 | } |
| 639 | |
| 640 | intel_free(img, img->wsi_data); |
| 641 | } |
| 642 | |
| 643 | XGL_RESULT intel_wsi_fence_init(struct intel_fence *fence) |
| 644 | { |
| 645 | struct intel_x11_fence_data *data; |
| 646 | |
| 647 | data = intel_alloc(fence, sizeof(*data), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 648 | if (!data) |
| 649 | return XGL_ERROR_OUT_OF_MEMORY; |
| 650 | |
| 651 | memset(data, 0, sizeof(*data)); |
| 652 | |
| 653 | assert(!fence->wsi_data); |
| 654 | fence->wsi_data = data; |
| 655 | |
| 656 | return XGL_SUCCESS; |
| 657 | } |
| 658 | |
| 659 | void intel_wsi_fence_cleanup(struct intel_fence *fence) |
| 660 | { |
| 661 | intel_free(fence, fence->wsi_data); |
| 662 | } |
| 663 | |
| 664 | void intel_wsi_fence_copy(struct intel_fence *fence, |
| 665 | const struct intel_fence *src) |
| 666 | { |
| 667 | memcpy(fence->wsi_data, src->wsi_data, |
| 668 | sizeof(struct intel_x11_fence_data)); |
| 669 | } |
| 670 | |
| 671 | XGL_RESULT intel_wsi_fence_wait(struct intel_fence *fence, |
| 672 | int64_t timeout_ns) |
| 673 | { |
| 674 | struct intel_x11_fence_data *data = |
| 675 | (struct intel_x11_fence_data *) fence->wsi_data; |
| 676 | |
| 677 | if (!data->win) |
| 678 | return XGL_SUCCESS; |
| 679 | |
| 680 | return wsi_x11_wait_window(data->x11, |
| 681 | data->win, data->serial, timeout_ns); |
| 682 | } |
| 683 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 684 | ICD_EXPORT XGL_RESULT XGLAPI xglWsiX11AssociateConnection( |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 685 | XGL_PHYSICAL_GPU gpu_, |
| 686 | const XGL_WSI_X11_CONNECTION_INFO* pConnectionInfo) |
| 687 | { |
| 688 | struct intel_gpu *gpu = intel_gpu(gpu_); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 689 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 690 | return intel_wsi_gpu_init(gpu, pConnectionInfo); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 691 | } |
| 692 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 693 | ICD_EXPORT XGL_RESULT XGLAPI xglWsiX11GetMSC( |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 694 | XGL_DEVICE device, |
Chia-I Wu | 6204f34 | 2014-11-07 13:33:45 +0800 | [diff] [blame] | 695 | xcb_window_t window, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 696 | xcb_randr_crtc_t crtc, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 697 | uint64_t * pMsc) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 698 | { |
| 699 | struct intel_dev *dev = intel_dev(device); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 700 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) dev->gpu->wsi_data; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 701 | struct intel_wsi_x11_window *win; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 702 | XGL_RESULT ret; |
| 703 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 704 | win = wsi_x11_lookup_window(x11, window); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 705 | if (!win) |
| 706 | return XGL_ERROR_UNKNOWN; |
| 707 | |
| 708 | wsi_x11_present_notify_msc(x11, win); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 709 | |
| 710 | /* wait for the event */ |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 711 | ret = wsi_x11_wait_window(x11, win, win->local.serial, -1); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 712 | if (ret != XGL_SUCCESS) |
| 713 | return ret; |
| 714 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 715 | *pMsc = win->remote.msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 716 | |
| 717 | return XGL_SUCCESS; |
| 718 | } |
| 719 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 720 | ICD_EXPORT XGL_RESULT XGLAPI xglWsiX11CreatePresentableImage( |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 721 | XGL_DEVICE device, |
| 722 | const XGL_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo, |
| 723 | XGL_IMAGE* pImage, |
| 724 | XGL_GPU_MEMORY* pMem) |
| 725 | { |
| 726 | struct intel_dev *dev = intel_dev(device); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 727 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) dev->gpu->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 728 | struct intel_img *img; |
| 729 | XGL_RESULT ret; |
| 730 | |
| 731 | ret = wsi_x11_img_create(x11, dev, pCreateInfo, &img); |
| 732 | if (ret == XGL_SUCCESS) { |
| 733 | *pImage = (XGL_IMAGE) img; |
| 734 | *pMem = (XGL_GPU_MEMORY) img->obj.mem; |
| 735 | } |
| 736 | |
| 737 | return ret; |
| 738 | } |
| 739 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 740 | ICD_EXPORT XGL_RESULT XGLAPI xglWsiX11QueuePresent( |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 741 | XGL_QUEUE queue_, |
| 742 | const XGL_WSI_X11_PRESENT_INFO* pPresentInfo, |
| 743 | XGL_FENCE fence_) |
| 744 | { |
| 745 | struct intel_queue *queue = intel_queue(queue_); |
| 746 | struct intel_fence *fence = intel_fence(fence_); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 747 | struct intel_wsi_x11 *x11 = |
| 748 | (struct intel_wsi_x11 *) queue->dev->gpu->wsi_data; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 749 | struct intel_wsi_x11_window *win; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 750 | XGL_RESULT ret; |
| 751 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 752 | win = wsi_x11_lookup_window(x11, pPresentInfo->destWindow); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 753 | if (!win) |
| 754 | return XGL_ERROR_UNKNOWN; |
| 755 | |
| 756 | ret = wsi_x11_present_pixmap(x11, win, pPresentInfo); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 757 | if (ret != XGL_SUCCESS) |
| 758 | return ret; |
| 759 | |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 760 | if (fence) { |
| 761 | struct intel_img *img = intel_img(pPresentInfo->srcImage); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 762 | struct intel_x11_fence_data *data = |
| 763 | (struct intel_x11_fence_data *) fence->wsi_data; |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 764 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame^] | 765 | data->x11 = x11; |
| 766 | data->win = win; |
| 767 | data->serial = win->local.serial; |
| 768 | |
| 769 | intel_fence_set_seqno(fence, img->obj.mem->bo); |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 770 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 771 | |
| 772 | return XGL_SUCCESS; |
| 773 | } |