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 <stdbool.h> 24#include <string.h> 25#include <unistd.h> 26#include <fcntl.h> 27#include <sys/ioctl.h> 28#include "tu_private.h" 29#include "tu_cs.h" 30#include "util/disk_cache.h" 31#include "util/strtod.h" 32#include "vk_util.h" 33#include "vk_format.h" 34#include "util/debug.h" 35#include "wsi_common_display.h" 36 37/* VK_EXT_display_control */ 38 39VKAPI_ATTR VkResult VKAPI_CALL 40tu_RegisterDeviceEventEXT(VkDevice _device, 41 const VkDeviceEventInfoEXT *device_event_info, 42 const VkAllocationCallbacks *allocator, 43 VkFence *out_fence) 44{ 45 TU_FROM_HANDLE(tu_device, device, _device); 46 VkResult ret; 47 48 VkFence _fence; 49 ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, &_fence); 50 if (ret != VK_SUCCESS) 51 return ret; 52 53 TU_FROM_HANDLE(tu_syncobj, fence, _fence); 54 55 int sync_fd = tu_syncobj_to_fd(device, fence); 56 if (sync_fd >= 0) { 57 ret = wsi_register_device_event(_device, 58 &device->physical_device->wsi_device, 59 device_event_info, 60 allocator, 61 NULL, 62 sync_fd); 63 64 close(sync_fd); 65 } else { 66 ret = VK_ERROR_OUT_OF_HOST_MEMORY; 67 } 68 69 if (ret != VK_SUCCESS) 70 tu_DestroyFence(_device, _fence, allocator); 71 else 72 *out_fence = _fence; 73 74 return ret; 75} 76 77VKAPI_ATTR VkResult VKAPI_CALL 78tu_RegisterDisplayEventEXT(VkDevice _device, 79 VkDisplayKHR display, 80 const VkDisplayEventInfoEXT *display_event_info, 81 const VkAllocationCallbacks *allocator, 82 VkFence *_fence) 83{ 84 TU_FROM_HANDLE(tu_device, device, _device); 85 VkResult ret; 86 87 ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, _fence); 88 if (ret != VK_SUCCESS) 89 return ret; 90 91 TU_FROM_HANDLE(tu_syncobj, fence, *_fence); 92 93 int sync_fd = tu_syncobj_to_fd(device, fence); 94 if (sync_fd >= 0) { 95 ret = wsi_register_display_event(_device, 96 &device->physical_device->wsi_device, 97 display, 98 display_event_info, 99 allocator, 100 NULL, 101 sync_fd); 102 103 close(sync_fd); 104 } else { 105 ret = VK_ERROR_OUT_OF_HOST_MEMORY; 106 } 107 108 if (ret != VK_SUCCESS) 109 tu_DestroyFence(_device, *_fence, allocator); 110 111 return ret; 112} 113