semaphore_handle.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GPU_VULKAN_SEMAPHORE_HANDLE_H_
  5. #define GPU_VULKAN_SEMAPHORE_HANDLE_H_
  6. #include <vulkan/vulkan_core.h>
  7. #include <utility>
  8. #include "base/component_export.h"
  9. #include "build/build_config.h"
  10. #include "ui/gfx/gpu_fence_handle.h"
  11. #if BUILDFLAG(IS_POSIX)
  12. #include "base/files/scoped_file.h"
  13. #endif
  14. #if BUILDFLAG(IS_FUCHSIA)
  15. #include <lib/zx/event.h>
  16. #endif
  17. #if BUILDFLAG(IS_WIN)
  18. #include "base/win/scoped_handle.h"
  19. #endif
  20. namespace gpu {
  21. // Thin wrapper around platform-specific handles for VkSemaphores.
  22. // Note that handle transference depends on a handle type.
  23. // SYNC_FD handles that use copy transference, while reference transference is
  24. // used other handles types.
  25. class COMPONENT_EXPORT(VULKAN) SemaphoreHandle {
  26. public:
  27. #if BUILDFLAG(IS_POSIX)
  28. using PlatformHandle = base::ScopedFD;
  29. #elif BUILDFLAG(IS_WIN)
  30. using PlatformHandle = base::win::ScopedHandle;
  31. #elif BUILDFLAG(IS_FUCHSIA)
  32. using PlatformHandle = zx::event;
  33. #endif
  34. SemaphoreHandle();
  35. SemaphoreHandle(VkExternalSemaphoreHandleTypeFlagBits type,
  36. PlatformHandle handle);
  37. explicit SemaphoreHandle(gfx::GpuFenceHandle fence);
  38. SemaphoreHandle(SemaphoreHandle&&);
  39. SemaphoreHandle(const SemaphoreHandle&) = delete;
  40. SemaphoreHandle& operator=(const SemaphoreHandle&) = delete;
  41. ~SemaphoreHandle();
  42. SemaphoreHandle& operator=(SemaphoreHandle&&);
  43. VkExternalSemaphoreHandleTypeFlagBits vk_handle_type() { return type_; }
  44. bool is_valid() const {
  45. #if BUILDFLAG(IS_WIN)
  46. return handle_.IsValid();
  47. #else
  48. return handle_.is_valid();
  49. #endif
  50. }
  51. // Returns underlying platform-specific handle for the semaphore. is_valid()
  52. // becomes false after this function returns.
  53. PlatformHandle TakeHandle() { return std::move(handle_); }
  54. // Moves platform specific instances to gfx::GpuFenceHandle.
  55. gfx::GpuFenceHandle ToGpuFenceHandle() &&;
  56. SemaphoreHandle Duplicate() const;
  57. private:
  58. void Init(VkExternalSemaphoreHandleTypeFlagBits type, PlatformHandle handle);
  59. VkExternalSemaphoreHandleTypeFlagBits type_;
  60. PlatformHandle handle_;
  61. };
  62. } // namespace gpu
  63. #endif // GPU_VULKAN_SEMAPHORE_HANDLE_H_