17ec681f3Smrg/*
27ec681f3Smrg * Copyright © 2017 Keith Packard
37ec681f3Smrg *
47ec681f3Smrg * Permission to use, copy, modify, distribute, and sell this software and its
57ec681f3Smrg * documentation for any purpose is hereby granted without fee, provided that
67ec681f3Smrg * the above copyright notice appear in all copies and that both that copyright
77ec681f3Smrg * notice and this permission notice appear in supporting documentation, and
87ec681f3Smrg * that the name of the copyright holders not be used in advertising or
97ec681f3Smrg * publicity pertaining to distribution of the software without specific,
107ec681f3Smrg * written prior permission.  The copyright holders make no representations
117ec681f3Smrg * about the suitability of this software for any purpose.  It is provided "as
127ec681f3Smrg * is" without express or implied warranty.
137ec681f3Smrg *
147ec681f3Smrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
157ec681f3Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
167ec681f3Smrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
177ec681f3Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
187ec681f3Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
197ec681f3Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
207ec681f3Smrg * OF THIS SOFTWARE.
217ec681f3Smrg */
227ec681f3Smrg
237ec681f3Smrg#include <stdbool.h>
247ec681f3Smrg#include <string.h>
257ec681f3Smrg#include <unistd.h>
267ec681f3Smrg#include <fcntl.h>
277ec681f3Smrg#include <sys/ioctl.h>
287ec681f3Smrg#include "tu_private.h"
297ec681f3Smrg#include "tu_cs.h"
307ec681f3Smrg#include "util/disk_cache.h"
317ec681f3Smrg#include "util/strtod.h"
327ec681f3Smrg#include "vk_util.h"
337ec681f3Smrg#include "vk_format.h"
347ec681f3Smrg#include "util/debug.h"
357ec681f3Smrg#include "wsi_common_display.h"
367ec681f3Smrg
377ec681f3Smrg/* VK_EXT_display_control */
387ec681f3Smrg
397ec681f3SmrgVKAPI_ATTR VkResult VKAPI_CALL
407ec681f3Smrgtu_RegisterDeviceEventEXT(VkDevice                    _device,
417ec681f3Smrg                          const VkDeviceEventInfoEXT  *device_event_info,
427ec681f3Smrg                          const VkAllocationCallbacks *allocator,
437ec681f3Smrg                          VkFence                     *out_fence)
447ec681f3Smrg{
457ec681f3Smrg   TU_FROM_HANDLE(tu_device, device, _device);
467ec681f3Smrg   VkResult ret;
477ec681f3Smrg
487ec681f3Smrg   VkFence _fence;
497ec681f3Smrg   ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, &_fence);
507ec681f3Smrg   if (ret != VK_SUCCESS)
517ec681f3Smrg      return ret;
527ec681f3Smrg
537ec681f3Smrg   TU_FROM_HANDLE(tu_syncobj, fence, _fence);
547ec681f3Smrg
557ec681f3Smrg   int sync_fd = tu_syncobj_to_fd(device, fence);
567ec681f3Smrg   if (sync_fd >= 0) {
577ec681f3Smrg      ret = wsi_register_device_event(_device,
587ec681f3Smrg                                      &device->physical_device->wsi_device,
597ec681f3Smrg                                      device_event_info,
607ec681f3Smrg                                      allocator,
617ec681f3Smrg                                      NULL,
627ec681f3Smrg                                      sync_fd);
637ec681f3Smrg
647ec681f3Smrg      close(sync_fd);
657ec681f3Smrg   } else {
667ec681f3Smrg      ret = VK_ERROR_OUT_OF_HOST_MEMORY;
677ec681f3Smrg   }
687ec681f3Smrg
697ec681f3Smrg   if (ret != VK_SUCCESS)
707ec681f3Smrg      tu_DestroyFence(_device, _fence, allocator);
717ec681f3Smrg   else
727ec681f3Smrg      *out_fence = _fence;
737ec681f3Smrg
747ec681f3Smrg   return ret;
757ec681f3Smrg}
767ec681f3Smrg
777ec681f3SmrgVKAPI_ATTR VkResult VKAPI_CALL
787ec681f3Smrgtu_RegisterDisplayEventEXT(VkDevice                           _device,
797ec681f3Smrg                           VkDisplayKHR                       display,
807ec681f3Smrg                           const VkDisplayEventInfoEXT        *display_event_info,
817ec681f3Smrg                           const VkAllocationCallbacks        *allocator,
827ec681f3Smrg                           VkFence                            *_fence)
837ec681f3Smrg{
847ec681f3Smrg   TU_FROM_HANDLE(tu_device, device, _device);
857ec681f3Smrg   VkResult ret;
867ec681f3Smrg
877ec681f3Smrg   ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, _fence);
887ec681f3Smrg   if (ret != VK_SUCCESS)
897ec681f3Smrg      return ret;
907ec681f3Smrg
917ec681f3Smrg   TU_FROM_HANDLE(tu_syncobj, fence, *_fence);
927ec681f3Smrg
937ec681f3Smrg   int sync_fd = tu_syncobj_to_fd(device, fence);
947ec681f3Smrg   if (sync_fd >= 0) {
957ec681f3Smrg      ret = wsi_register_display_event(_device,
967ec681f3Smrg                                       &device->physical_device->wsi_device,
977ec681f3Smrg                                       display,
987ec681f3Smrg                                       display_event_info,
997ec681f3Smrg                                       allocator,
1007ec681f3Smrg                                       NULL,
1017ec681f3Smrg                                       sync_fd);
1027ec681f3Smrg
1037ec681f3Smrg      close(sync_fd);
1047ec681f3Smrg   } else {
1057ec681f3Smrg      ret = VK_ERROR_OUT_OF_HOST_MEMORY;
1067ec681f3Smrg   }
1077ec681f3Smrg
1087ec681f3Smrg   if (ret != VK_SUCCESS)
1097ec681f3Smrg      tu_DestroyFence(_device, *_fence, allocator);
1107ec681f3Smrg
1117ec681f3Smrg   return ret;
1127ec681f3Smrg}
113