1 /*
2  * Copyright © 2017 Keith Packard
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22 
23 #include "anv_private.h"
24 #include "wsi_common.h"
25 #include "vk_util.h"
26 #include "wsi_common_display.h"
27 
28 /* VK_EXT_display_control */
29 
30 VkResult
anv_RegisterDeviceEventEXT(VkDevice _device,const VkDeviceEventInfoEXT * device_event_info,const VkAllocationCallbacks * allocator,VkFence * _fence)31 anv_RegisterDeviceEventEXT(VkDevice _device,
32                             const VkDeviceEventInfoEXT *device_event_info,
33                             const VkAllocationCallbacks *allocator,
34                             VkFence *_fence)
35 {
36    ANV_FROM_HANDLE(anv_device, device, _device);
37    struct anv_fence *fence;
38    VkResult ret;
39 
40    fence = vk_object_zalloc(&device->vk, allocator, sizeof (*fence),
41                             VK_OBJECT_TYPE_FENCE);
42    if (!fence)
43       return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
44 
45    fence->permanent.type = ANV_FENCE_TYPE_WSI;
46 
47    ret = wsi_register_device_event(_device,
48                                    &device->physical->wsi_device,
49                                    device_event_info,
50                                    allocator,
51                                    &fence->permanent.fence_wsi,
52                                    -1);
53    if (ret == VK_SUCCESS)
54       *_fence = anv_fence_to_handle(fence);
55    else
56       vk_free2(&device->vk.alloc, allocator, fence);
57    return ret;
58 }
59 
60 VkResult
anv_RegisterDisplayEventEXT(VkDevice _device,VkDisplayKHR display,const VkDisplayEventInfoEXT * display_event_info,const VkAllocationCallbacks * allocator,VkFence * _fence)61 anv_RegisterDisplayEventEXT(VkDevice _device,
62                              VkDisplayKHR display,
63                              const VkDisplayEventInfoEXT *display_event_info,
64                              const VkAllocationCallbacks *allocator,
65                              VkFence *_fence)
66 {
67    ANV_FROM_HANDLE(anv_device, device, _device);
68    struct anv_fence *fence;
69    VkResult ret;
70 
71    fence = vk_object_zalloc(&device->vk, allocator, sizeof (*fence),
72                             VK_OBJECT_TYPE_FENCE);
73    if (!fence)
74       return VK_ERROR_OUT_OF_HOST_MEMORY;
75 
76    fence->permanent.type = ANV_FENCE_TYPE_WSI;
77 
78    ret = wsi_register_display_event(
79       _device, &device->physical->wsi_device,
80       display, display_event_info, allocator, &fence->permanent.fence_wsi, -1);
81 
82    if (ret == VK_SUCCESS)
83       *_fence = anv_fence_to_handle(fence);
84    else
85       vk_free2(&device->vk.alloc, allocator, fence);
86    return ret;
87 }
88