• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_format_info.h"
26 #include "vk_util.h"
27 #include "wsi_common_display.h"
28 
29 VkResult
anv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,uint32_t * property_count,VkDisplayPropertiesKHR * properties)30 anv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,
31                                           uint32_t *property_count,
32                                           VkDisplayPropertiesKHR *properties)
33 {
34    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
35 
36    return wsi_display_get_physical_device_display_properties(
37       physical_device,
38       &pdevice->wsi_device,
39       property_count,
40       properties);
41 }
42 
43 VkResult
anv_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayProperties2KHR * pProperties)44 anv_GetPhysicalDeviceDisplayProperties2KHR(
45     VkPhysicalDevice                            physicalDevice,
46     uint32_t*                                   pPropertyCount,
47     VkDisplayProperties2KHR*                    pProperties)
48 {
49    ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
50 
51    return wsi_display_get_physical_device_display_properties2(
52       physicalDevice, &pdevice->wsi_device,
53       pPropertyCount, pProperties);
54 }
55 
56 VkResult
anv_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physical_device,uint32_t * property_count,VkDisplayPlanePropertiesKHR * properties)57 anv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
58    VkPhysicalDevice physical_device,
59    uint32_t *property_count,
60    VkDisplayPlanePropertiesKHR *properties)
61 {
62    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
63 
64    return wsi_display_get_physical_device_display_plane_properties(
65       physical_device, &pdevice->wsi_device,
66       property_count, properties);
67 }
68 
69 VkResult
anv_GetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPlaneProperties2KHR * pProperties)70 anv_GetPhysicalDeviceDisplayPlaneProperties2KHR(
71     VkPhysicalDevice                            physicalDevice,
72     uint32_t*                                   pPropertyCount,
73     VkDisplayPlaneProperties2KHR*               pProperties)
74 {
75    ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
76 
77    return wsi_display_get_physical_device_display_plane_properties2(
78       physicalDevice, &pdevice->wsi_device,
79       pPropertyCount, pProperties);
80 }
81 
82 VkResult
anv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,uint32_t plane_index,uint32_t * display_count,VkDisplayKHR * displays)83 anv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,
84                                         uint32_t plane_index,
85                                         uint32_t *display_count,
86                                         VkDisplayKHR *displays)
87 {
88    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
89 
90    return wsi_display_get_display_plane_supported_displays(physical_device,
91                                                            &pdevice->wsi_device,
92                                                            plane_index,
93                                                            display_count,
94                                                            displays);
95 }
96 
97 
98 VkResult
anv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,VkDisplayKHR display,uint32_t * property_count,VkDisplayModePropertiesKHR * properties)99 anv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,
100                                 VkDisplayKHR display,
101                                 uint32_t *property_count,
102                                 VkDisplayModePropertiesKHR *properties)
103 {
104    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
105 
106    return wsi_display_get_display_mode_properties(physical_device,
107                                                   &pdevice->wsi_device,
108                                                   display,
109                                                   property_count,
110                                                   properties);
111 }
112 
113 VkResult
anv_GetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModeProperties2KHR * pProperties)114 anv_GetDisplayModeProperties2KHR(
115     VkPhysicalDevice                            physicalDevice,
116     VkDisplayKHR                                display,
117     uint32_t*                                   pPropertyCount,
118     VkDisplayModeProperties2KHR*                pProperties)
119 {
120    ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
121 
122    return wsi_display_get_display_mode_properties2(physicalDevice,
123                                                    &pdevice->wsi_device,
124                                                    display,
125                                                    pPropertyCount,
126                                                    pProperties);
127 }
128 
129 VkResult
anv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,VkDisplayKHR display,const VkDisplayModeCreateInfoKHR * create_info,const VkAllocationCallbacks * allocator,VkDisplayModeKHR * mode)130 anv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,
131                          VkDisplayKHR display,
132                          const VkDisplayModeCreateInfoKHR *create_info,
133                          const VkAllocationCallbacks *allocator,
134                          VkDisplayModeKHR *mode)
135 {
136    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
137 
138    return wsi_display_create_display_mode(physical_device,
139                                           &pdevice->wsi_device,
140                                           display,
141                                           create_info,
142                                           allocator,
143                                           mode);
144 }
145 
146 VkResult
anv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,VkDisplayModeKHR mode_khr,uint32_t plane_index,VkDisplayPlaneCapabilitiesKHR * capabilities)147 anv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,
148                                    VkDisplayModeKHR mode_khr,
149                                    uint32_t plane_index,
150                                    VkDisplayPlaneCapabilitiesKHR *capabilities)
151 {
152    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
153 
154    return wsi_get_display_plane_capabilities(physical_device,
155                                              &pdevice->wsi_device,
156                                              mode_khr,
157                                              plane_index,
158                                              capabilities);
159 }
160 
161 VkResult
anv_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,const VkDisplayPlaneInfo2KHR * pDisplayPlaneInfo,VkDisplayPlaneCapabilities2KHR * pCapabilities)162 anv_GetDisplayPlaneCapabilities2KHR(
163     VkPhysicalDevice                            physicalDevice,
164     const VkDisplayPlaneInfo2KHR*               pDisplayPlaneInfo,
165     VkDisplayPlaneCapabilities2KHR*             pCapabilities)
166 {
167    ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
168 
169    return wsi_get_display_plane_capabilities2(physicalDevice,
170                                               &pdevice->wsi_device,
171                                               pDisplayPlaneInfo,
172                                               pCapabilities);
173 }
174 
175 VkResult
anv_CreateDisplayPlaneSurfaceKHR(VkInstance _instance,const VkDisplaySurfaceCreateInfoKHR * create_info,const VkAllocationCallbacks * allocator,VkSurfaceKHR * surface)176 anv_CreateDisplayPlaneSurfaceKHR(
177    VkInstance _instance,
178    const VkDisplaySurfaceCreateInfoKHR *create_info,
179    const VkAllocationCallbacks *allocator,
180    VkSurfaceKHR *surface)
181 {
182    ANV_FROM_HANDLE(anv_instance, instance, _instance);
183    const VkAllocationCallbacks *alloc;
184 
185    if (allocator)
186      alloc = allocator;
187    else
188      alloc = &instance->alloc;
189 
190    return wsi_create_display_surface(_instance, alloc, create_info, surface);
191 }
192 
193 VkResult
anv_ReleaseDisplayEXT(VkPhysicalDevice physical_device,VkDisplayKHR display)194 anv_ReleaseDisplayEXT(VkPhysicalDevice physical_device,
195                        VkDisplayKHR     display)
196 {
197    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
198 
199    return wsi_release_display(physical_device,
200                               &pdevice->wsi_device,
201                               display);
202 }
203 
204 #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
205 VkResult
anv_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device,Display * dpy,VkDisplayKHR display)206 anv_AcquireXlibDisplayEXT(VkPhysicalDevice     physical_device,
207                            Display              *dpy,
208                            VkDisplayKHR         display)
209 {
210    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
211 
212    return wsi_acquire_xlib_display(physical_device,
213                                    &pdevice->wsi_device,
214                                    dpy,
215                                    display);
216 }
217 
218 VkResult
anv_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device,Display * dpy,RROutput output,VkDisplayKHR * display)219 anv_GetRandROutputDisplayEXT(VkPhysicalDevice  physical_device,
220                               Display           *dpy,
221                               RROutput          output,
222                               VkDisplayKHR      *display)
223 {
224    ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
225 
226    return wsi_get_randr_output_display(physical_device,
227                                        &pdevice->wsi_device,
228                                        dpy,
229                                        output,
230                                        display);
231 }
232 #endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */
233 
234 /* VK_EXT_display_control */
235 
236 VkResult
anv_DisplayPowerControlEXT(VkDevice _device,VkDisplayKHR display,const VkDisplayPowerInfoEXT * display_power_info)237 anv_DisplayPowerControlEXT(VkDevice                    _device,
238                             VkDisplayKHR                display,
239                             const VkDisplayPowerInfoEXT *display_power_info)
240 {
241    ANV_FROM_HANDLE(anv_device, device, _device);
242 
243    return wsi_display_power_control(
244       _device, &device->physical->wsi_device,
245       display, display_power_info);
246 }
247 
248 VkResult
anv_RegisterDeviceEventEXT(VkDevice _device,const VkDeviceEventInfoEXT * device_event_info,const VkAllocationCallbacks * allocator,VkFence * _fence)249 anv_RegisterDeviceEventEXT(VkDevice _device,
250                             const VkDeviceEventInfoEXT *device_event_info,
251                             const VkAllocationCallbacks *allocator,
252                             VkFence *_fence)
253 {
254    ANV_FROM_HANDLE(anv_device, device, _device);
255    struct anv_fence *fence;
256    VkResult ret;
257 
258    fence = vk_zalloc2(&device->vk.alloc, allocator, sizeof (*fence), 8,
259                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
260    if (!fence)
261       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
262 
263    fence->permanent.type = ANV_FENCE_TYPE_WSI;
264 
265    ret = wsi_register_device_event(_device,
266                                    &device->physical->wsi_device,
267                                    device_event_info,
268                                    allocator,
269                                    &fence->permanent.fence_wsi,
270                                    -1);
271    if (ret == VK_SUCCESS)
272       *_fence = anv_fence_to_handle(fence);
273    else
274       vk_free2(&device->vk.alloc, allocator, fence);
275    return ret;
276 }
277 
278 VkResult
anv_RegisterDisplayEventEXT(VkDevice _device,VkDisplayKHR display,const VkDisplayEventInfoEXT * display_event_info,const VkAllocationCallbacks * allocator,VkFence * _fence)279 anv_RegisterDisplayEventEXT(VkDevice _device,
280                              VkDisplayKHR display,
281                              const VkDisplayEventInfoEXT *display_event_info,
282                              const VkAllocationCallbacks *allocator,
283                              VkFence *_fence)
284 {
285    ANV_FROM_HANDLE(anv_device, device, _device);
286    struct anv_fence *fence;
287    VkResult ret;
288 
289    fence = vk_zalloc2(&device->vk.alloc, allocator, sizeof (*fence), 8,
290                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
291    if (!fence)
292       return VK_ERROR_OUT_OF_HOST_MEMORY;
293 
294    fence->permanent.type = ANV_FENCE_TYPE_WSI;
295 
296    ret = wsi_register_display_event(
297       _device, &device->physical->wsi_device,
298       display, display_event_info, allocator, &fence->permanent.fence_wsi, -1);
299 
300    if (ret == VK_SUCCESS)
301       *_fence = anv_fence_to_handle(fence);
302    else
303       vk_free2(&device->vk.alloc, allocator, fence);
304    return ret;
305 }
306 
307 VkResult
anv_GetSwapchainCounterEXT(VkDevice _device,VkSwapchainKHR swapchain,VkSurfaceCounterFlagBitsEXT flag_bits,uint64_t * value)308 anv_GetSwapchainCounterEXT(VkDevice _device,
309                             VkSwapchainKHR swapchain,
310                             VkSurfaceCounterFlagBitsEXT flag_bits,
311                             uint64_t *value)
312 {
313    ANV_FROM_HANDLE(anv_device, device, _device);
314 
315    return wsi_get_swapchain_counter(
316       _device, &device->physical->wsi_device,
317       swapchain, flag_bits, value);
318 }
319