2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include <wayland-client.h>
25 #include <wayland-drm-client-protocol.h>
34 #include "wsi_common_wayland.h"
36 #include <util/hash_table.h>
37 #include <util/u_vector.h>
39 #define typed_memcpy(dest, src, count) ({ \
40 static_assert(sizeof(*src) == sizeof(*dest), ""); \
41 memcpy((dest), (src), (count) * sizeof(*(src))); \
44 #define MIN_NUM_IMAGES 2
48 struct wsi_wl_display
{
49 struct wl_display
* display
;
52 struct wsi_wayland
*wsi_wl
;
53 /* Vector of VkFormats supported */
54 struct u_vector formats
;
56 uint32_t capabilities
;
60 struct wsi_interface base
;
62 const VkAllocationCallbacks
*alloc
;
63 VkPhysicalDevice physical_device
;
65 pthread_mutex_t mutex
;
66 /* Hash table of wl_display -> wsi_wl_display mappings */
67 struct hash_table
* displays
;
69 const struct wsi_callbacks
*cbs
;
73 wsi_wl_display_add_vk_format(struct wsi_wl_display
*display
, VkFormat format
)
75 /* Don't add a format that's already in the list */
77 u_vector_foreach(f
, &display
->formats
)
81 /* Don't add formats that aren't renderable. */
82 VkFormatProperties props
;
84 display
->wsi_wl
->cbs
->get_phys_device_format_properties(display
->wsi_wl
->physical_device
,
86 if (!(props
.optimalTilingFeatures
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
))
89 f
= u_vector_add(&display
->formats
);
95 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *name
)
97 fprintf(stderr
, "wl_drm.device(%s)\n", name
);
101 wl_drm_format_for_vk_format(VkFormat vk_format
, bool alpha
)
104 /* TODO: Figure out what all the formats mean and make this table
108 case VK_FORMAT_R4G4B4A4_UNORM
:
109 return alpha
? WL_DRM_FORMAT_ABGR4444
: WL_DRM_FORMAT_XBGR4444
;
110 case VK_FORMAT_R5G6B5_UNORM
:
111 return WL_DRM_FORMAT_BGR565
;
112 case VK_FORMAT_R5G5B5A1_UNORM
:
113 return alpha
? WL_DRM_FORMAT_ABGR1555
: WL_DRM_FORMAT_XBGR1555
;
114 case VK_FORMAT_R8G8B8_UNORM
:
115 return WL_DRM_FORMAT_XBGR8888
;
116 case VK_FORMAT_R8G8B8A8_UNORM
:
117 return alpha
? WL_DRM_FORMAT_ABGR8888
: WL_DRM_FORMAT_XBGR8888
;
118 case VK_FORMAT_R10G10B10A2_UNORM
:
119 return alpha
? WL_DRM_FORMAT_ABGR2101010
: WL_DRM_FORMAT_XBGR2101010
;
120 case VK_FORMAT_B4G4R4A4_UNORM
:
121 return alpha
? WL_DRM_FORMAT_ARGB4444
: WL_DRM_FORMAT_XRGB4444
;
122 case VK_FORMAT_B5G6R5_UNORM
:
123 return WL_DRM_FORMAT_RGB565
;
124 case VK_FORMAT_B5G5R5A1_UNORM
:
125 return alpha
? WL_DRM_FORMAT_XRGB1555
: WL_DRM_FORMAT_XRGB1555
;
127 case VK_FORMAT_B8G8R8_UNORM
:
128 case VK_FORMAT_B8G8R8_SRGB
:
129 return WL_DRM_FORMAT_BGRX8888
;
130 case VK_FORMAT_B8G8R8A8_UNORM
:
131 case VK_FORMAT_B8G8R8A8_SRGB
:
132 return alpha
? WL_DRM_FORMAT_ARGB8888
: WL_DRM_FORMAT_XRGB8888
;
134 case VK_FORMAT_B10G10R10A2_UNORM
:
135 return alpha
? WL_DRM_FORMAT_ARGB2101010
: WL_DRM_FORMAT_XRGB2101010
;
139 assert(!"Unsupported Vulkan format");
145 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t wl_format
)
147 struct wsi_wl_display
*display
= data
;
151 case WL_DRM_FORMAT_ABGR4444
:
152 case WL_DRM_FORMAT_XBGR4444
:
153 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R4G4B4A4_UNORM
);
155 case WL_DRM_FORMAT_BGR565
:
156 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R5G6B5_UNORM
);
158 case WL_DRM_FORMAT_ABGR1555
:
159 case WL_DRM_FORMAT_XBGR1555
:
160 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R5G5B5A1_UNORM
);
162 case WL_DRM_FORMAT_XBGR8888
:
163 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R8G8B8_UNORM
);
165 case WL_DRM_FORMAT_ABGR8888
:
166 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R8G8B8A8_UNORM
);
168 case WL_DRM_FORMAT_ABGR2101010
:
169 case WL_DRM_FORMAT_XBGR2101010
:
170 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R10G10B10A2_UNORM
);
172 case WL_DRM_FORMAT_ARGB4444
:
173 case WL_DRM_FORMAT_XRGB4444
:
174 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B4G4R4A4_UNORM
);
176 case WL_DRM_FORMAT_RGB565
:
177 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B5G6R5_UNORM
);
179 case WL_DRM_FORMAT_ARGB1555
:
180 case WL_DRM_FORMAT_XRGB1555
:
181 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B5G5R5A1_UNORM
);
184 case WL_DRM_FORMAT_XRGB8888
:
185 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8_SRGB
);
186 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8_UNORM
);
188 case WL_DRM_FORMAT_ARGB8888
:
189 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8A8_SRGB
);
190 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8A8_UNORM
);
193 case WL_DRM_FORMAT_ARGB2101010
:
194 case WL_DRM_FORMAT_XRGB2101010
:
195 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B10G10R10A2_UNORM
);
202 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
207 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t capabilities
)
209 struct wsi_wl_display
*display
= data
;
211 display
->capabilities
= capabilities
;
214 static const struct wl_drm_listener drm_listener
= {
217 drm_handle_authenticated
,
218 drm_handle_capabilities
,
222 registry_handle_global(void *data
, struct wl_registry
*registry
,
223 uint32_t name
, const char *interface
, uint32_t version
)
225 struct wsi_wl_display
*display
= data
;
227 if (strcmp(interface
, "wl_drm") == 0) {
228 assert(display
->drm
== NULL
);
230 assert(version
>= 2);
231 display
->drm
= wl_registry_bind(registry
, name
, &wl_drm_interface
, 2);
234 wl_drm_add_listener(display
->drm
, &drm_listener
, display
);
239 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
243 static const struct wl_registry_listener registry_listener
= {
244 registry_handle_global
,
245 registry_handle_global_remove
249 wsi_wl_display_destroy(struct wsi_wayland
*wsi
, struct wsi_wl_display
*display
)
251 u_vector_finish(&display
->formats
);
253 wl_drm_destroy(display
->drm
);
254 vk_free(wsi
->alloc
, display
);
257 static struct wsi_wl_display
*
258 wsi_wl_display_create(struct wsi_wayland
*wsi
, struct wl_display
*wl_display
)
260 struct wsi_wl_display
*display
=
261 vk_alloc(wsi
->alloc
, sizeof(*display
), 8,
262 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
266 memset(display
, 0, sizeof(*display
));
268 display
->display
= wl_display
;
269 display
->wsi_wl
= wsi
;
271 if (!u_vector_init(&display
->formats
, sizeof(VkFormat
), 8))
274 struct wl_registry
*registry
= wl_display_get_registry(wl_display
);
278 wl_registry_add_listener(registry
, ®istry_listener
, display
);
280 /* Round-rip to get the wl_drm global */
281 wl_display_roundtrip(wl_display
);
286 /* Round-rip to get wl_drm formats and capabilities */
287 wl_display_roundtrip(wl_display
);
289 /* We need prime support */
290 if (!(display
->capabilities
& WL_DRM_CAPABILITY_PRIME
))
293 /* We don't need this anymore */
294 wl_registry_destroy(registry
);
300 wl_registry_destroy(registry
);
302 wsi_wl_display_destroy(wsi
, display
);
306 static struct wsi_wl_display
*
307 wsi_wl_get_display(struct wsi_device
*wsi_device
,
308 struct wl_display
*wl_display
)
310 struct wsi_wayland
*wsi
=
311 (struct wsi_wayland
*)wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_WAYLAND
];
313 pthread_mutex_lock(&wsi
->mutex
);
315 struct hash_entry
*entry
= _mesa_hash_table_search(wsi
->displays
,
318 /* We're about to make a bunch of blocking calls. Let's drop the
319 * mutex for now so we don't block up too badly.
321 pthread_mutex_unlock(&wsi
->mutex
);
323 struct wsi_wl_display
*display
= wsi_wl_display_create(wsi
, wl_display
);
325 pthread_mutex_lock(&wsi
->mutex
);
327 entry
= _mesa_hash_table_search(wsi
->displays
, wl_display
);
329 /* Oops, someone raced us to it */
330 wsi_wl_display_destroy(wsi
, display
);
332 entry
= _mesa_hash_table_insert(wsi
->displays
, wl_display
, display
);
336 pthread_mutex_unlock(&wsi
->mutex
);
342 wsi_wl_get_presentation_support(struct wsi_device
*wsi_device
,
343 struct wl_display
*wl_display
)
345 return wsi_wl_get_display(wsi_device
, wl_display
) != NULL
;
349 wsi_wl_surface_get_support(VkIcdSurfaceBase
*surface
,
350 struct wsi_device
*wsi_device
,
351 const VkAllocationCallbacks
*alloc
,
352 uint32_t queueFamilyIndex
,
353 VkBool32
* pSupported
)
360 static const VkPresentModeKHR present_modes
[] = {
361 VK_PRESENT_MODE_MAILBOX_KHR
,
362 VK_PRESENT_MODE_FIFO_KHR
,
366 wsi_wl_surface_get_capabilities(VkIcdSurfaceBase
*surface
,
367 VkSurfaceCapabilitiesKHR
* caps
)
369 caps
->minImageCount
= MIN_NUM_IMAGES
;
370 caps
->maxImageCount
= 4;
371 caps
->currentExtent
= (VkExtent2D
) { -1, -1 };
372 caps
->minImageExtent
= (VkExtent2D
) { 1, 1 };
373 caps
->maxImageExtent
= (VkExtent2D
) { INT16_MAX
, INT16_MAX
};
374 caps
->supportedTransforms
= VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;
375 caps
->currentTransform
= VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;
376 caps
->maxImageArrayLayers
= 1;
378 caps
->supportedCompositeAlpha
=
379 VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR
|
380 VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR
;
382 caps
->supportedUsageFlags
=
383 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
384 VK_IMAGE_USAGE_SAMPLED_BIT
|
385 VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
386 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
392 wsi_wl_surface_get_formats(VkIcdSurfaceBase
*icd_surface
,
393 struct wsi_device
*wsi_device
,
394 uint32_t* pSurfaceFormatCount
,
395 VkSurfaceFormatKHR
* pSurfaceFormats
)
397 VkIcdSurfaceWayland
*surface
= (VkIcdSurfaceWayland
*)icd_surface
;
398 struct wsi_wl_display
*display
=
399 wsi_wl_get_display(wsi_device
, surface
->display
);
401 uint32_t count
= u_vector_length(&display
->formats
);
403 if (pSurfaceFormats
== NULL
) {
404 *pSurfaceFormatCount
= count
;
408 assert(*pSurfaceFormatCount
>= count
);
409 *pSurfaceFormatCount
= count
;
412 u_vector_foreach(f
, &display
->formats
) {
413 *(pSurfaceFormats
++) = (VkSurfaceFormatKHR
) {
415 /* TODO: We should get this from the compositor somehow */
416 .colorSpace
= VK_COLORSPACE_SRGB_NONLINEAR_KHR
,
424 wsi_wl_surface_get_present_modes(VkIcdSurfaceBase
*surface
,
425 uint32_t* pPresentModeCount
,
426 VkPresentModeKHR
* pPresentModes
)
428 if (pPresentModes
== NULL
) {
429 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
433 assert(*pPresentModeCount
>= ARRAY_SIZE(present_modes
));
434 typed_memcpy(pPresentModes
, present_modes
, *pPresentModeCount
);
435 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
440 VkResult
wsi_create_wl_surface(const VkAllocationCallbacks
*pAllocator
,
441 const VkWaylandSurfaceCreateInfoKHR
*pCreateInfo
,
442 VkSurfaceKHR
*pSurface
)
444 VkIcdSurfaceWayland
*surface
;
446 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
447 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
449 return VK_ERROR_OUT_OF_HOST_MEMORY
;
451 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_WAYLAND
;
452 surface
->display
= pCreateInfo
->display
;
453 surface
->surface
= pCreateInfo
->surface
;
455 *pSurface
= _VkIcdSurfaceBase_to_handle(&surface
->base
);
460 struct wsi_wl_image
{
462 VkDeviceMemory memory
;
463 struct wl_buffer
* buffer
;
467 struct wsi_wl_swapchain
{
468 struct wsi_swapchain base
;
470 struct wsi_wl_display
* display
;
471 struct wl_event_queue
* queue
;
472 struct wl_surface
* surface
;
478 VkPresentModeKHR present_mode
;
481 uint32_t image_count
;
482 struct wsi_wl_image images
[0];
486 wsi_wl_swapchain_get_images(struct wsi_swapchain
*wsi_chain
,
487 uint32_t *pCount
, VkImage
*pSwapchainImages
)
489 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)wsi_chain
;
491 if (pSwapchainImages
== NULL
) {
492 *pCount
= chain
->image_count
;
496 assert(chain
->image_count
<= *pCount
);
497 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
498 pSwapchainImages
[i
] = chain
->images
[i
].image
;
500 *pCount
= chain
->image_count
;
506 wsi_wl_swapchain_acquire_next_image(struct wsi_swapchain
*wsi_chain
,
508 VkSemaphore semaphore
,
509 uint32_t *image_index
)
511 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)wsi_chain
;
513 int ret
= wl_display_dispatch_queue_pending(chain
->display
->display
,
515 /* XXX: I'm not sure if out-of-date is the right error here. If
516 * wl_display_dispatch_queue_pending fails it most likely means we got
517 * kicked by the server so this seems more-or-less correct.
520 return VK_ERROR_OUT_OF_DATE_KHR
;
523 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
524 if (!chain
->images
[i
].busy
) {
525 /* We found a non-busy image */
527 chain
->images
[i
].busy
= true;
532 /* This time we do a blocking dispatch because we can't go
533 * anywhere until we get an event.
535 int ret
= wl_display_roundtrip_queue(chain
->display
->display
,
538 return VK_ERROR_OUT_OF_DATE_KHR
;
543 frame_handle_done(void *data
, struct wl_callback
*callback
, uint32_t serial
)
545 struct wsi_wl_swapchain
*chain
= data
;
547 chain
->fifo_ready
= true;
549 wl_callback_destroy(callback
);
552 static const struct wl_callback_listener frame_listener
= {
557 wsi_wl_swapchain_queue_present(struct wsi_swapchain
*wsi_chain
,
558 uint32_t image_index
)
560 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)wsi_chain
;
562 if (chain
->present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
563 while (!chain
->fifo_ready
) {
564 int ret
= wl_display_dispatch_queue(chain
->display
->display
,
567 return VK_ERROR_OUT_OF_DATE_KHR
;
571 assert(image_index
< chain
->image_count
);
572 wl_surface_attach(chain
->surface
, chain
->images
[image_index
].buffer
, 0, 0);
573 wl_surface_damage(chain
->surface
, 0, 0, INT32_MAX
, INT32_MAX
);
575 if (chain
->present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
576 struct wl_callback
*frame
= wl_surface_frame(chain
->surface
);
577 wl_proxy_set_queue((struct wl_proxy
*)frame
, chain
->queue
);
578 wl_callback_add_listener(frame
, &frame_listener
, chain
);
579 chain
->fifo_ready
= false;
582 chain
->images
[image_index
].busy
= true;
583 wl_surface_commit(chain
->surface
);
584 wl_display_flush(chain
->display
->display
);
590 buffer_handle_release(void *data
, struct wl_buffer
*buffer
)
592 struct wsi_wl_image
*image
= data
;
594 assert(image
->buffer
== buffer
);
599 static const struct wl_buffer_listener buffer_listener
= {
600 buffer_handle_release
,
604 wsi_wl_image_init(struct wsi_wl_swapchain
*chain
,
605 struct wsi_wl_image
*image
,
606 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
607 const VkAllocationCallbacks
* pAllocator
)
609 VkDevice vk_device
= chain
->base
.device
;
615 result
= chain
->base
.image_fns
->create_wsi_image(vk_device
,
624 if (result
!= VK_SUCCESS
)
627 image
->buffer
= wl_drm_create_prime_buffer(chain
->display
->drm
,
630 chain
->extent
.height
,
634 0, 0, 0, 0 /* unused */);
635 wl_display_roundtrip(chain
->display
->display
);
641 wl_proxy_set_queue((struct wl_proxy
*)image
->buffer
, chain
->queue
);
642 wl_buffer_add_listener(image
->buffer
, &buffer_listener
, image
);
647 chain
->base
.image_fns
->free_wsi_image(vk_device
, pAllocator
,
648 image
->image
, image
->memory
);
654 wsi_wl_swapchain_destroy(struct wsi_swapchain
*wsi_chain
,
655 const VkAllocationCallbacks
*pAllocator
)
657 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)wsi_chain
;
659 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
660 if (chain
->images
[i
].buffer
)
661 chain
->base
.image_fns
->free_wsi_image(chain
->base
.device
, pAllocator
,
662 chain
->images
[i
].image
,
663 chain
->images
[i
].memory
);
666 vk_free(pAllocator
, chain
);
672 wsi_wl_surface_create_swapchain(VkIcdSurfaceBase
*icd_surface
,
674 struct wsi_device
*wsi_device
,
675 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
676 const VkAllocationCallbacks
* pAllocator
,
677 const struct wsi_image_fns
*image_fns
,
678 struct wsi_swapchain
**swapchain_out
)
680 VkIcdSurfaceWayland
*surface
= (VkIcdSurfaceWayland
*)icd_surface
;
681 struct wsi_wl_swapchain
*chain
;
684 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
);
686 int num_images
= pCreateInfo
->minImageCount
;
688 assert(num_images
>= MIN_NUM_IMAGES
);
690 /* For true mailbox mode, we need at least 4 images:
691 * 1) One to scan out from
692 * 2) One to have queued for scan-out
693 * 3) One to be currently held by the Wayland compositor
694 * 4) One to render to
696 if (pCreateInfo
->presentMode
== VK_PRESENT_MODE_MAILBOX_KHR
)
697 num_images
= MAX2(num_images
, 4);
699 size_t size
= sizeof(*chain
) + num_images
* sizeof(chain
->images
[0]);
700 chain
= vk_alloc(pAllocator
, size
, 8,
701 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
703 return VK_ERROR_OUT_OF_HOST_MEMORY
;
705 bool alpha
= pCreateInfo
->compositeAlpha
==
706 VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR
;
708 chain
->base
.device
= device
;
709 chain
->base
.destroy
= wsi_wl_swapchain_destroy
;
710 chain
->base
.get_images
= wsi_wl_swapchain_get_images
;
711 chain
->base
.acquire_next_image
= wsi_wl_swapchain_acquire_next_image
;
712 chain
->base
.queue_present
= wsi_wl_swapchain_queue_present
;
713 chain
->base
.image_fns
= image_fns
;
714 chain
->surface
= surface
->surface
;
715 chain
->extent
= pCreateInfo
->imageExtent
;
716 chain
->vk_format
= pCreateInfo
->imageFormat
;
717 chain
->drm_format
= wl_drm_format_for_vk_format(chain
->vk_format
, alpha
);
719 chain
->present_mode
= pCreateInfo
->presentMode
;
720 chain
->fifo_ready
= true;
722 chain
->image_count
= num_images
;
724 /* Mark a bunch of stuff as NULL. This way we can just call
725 * destroy_swapchain for cleanup.
727 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
728 chain
->images
[i
].buffer
= NULL
;
731 chain
->display
= wsi_wl_get_display(wsi_device
,
733 if (!chain
->display
) {
734 result
= VK_ERROR_INITIALIZATION_FAILED
;
738 chain
->queue
= wl_display_create_queue(chain
->display
->display
);
740 result
= VK_ERROR_INITIALIZATION_FAILED
;
744 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
745 result
= wsi_wl_image_init(chain
, &chain
->images
[i
],
746 pCreateInfo
, pAllocator
);
747 if (result
!= VK_SUCCESS
)
749 chain
->images
[i
].busy
= false;
752 *swapchain_out
= &chain
->base
;
757 wsi_wl_swapchain_destroy(&chain
->base
, pAllocator
);
763 wsi_wl_init_wsi(struct wsi_device
*wsi_device
,
764 const VkAllocationCallbacks
*alloc
,
765 VkPhysicalDevice physical_device
,
766 const struct wsi_callbacks
*cbs
)
768 struct wsi_wayland
*wsi
;
771 wsi
= vk_alloc(alloc
, sizeof(*wsi
), 8,
772 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
774 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
778 wsi
->physical_device
= physical_device
;
781 int ret
= pthread_mutex_init(&wsi
->mutex
, NULL
);
784 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
786 /* FINISHME: Choose a better error. */
787 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
793 wsi
->displays
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
794 _mesa_key_pointer_equal
);
795 if (!wsi
->displays
) {
796 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
800 wsi
->base
.get_support
= wsi_wl_surface_get_support
;
801 wsi
->base
.get_capabilities
= wsi_wl_surface_get_capabilities
;
802 wsi
->base
.get_formats
= wsi_wl_surface_get_formats
;
803 wsi
->base
.get_present_modes
= wsi_wl_surface_get_present_modes
;
804 wsi
->base
.create_swapchain
= wsi_wl_surface_create_swapchain
;
806 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_WAYLAND
] = &wsi
->base
;
811 pthread_mutex_destroy(&wsi
->mutex
);
816 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_WAYLAND
] = NULL
;
822 wsi_wl_finish_wsi(struct wsi_device
*wsi_device
,
823 const VkAllocationCallbacks
*alloc
)
825 struct wsi_wayland
*wsi
=
826 (struct wsi_wayland
*)wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_WAYLAND
];
829 _mesa_hash_table_destroy(wsi
->displays
, NULL
);
831 pthread_mutex_destroy(&wsi
->mutex
);