Path: blob/21.2-virgl/src/intel/vulkan/anv_wsi_display.c
4547 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 "anv_private.h"23#include "wsi_common.h"24#include "vk_util.h"25#include "wsi_common_display.h"2627VkResult28anv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,29uint32_t *property_count,30VkDisplayPropertiesKHR *properties)31{32ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);3334return wsi_display_get_physical_device_display_properties(35physical_device,36&pdevice->wsi_device,37property_count,38properties);39}4041VkResult42anv_GetPhysicalDeviceDisplayProperties2KHR(43VkPhysicalDevice physicalDevice,44uint32_t* pPropertyCount,45VkDisplayProperties2KHR* pProperties)46{47ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);4849return wsi_display_get_physical_device_display_properties2(50physicalDevice, &pdevice->wsi_device,51pPropertyCount, pProperties);52}5354VkResult55anv_GetPhysicalDeviceDisplayPlanePropertiesKHR(56VkPhysicalDevice physical_device,57uint32_t *property_count,58VkDisplayPlanePropertiesKHR *properties)59{60ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);6162return wsi_display_get_physical_device_display_plane_properties(63physical_device, &pdevice->wsi_device,64property_count, properties);65}6667VkResult68anv_GetPhysicalDeviceDisplayPlaneProperties2KHR(69VkPhysicalDevice physicalDevice,70uint32_t* pPropertyCount,71VkDisplayPlaneProperties2KHR* pProperties)72{73ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);7475return wsi_display_get_physical_device_display_plane_properties2(76physicalDevice, &pdevice->wsi_device,77pPropertyCount, pProperties);78}7980VkResult81anv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,82uint32_t plane_index,83uint32_t *display_count,84VkDisplayKHR *displays)85{86ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);8788return wsi_display_get_display_plane_supported_displays(physical_device,89&pdevice->wsi_device,90plane_index,91display_count,92displays);93}949596VkResult97anv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,98VkDisplayKHR display,99uint32_t *property_count,100VkDisplayModePropertiesKHR *properties)101{102ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);103104return wsi_display_get_display_mode_properties(physical_device,105&pdevice->wsi_device,106display,107property_count,108properties);109}110111VkResult112anv_GetDisplayModeProperties2KHR(113VkPhysicalDevice physicalDevice,114VkDisplayKHR display,115uint32_t* pPropertyCount,116VkDisplayModeProperties2KHR* pProperties)117{118ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);119120return wsi_display_get_display_mode_properties2(physicalDevice,121&pdevice->wsi_device,122display,123pPropertyCount,124pProperties);125}126127VkResult128anv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,129VkDisplayKHR display,130const VkDisplayModeCreateInfoKHR *create_info,131const VkAllocationCallbacks *allocator,132VkDisplayModeKHR *mode)133{134ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);135136return wsi_display_create_display_mode(physical_device,137&pdevice->wsi_device,138display,139create_info,140allocator,141mode);142}143144VkResult145anv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,146VkDisplayModeKHR mode_khr,147uint32_t plane_index,148VkDisplayPlaneCapabilitiesKHR *capabilities)149{150ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);151152return wsi_get_display_plane_capabilities(physical_device,153&pdevice->wsi_device,154mode_khr,155plane_index,156capabilities);157}158159VkResult160anv_GetDisplayPlaneCapabilities2KHR(161VkPhysicalDevice physicalDevice,162const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo,163VkDisplayPlaneCapabilities2KHR* pCapabilities)164{165ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);166167return wsi_get_display_plane_capabilities2(physicalDevice,168&pdevice->wsi_device,169pDisplayPlaneInfo,170pCapabilities);171}172173VkResult174anv_CreateDisplayPlaneSurfaceKHR(175VkInstance _instance,176const VkDisplaySurfaceCreateInfoKHR *create_info,177const VkAllocationCallbacks *allocator,178VkSurfaceKHR *surface)179{180ANV_FROM_HANDLE(anv_instance, instance, _instance);181const VkAllocationCallbacks *alloc;182183if (allocator)184alloc = allocator;185else186alloc = &instance->vk.alloc;187188return wsi_create_display_surface(_instance, alloc, create_info, surface);189}190191VkResult192anv_ReleaseDisplayEXT(VkPhysicalDevice physical_device,193VkDisplayKHR display)194{195ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);196197return wsi_release_display(physical_device,198&pdevice->wsi_device,199display);200}201202#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT203VkResult204anv_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device,205Display *dpy,206VkDisplayKHR display)207{208ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);209210return wsi_acquire_xlib_display(physical_device,211&pdevice->wsi_device,212dpy,213display);214}215216VkResult217anv_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device,218Display *dpy,219RROutput output,220VkDisplayKHR *display)221{222ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);223224return wsi_get_randr_output_display(physical_device,225&pdevice->wsi_device,226dpy,227output,228display);229}230#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */231232/* VK_EXT_display_control */233234VkResult235anv_DisplayPowerControlEXT(VkDevice _device,236VkDisplayKHR display,237const VkDisplayPowerInfoEXT *display_power_info)238{239ANV_FROM_HANDLE(anv_device, device, _device);240241return wsi_display_power_control(242_device, &device->physical->wsi_device,243display, display_power_info);244}245246VkResult247anv_RegisterDeviceEventEXT(VkDevice _device,248const VkDeviceEventInfoEXT *device_event_info,249const VkAllocationCallbacks *allocator,250VkFence *_fence)251{252ANV_FROM_HANDLE(anv_device, device, _device);253struct anv_fence *fence;254VkResult ret;255256fence = vk_zalloc2(&device->vk.alloc, allocator, sizeof (*fence), 8,257VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);258if (!fence)259return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);260261fence->permanent.type = ANV_FENCE_TYPE_WSI;262263ret = wsi_register_device_event(_device,264&device->physical->wsi_device,265device_event_info,266allocator,267&fence->permanent.fence_wsi,268-1);269if (ret == VK_SUCCESS)270*_fence = anv_fence_to_handle(fence);271else272vk_free2(&device->vk.alloc, allocator, fence);273return ret;274}275276VkResult277anv_RegisterDisplayEventEXT(VkDevice _device,278VkDisplayKHR display,279const VkDisplayEventInfoEXT *display_event_info,280const VkAllocationCallbacks *allocator,281VkFence *_fence)282{283ANV_FROM_HANDLE(anv_device, device, _device);284struct anv_fence *fence;285VkResult ret;286287fence = vk_zalloc2(&device->vk.alloc, allocator, sizeof (*fence), 8,288VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);289if (!fence)290return VK_ERROR_OUT_OF_HOST_MEMORY;291292fence->permanent.type = ANV_FENCE_TYPE_WSI;293294ret = wsi_register_display_event(295_device, &device->physical->wsi_device,296display, display_event_info, allocator, &fence->permanent.fence_wsi, -1);297298if (ret == VK_SUCCESS)299*_fence = anv_fence_to_handle(fence);300else301vk_free2(&device->vk.alloc, allocator, fence);302return ret;303}304305VkResult306anv_GetSwapchainCounterEXT(VkDevice _device,307VkSwapchainKHR swapchain,308VkSurfaceCounterFlagBitsEXT flag_bits,309uint64_t *value)310{311ANV_FROM_HANDLE(anv_device, device, _device);312313return wsi_get_swapchain_counter(314_device, &device->physical->wsi_device,315swapchain, flag_bits, value);316}317318VkResult319anv_AcquireDrmDisplayEXT(VkPhysicalDevice physical_device,320int32_t drm_fd,321VkDisplayKHR display)322{323ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);324325return wsi_acquire_drm_display(physical_device, &pdevice->wsi_device, drm_fd, display);326}327328VkResult329anv_GetDrmDisplayEXT(VkPhysicalDevice physical_device,330int32_t drm_fd,331uint32_t connector_id,332VkDisplayKHR *display)333{334ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);335336return wsi_get_drm_display(physical_device, &pdevice->wsi_device, drm_fd, connector_id, display);337}338339340