Path: blob/21.2-virgl/src/freedreno/vulkan/tu_wsi_display.c
4565 views
/*1* Copyright © 2017 Keith Packard2*3* Permission to use, copy, modify, distribute, and sell this software and its4* documentation for any purpose is hereby granted without fee, provided that5* the above copyright notice appear in all copies and that both that copyright6* notice and this permission notice appear in supporting documentation, and7* that the name of the copyright holders not be used in advertising or8* publicity pertaining to distribution of the software without specific,9* written prior permission. The copyright holders make no representations10* about the suitability of this software for any purpose. It is provided "as11* is" without express or implied warranty.12*13* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,14* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO15* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR16* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,17* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER18* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE19* OF THIS SOFTWARE.20*/2122#include <stdbool.h>23#include <string.h>24#include <unistd.h>25#include <fcntl.h>26#include <sys/ioctl.h>27#include "tu_private.h"28#include "tu_cs.h"29#include "util/disk_cache.h"30#include "util/strtod.h"31#include "vk_util.h"32#include "vk_format.h"33#include "util/debug.h"34#include "wsi_common_display.h"3536VKAPI_ATTR VkResult VKAPI_CALL37tu_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,38uint32_t *property_count,39VkDisplayPropertiesKHR *properties)40{41TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);4243return wsi_display_get_physical_device_display_properties(44physical_device,45&pdevice->wsi_device,46property_count,47properties);48}4950VKAPI_ATTR VkResult VKAPI_CALL51tu_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physical_device,52uint32_t *property_count,53VkDisplayProperties2KHR *properties)54{55TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);5657return wsi_display_get_physical_device_display_properties2(58physical_device,59&pdevice->wsi_device,60property_count,61properties);62}6364VKAPI_ATTR VkResult VKAPI_CALL65tu_GetPhysicalDeviceDisplayPlanePropertiesKHR(66VkPhysicalDevice physical_device,67uint32_t *property_count,68VkDisplayPlanePropertiesKHR *properties)69{70TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);7172return wsi_display_get_physical_device_display_plane_properties(73physical_device,74&pdevice->wsi_device,75property_count,76properties);77}7879VKAPI_ATTR VkResult VKAPI_CALL80tu_GetPhysicalDeviceDisplayPlaneProperties2KHR(81VkPhysicalDevice physical_device,82uint32_t *property_count,83VkDisplayPlaneProperties2KHR *properties)84{85TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);8687return wsi_display_get_physical_device_display_plane_properties2(88physical_device,89&pdevice->wsi_device,90property_count,91properties);92}9394VKAPI_ATTR VkResult VKAPI_CALL95tu_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,96uint32_t plane_index,97uint32_t *display_count,98VkDisplayKHR *displays)99{100TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);101102return wsi_display_get_display_plane_supported_displays(103physical_device,104&pdevice->wsi_device,105plane_index,106display_count,107displays);108}109110111VKAPI_ATTR VkResult VKAPI_CALL112tu_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,113VkDisplayKHR display,114uint32_t *property_count,115VkDisplayModePropertiesKHR *properties)116{117TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);118119return wsi_display_get_display_mode_properties(physical_device,120&pdevice->wsi_device,121display,122property_count,123properties);124}125126VKAPI_ATTR VkResult VKAPI_CALL127tu_GetDisplayModeProperties2KHR(VkPhysicalDevice physical_device,128VkDisplayKHR display,129uint32_t *property_count,130VkDisplayModeProperties2KHR *properties)131{132TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);133134return wsi_display_get_display_mode_properties2(physical_device,135&pdevice->wsi_device,136display,137property_count,138properties);139}140141VKAPI_ATTR VkResult VKAPI_CALL142tu_CreateDisplayModeKHR(VkPhysicalDevice physical_device,143VkDisplayKHR display,144const VkDisplayModeCreateInfoKHR *create_info,145const VkAllocationCallbacks *allocator,146VkDisplayModeKHR *mode)147{148TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);149150return wsi_display_create_display_mode(physical_device,151&pdevice->wsi_device,152display,153create_info,154allocator,155mode);156}157158VKAPI_ATTR VkResult VKAPI_CALL159tu_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,160VkDisplayModeKHR mode_khr,161uint32_t plane_index,162VkDisplayPlaneCapabilitiesKHR *capabilities)163{164TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);165166return wsi_get_display_plane_capabilities(physical_device,167&pdevice->wsi_device,168mode_khr,169plane_index,170capabilities);171}172173VKAPI_ATTR VkResult VKAPI_CALL174tu_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physical_device,175const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,176VkDisplayPlaneCapabilities2KHR *capabilities)177{178TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);179180return wsi_get_display_plane_capabilities2(physical_device,181&pdevice->wsi_device,182pDisplayPlaneInfo,183capabilities);184}185186VKAPI_ATTR VkResult VKAPI_CALL187tu_CreateDisplayPlaneSurfaceKHR(188VkInstance _instance,189const VkDisplaySurfaceCreateInfoKHR *create_info,190const VkAllocationCallbacks *allocator,191VkSurfaceKHR *surface)192{193TU_FROM_HANDLE(tu_instance, instance, _instance);194const VkAllocationCallbacks *alloc;195196if (allocator)197alloc = allocator;198else199alloc = &instance->vk.alloc;200201return wsi_create_display_surface(_instance, alloc,202create_info, surface);203}204205VKAPI_ATTR VkResult VKAPI_CALL206tu_ReleaseDisplayEXT(VkPhysicalDevice physical_device,207VkDisplayKHR display)208{209TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);210211return wsi_release_display(physical_device,212&pdevice->wsi_device,213display);214}215216#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT217VKAPI_ATTR VkResult VKAPI_CALL218tu_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device,219Display *dpy,220VkDisplayKHR display)221{222TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);223224return wsi_acquire_xlib_display(physical_device,225&pdevice->wsi_device,226dpy,227display);228}229230VKAPI_ATTR VkResult VKAPI_CALL231tu_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device,232Display *dpy,233RROutput output,234VkDisplayKHR *display)235{236TU_FROM_HANDLE(tu_physical_device, pdevice, physical_device);237238return wsi_get_randr_output_display(physical_device,239&pdevice->wsi_device,240dpy,241output,242display);243}244#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */245246/* VK_EXT_display_control */247248VKAPI_ATTR VkResult VKAPI_CALL249tu_DisplayPowerControlEXT(VkDevice _device,250VkDisplayKHR display,251const VkDisplayPowerInfoEXT *display_power_info)252{253TU_FROM_HANDLE(tu_device, device, _device);254255return wsi_display_power_control(_device,256&device->physical_device->wsi_device,257display,258display_power_info);259}260261VKAPI_ATTR VkResult VKAPI_CALL262tu_RegisterDeviceEventEXT(VkDevice _device,263const VkDeviceEventInfoEXT *device_event_info,264const VkAllocationCallbacks *allocator,265VkFence *out_fence)266{267TU_FROM_HANDLE(tu_device, device, _device);268VkResult ret;269270VkFence _fence;271ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, &_fence);272if (ret != VK_SUCCESS)273return ret;274275TU_FROM_HANDLE(tu_syncobj, fence, _fence);276277int sync_fd = tu_syncobj_to_fd(device, fence);278if (sync_fd >= 0) {279ret = wsi_register_device_event(_device,280&device->physical_device->wsi_device,281device_event_info,282allocator,283NULL,284sync_fd);285286close(sync_fd);287} else {288ret = VK_ERROR_OUT_OF_HOST_MEMORY;289}290291if (ret != VK_SUCCESS)292tu_DestroyFence(_device, _fence, allocator);293else294*out_fence = _fence;295296return ret;297}298299VKAPI_ATTR VkResult VKAPI_CALL300tu_RegisterDisplayEventEXT(VkDevice _device,301VkDisplayKHR display,302const VkDisplayEventInfoEXT *display_event_info,303const VkAllocationCallbacks *allocator,304VkFence *_fence)305{306TU_FROM_HANDLE(tu_device, device, _device);307VkResult ret;308309ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, _fence);310if (ret != VK_SUCCESS)311return ret;312313TU_FROM_HANDLE(tu_syncobj, fence, *_fence);314315int sync_fd = tu_syncobj_to_fd(device, fence);316if (sync_fd >= 0) {317ret = wsi_register_display_event(_device,318&device->physical_device->wsi_device,319display,320display_event_info,321allocator,322NULL,323sync_fd);324325close(sync_fd);326} else {327ret = VK_ERROR_OUT_OF_HOST_MEMORY;328}329330if (ret != VK_SUCCESS)331tu_DestroyFence(_device, *_fence, allocator);332333return ret;334}335336VKAPI_ATTR VkResult VKAPI_CALL337tu_GetSwapchainCounterEXT(VkDevice _device,338VkSwapchainKHR swapchain,339VkSurfaceCounterFlagBitsEXT flag_bits,340uint64_t *value)341{342TU_FROM_HANDLE(tu_device, device, _device);343344return wsi_get_swapchain_counter(_device,345&device->physical_device->wsi_device,346swapchain,347flag_bits,348value);349}350351352353