• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016 Red Hat
3  * SPDX-License-Identifier: MIT
4  *
5  * based on intel anv code:
6  * Copyright © 2015 Intel Corporation
7  */
8 
9 #include "tu_wsi.h"
10 
11 #include "vk_util.h"
12 #include "wsi_common_drm.h"
13 #include "drm-uapi/drm_fourcc.h"
14 
15 #include "tu_device.h"
16 
17 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
tu_wsi_proc_addr(VkPhysicalDevice physicalDevice,const char * pName)18 tu_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
19 {
20    TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
21    return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
22 }
23 
24 static bool
tu_wsi_can_present_on_device(VkPhysicalDevice physicalDevice,int fd)25 tu_wsi_can_present_on_device(VkPhysicalDevice physicalDevice, int fd)
26 {
27    TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
28 
29    return wsi_common_drm_devices_equal(fd, pdevice->local_fd);
30 }
31 
32 VkResult
tu_wsi_init(struct tu_physical_device * physical_device)33 tu_wsi_init(struct tu_physical_device *physical_device)
34 {
35    VkResult result;
36 
37    result = wsi_device_init(&physical_device->wsi_device,
38                             tu_physical_device_to_handle(physical_device),
39                             tu_wsi_proc_addr,
40                             &physical_device->instance->vk.alloc,
41                             physical_device->master_fd,
42                             &physical_device->instance->dri_options,
43                             false);
44    if (result != VK_SUCCESS)
45       return result;
46 
47    physical_device->wsi_device.supports_modifiers = true;
48    physical_device->wsi_device.can_present_on_device =
49       tu_wsi_can_present_on_device;
50 
51    physical_device->vk.wsi_device = &physical_device->wsi_device;
52 
53    return VK_SUCCESS;
54 }
55 
56 void
tu_wsi_finish(struct tu_physical_device * physical_device)57 tu_wsi_finish(struct tu_physical_device *physical_device)
58 {
59    physical_device->vk.wsi_device = NULL;
60    wsi_device_finish(&physical_device->wsi_device,
61                      &physical_device->instance->vk.alloc);
62 }
63