1b8e80941Smrg/*
2b8e80941Smrg * Copyright © 2017 Keith Packard
3b8e80941Smrg *
4b8e80941Smrg * Permission to use, copy, modify, distribute, and sell this software and its
5b8e80941Smrg * documentation for any purpose is hereby granted without fee, provided that
6b8e80941Smrg * the above copyright notice appear in all copies and that both that copyright
7b8e80941Smrg * notice and this permission notice appear in supporting documentation, and
8b8e80941Smrg * that the name of the copyright holders not be used in advertising or
9b8e80941Smrg * publicity pertaining to distribution of the software without specific,
10b8e80941Smrg * written prior permission.  The copyright holders make no representations
11b8e80941Smrg * about the suitability of this software for any purpose.  It is provided "as
12b8e80941Smrg * is" without express or implied warranty.
13b8e80941Smrg *
14b8e80941Smrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15b8e80941Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16b8e80941Smrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17b8e80941Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18b8e80941Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19b8e80941Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20b8e80941Smrg * OF THIS SOFTWARE.
21b8e80941Smrg */
22b8e80941Smrg
23b8e80941Smrg#include "anv_private.h"
24b8e80941Smrg#include "wsi_common.h"
25b8e80941Smrg#include "vk_format_info.h"
26b8e80941Smrg#include "vk_util.h"
27b8e80941Smrg#include "wsi_common_display.h"
28b8e80941Smrg
29b8e80941SmrgVkResult
30b8e80941Smrganv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,
31b8e80941Smrg                                          uint32_t *property_count,
32b8e80941Smrg                                          VkDisplayPropertiesKHR *properties)
33b8e80941Smrg{
34b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
35b8e80941Smrg
36b8e80941Smrg   return wsi_display_get_physical_device_display_properties(
37b8e80941Smrg      physical_device,
38b8e80941Smrg      &pdevice->wsi_device,
39b8e80941Smrg      property_count,
40b8e80941Smrg      properties);
41b8e80941Smrg}
42b8e80941Smrg
43b8e80941SmrgVkResult
44b8e80941Smrganv_GetPhysicalDeviceDisplayProperties2KHR(
45b8e80941Smrg    VkPhysicalDevice                            physicalDevice,
46b8e80941Smrg    uint32_t*                                   pPropertyCount,
47b8e80941Smrg    VkDisplayProperties2KHR*                    pProperties)
48b8e80941Smrg{
49b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
50b8e80941Smrg
51b8e80941Smrg   return wsi_display_get_physical_device_display_properties2(
52b8e80941Smrg      physicalDevice, &pdevice->wsi_device,
53b8e80941Smrg      pPropertyCount, pProperties);
54b8e80941Smrg}
55b8e80941Smrg
56b8e80941SmrgVkResult
57b8e80941Smrganv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
58b8e80941Smrg   VkPhysicalDevice physical_device,
59b8e80941Smrg   uint32_t *property_count,
60b8e80941Smrg   VkDisplayPlanePropertiesKHR *properties)
61b8e80941Smrg{
62b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
63b8e80941Smrg
64b8e80941Smrg   return wsi_display_get_physical_device_display_plane_properties(
65b8e80941Smrg      physical_device, &pdevice->wsi_device,
66b8e80941Smrg      property_count, properties);
67b8e80941Smrg}
68b8e80941Smrg
69b8e80941SmrgVkResult
70b8e80941Smrganv_GetPhysicalDeviceDisplayPlaneProperties2KHR(
71b8e80941Smrg    VkPhysicalDevice                            physicalDevice,
72b8e80941Smrg    uint32_t*                                   pPropertyCount,
73b8e80941Smrg    VkDisplayPlaneProperties2KHR*               pProperties)
74b8e80941Smrg{
75b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
76b8e80941Smrg
77b8e80941Smrg   return wsi_display_get_physical_device_display_plane_properties2(
78b8e80941Smrg      physicalDevice, &pdevice->wsi_device,
79b8e80941Smrg      pPropertyCount, pProperties);
80b8e80941Smrg}
81b8e80941Smrg
82b8e80941SmrgVkResult
83b8e80941Smrganv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,
84b8e80941Smrg                                        uint32_t plane_index,
85b8e80941Smrg                                        uint32_t *display_count,
86b8e80941Smrg                                        VkDisplayKHR *displays)
87b8e80941Smrg{
88b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
89b8e80941Smrg
90b8e80941Smrg   return wsi_display_get_display_plane_supported_displays(physical_device,
91b8e80941Smrg                                                           &pdevice->wsi_device,
92b8e80941Smrg                                                           plane_index,
93b8e80941Smrg                                                           display_count,
94b8e80941Smrg                                                           displays);
95b8e80941Smrg}
96b8e80941Smrg
97b8e80941Smrg
98b8e80941SmrgVkResult
99b8e80941Smrganv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,
100b8e80941Smrg                                VkDisplayKHR display,
101b8e80941Smrg                                uint32_t *property_count,
102b8e80941Smrg                                VkDisplayModePropertiesKHR *properties)
103b8e80941Smrg{
104b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
105b8e80941Smrg
106b8e80941Smrg   return wsi_display_get_display_mode_properties(physical_device,
107b8e80941Smrg                                                  &pdevice->wsi_device,
108b8e80941Smrg                                                  display,
109b8e80941Smrg                                                  property_count,
110b8e80941Smrg                                                  properties);
111b8e80941Smrg}
112b8e80941Smrg
113b8e80941SmrgVkResult
114b8e80941Smrganv_GetDisplayModeProperties2KHR(
115b8e80941Smrg    VkPhysicalDevice                            physicalDevice,
116b8e80941Smrg    VkDisplayKHR                                display,
117b8e80941Smrg    uint32_t*                                   pPropertyCount,
118b8e80941Smrg    VkDisplayModeProperties2KHR*                pProperties)
119b8e80941Smrg{
120b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
121b8e80941Smrg
122b8e80941Smrg   return wsi_display_get_display_mode_properties2(physicalDevice,
123b8e80941Smrg                                                   &pdevice->wsi_device,
124b8e80941Smrg                                                   display,
125b8e80941Smrg                                                   pPropertyCount,
126b8e80941Smrg                                                   pProperties);
127b8e80941Smrg}
128b8e80941Smrg
129b8e80941SmrgVkResult
130b8e80941Smrganv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,
131b8e80941Smrg                         VkDisplayKHR display,
132b8e80941Smrg                         const VkDisplayModeCreateInfoKHR *create_info,
133b8e80941Smrg                         const VkAllocationCallbacks *allocator,
134b8e80941Smrg                         VkDisplayModeKHR *mode)
135b8e80941Smrg{
136b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
137b8e80941Smrg
138b8e80941Smrg   return wsi_display_create_display_mode(physical_device,
139b8e80941Smrg                                          &pdevice->wsi_device,
140b8e80941Smrg                                          display,
141b8e80941Smrg                                          create_info,
142b8e80941Smrg                                          allocator,
143b8e80941Smrg                                          mode);
144b8e80941Smrg}
145b8e80941Smrg
146b8e80941SmrgVkResult
147b8e80941Smrganv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,
148b8e80941Smrg                                   VkDisplayModeKHR mode_khr,
149b8e80941Smrg                                   uint32_t plane_index,
150b8e80941Smrg                                   VkDisplayPlaneCapabilitiesKHR *capabilities)
151b8e80941Smrg{
152b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
153b8e80941Smrg
154b8e80941Smrg   return wsi_get_display_plane_capabilities(physical_device,
155b8e80941Smrg                                             &pdevice->wsi_device,
156b8e80941Smrg                                             mode_khr,
157b8e80941Smrg                                             plane_index,
158b8e80941Smrg                                             capabilities);
159b8e80941Smrg}
160b8e80941Smrg
161b8e80941SmrgVkResult
162b8e80941Smrganv_GetDisplayPlaneCapabilities2KHR(
163b8e80941Smrg    VkPhysicalDevice                            physicalDevice,
164b8e80941Smrg    const VkDisplayPlaneInfo2KHR*               pDisplayPlaneInfo,
165b8e80941Smrg    VkDisplayPlaneCapabilities2KHR*             pCapabilities)
166b8e80941Smrg{
167b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
168b8e80941Smrg
169b8e80941Smrg   return wsi_get_display_plane_capabilities2(physicalDevice,
170b8e80941Smrg                                              &pdevice->wsi_device,
171b8e80941Smrg                                              pDisplayPlaneInfo,
172b8e80941Smrg                                              pCapabilities);
173b8e80941Smrg}
174b8e80941Smrg
175b8e80941SmrgVkResult
176b8e80941Smrganv_CreateDisplayPlaneSurfaceKHR(
177b8e80941Smrg   VkInstance _instance,
178b8e80941Smrg   const VkDisplaySurfaceCreateInfoKHR *create_info,
179b8e80941Smrg   const VkAllocationCallbacks *allocator,
180b8e80941Smrg   VkSurfaceKHR *surface)
181b8e80941Smrg{
182b8e80941Smrg   ANV_FROM_HANDLE(anv_instance, instance, _instance);
183b8e80941Smrg   const VkAllocationCallbacks *alloc;
184b8e80941Smrg
185b8e80941Smrg   if (allocator)
186b8e80941Smrg     alloc = allocator;
187b8e80941Smrg   else
188b8e80941Smrg     alloc = &instance->alloc;
189b8e80941Smrg
190b8e80941Smrg   return wsi_create_display_surface(_instance, alloc, create_info, surface);
191b8e80941Smrg}
192b8e80941Smrg
193b8e80941SmrgVkResult
194b8e80941Smrganv_ReleaseDisplayEXT(VkPhysicalDevice physical_device,
195b8e80941Smrg                       VkDisplayKHR     display)
196b8e80941Smrg{
197b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
198b8e80941Smrg
199b8e80941Smrg   return wsi_release_display(physical_device,
200b8e80941Smrg                              &pdevice->wsi_device,
201b8e80941Smrg                              display);
202b8e80941Smrg}
203b8e80941Smrg
204b8e80941Smrg#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
205b8e80941SmrgVkResult
206b8e80941Smrganv_AcquireXlibDisplayEXT(VkPhysicalDevice     physical_device,
207b8e80941Smrg                           Display              *dpy,
208b8e80941Smrg                           VkDisplayKHR         display)
209b8e80941Smrg{
210b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
211b8e80941Smrg
212b8e80941Smrg   return wsi_acquire_xlib_display(physical_device,
213b8e80941Smrg                                   &pdevice->wsi_device,
214b8e80941Smrg                                   dpy,
215b8e80941Smrg                                   display);
216b8e80941Smrg}
217b8e80941Smrg
218b8e80941SmrgVkResult
219b8e80941Smrganv_GetRandROutputDisplayEXT(VkPhysicalDevice  physical_device,
220b8e80941Smrg                              Display           *dpy,
221b8e80941Smrg                              RROutput          output,
222b8e80941Smrg                              VkDisplayKHR      *display)
223b8e80941Smrg{
224b8e80941Smrg   ANV_FROM_HANDLE(anv_physical_device, pdevice, physical_device);
225b8e80941Smrg
226b8e80941Smrg   return wsi_get_randr_output_display(physical_device,
227b8e80941Smrg                                       &pdevice->wsi_device,
228b8e80941Smrg                                       dpy,
229b8e80941Smrg                                       output,
230b8e80941Smrg                                       display);
231b8e80941Smrg}
232b8e80941Smrg#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */
233b8e80941Smrg
234b8e80941Smrg/* VK_EXT_display_control */
235b8e80941Smrg
236b8e80941SmrgVkResult
237b8e80941Smrganv_DisplayPowerControlEXT(VkDevice                    _device,
238b8e80941Smrg                            VkDisplayKHR                display,
239b8e80941Smrg                            const VkDisplayPowerInfoEXT *display_power_info)
240b8e80941Smrg{
241b8e80941Smrg   ANV_FROM_HANDLE(anv_device, device, _device);
242b8e80941Smrg
243b8e80941Smrg   return wsi_display_power_control(
244b8e80941Smrg      _device, &device->instance->physicalDevice.wsi_device,
245b8e80941Smrg      display, display_power_info);
246b8e80941Smrg}
247b8e80941Smrg
248b8e80941SmrgVkResult
249b8e80941Smrganv_RegisterDeviceEventEXT(VkDevice _device,
250b8e80941Smrg                            const VkDeviceEventInfoEXT *device_event_info,
251b8e80941Smrg                            const VkAllocationCallbacks *allocator,
252b8e80941Smrg                            VkFence *_fence)
253b8e80941Smrg{
254b8e80941Smrg   ANV_FROM_HANDLE(anv_device, device, _device);
255b8e80941Smrg   struct anv_fence *fence;
256b8e80941Smrg   VkResult ret;
257b8e80941Smrg
258b8e80941Smrg   fence = vk_zalloc2(&device->instance->alloc, allocator, sizeof (*fence), 8,
259b8e80941Smrg                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
260b8e80941Smrg   if (!fence)
261b8e80941Smrg      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
262b8e80941Smrg
263b8e80941Smrg   fence->permanent.type = ANV_FENCE_TYPE_WSI;
264b8e80941Smrg
265b8e80941Smrg   ret = wsi_register_device_event(_device,
266b8e80941Smrg                                   &device->instance->physicalDevice.wsi_device,
267b8e80941Smrg                                   device_event_info,
268b8e80941Smrg                                   allocator,
269b8e80941Smrg                                   &fence->permanent.fence_wsi);
270b8e80941Smrg   if (ret == VK_SUCCESS)
271b8e80941Smrg      *_fence = anv_fence_to_handle(fence);
272b8e80941Smrg   else
273b8e80941Smrg      vk_free2(&device->instance->alloc, allocator, fence);
274b8e80941Smrg   return ret;
275b8e80941Smrg}
276b8e80941Smrg
277b8e80941SmrgVkResult
278b8e80941Smrganv_RegisterDisplayEventEXT(VkDevice _device,
279b8e80941Smrg                             VkDisplayKHR display,
280b8e80941Smrg                             const VkDisplayEventInfoEXT *display_event_info,
281b8e80941Smrg                             const VkAllocationCallbacks *allocator,
282b8e80941Smrg                             VkFence *_fence)
283b8e80941Smrg{
284b8e80941Smrg   ANV_FROM_HANDLE(anv_device, device, _device);
285b8e80941Smrg   struct anv_fence *fence;
286b8e80941Smrg   VkResult ret;
287b8e80941Smrg
288b8e80941Smrg   fence = vk_zalloc2(&device->alloc, allocator, sizeof (*fence), 8,
289b8e80941Smrg                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
290b8e80941Smrg   if (!fence)
291b8e80941Smrg      return VK_ERROR_OUT_OF_HOST_MEMORY;
292b8e80941Smrg
293b8e80941Smrg   fence->permanent.type = ANV_FENCE_TYPE_WSI;
294b8e80941Smrg
295b8e80941Smrg   ret = wsi_register_display_event(
296b8e80941Smrg      _device, &device->instance->physicalDevice.wsi_device,
297b8e80941Smrg      display, display_event_info, allocator, &(fence->permanent.fence_wsi));
298b8e80941Smrg
299b8e80941Smrg   if (ret == VK_SUCCESS)
300b8e80941Smrg      *_fence = anv_fence_to_handle(fence);
301b8e80941Smrg   else
302b8e80941Smrg      vk_free2(&device->alloc, allocator, fence);
303b8e80941Smrg   return ret;
304b8e80941Smrg}
305b8e80941Smrg
306b8e80941SmrgVkResult
307b8e80941Smrganv_GetSwapchainCounterEXT(VkDevice _device,
308b8e80941Smrg                            VkSwapchainKHR swapchain,
309b8e80941Smrg                            VkSurfaceCounterFlagBitsEXT flag_bits,
310b8e80941Smrg                            uint64_t *value)
311b8e80941Smrg{
312b8e80941Smrg   ANV_FROM_HANDLE(anv_device, device, _device);
313b8e80941Smrg
314b8e80941Smrg   return wsi_get_swapchain_counter(
315b8e80941Smrg      _device, &device->instance->physicalDevice.wsi_device,
316b8e80941Smrg      swapchain, flag_bits, value);
317b8e80941Smrg}
318