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