2 * Copyright (c) 2021 Arm Limited.
4 * SPDX-License-Identifier: MIT
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * @brief Definitions for a Wayland WSI Surface
31 #include <wayland-client.h>
33 #include "wsi/surface.hpp"
34 #include "surface_properties.hpp"
35 #include "wl_object_owner.hpp"
42 struct drm_format_pair
49 * Wayland callback for global wl_registry events to handle global objects required by @ref wsi::wayland::surface
51 extern "C" void surface_registry_handler(void *data, struct wl_registry *wl_registry, uint32_t name,
52 const char *interface, uint32_t version);
54 class surface : public wsi::surface
58 struct init_parameters;
60 /** Constructor to allow for custom allocation, but require privately defined arguments. */
61 surface(const init_parameters&);
64 * @brief Allocates and initializes a surface
66 * @param allocator An allocator to use for host allocations needed for the surface.
67 * @param display The Wayland display used to create the VkSurface
68 * @param surf The Wayland surface used to create the VkSurface
70 * @return A constructed and initalized surface or nullptr on failure
72 static util::unique_ptr<surface> make_surface(const util::allocator &allocator, wl_display *display,
78 wsi::surface_properties &get_properties() override;
79 util::unique_ptr<swapchain_base> allocate_swapchain(layer::device_private_data &dev_data,
80 const VkAllocationCallbacks *allocator) override;
82 /** Returns the Wayland display */
83 wl_display *get_wl_display() const
85 return wayland_display;
88 /** Returns the Wayland surface */
89 wl_surface *get_wl_surface() const
91 return wayland_surface;
95 * @brief Returns a pointer to the Wayland zwp_linux_dmabuf_v1 interface.
97 * The raw pointer is valid throughout the lifetime of this surface.
99 zwp_linux_dmabuf_v1 *get_dmabuf_interface()
101 return dmabuf_interface.get();
105 * @brief Returns a pointer to the Wayland zwp_linux_surface_synchronization_v1 interface obtained for the wayland
108 * The raw pointer is valid for the lifetime of the surface.
110 zwp_linux_surface_synchronization_v1* get_surface_sync_interface()
112 return surface_sync_interface.get();
116 * @brief Returns a reference to a list of DRM formats supported by the Wayland surface.
118 * The reference is valid throughout the lifetime of this surface.
120 const util::vector<drm_format_pair> &get_formats() const
122 return supported_formats;
127 * @brief Initialize the WSI surface by creating Wayland queues and linking to Wayland protocols.
129 * @return true on success, false otherwise.
133 friend void surface_registry_handler(void *data, struct wl_registry *wl_registry, uint32_t name,
134 const char *interface, uint32_t version);
136 /** The native Wayland display */
137 wl_display *wayland_display;
138 /** The native Wayland surface */
139 wl_surface *wayland_surface;
140 /** A list of DRM formats supported by the Wayland compositor on this surface */
141 util::vector<drm_format_pair> supported_formats;
142 /** Surface properties specific to the Wayland surface. */
143 surface_properties properties;
145 /** Container for the zwp_linux_dmabuf_v1 interface binding */
146 wayland_owner<zwp_linux_dmabuf_v1> dmabuf_interface;
148 /** Container for the zwp_linux_explicit_synchronization_v1 interface binding */
149 wayland_owner<zwp_linux_explicit_synchronization_v1> explicit_sync_interface;
150 /** Container for the surface specific zwp_linux_surface_synchronization_v1 interface. */
151 wayland_owner<zwp_linux_surface_synchronization_v1> surface_sync_interface;
153 /** Private queue for surface events generated by the layer */
154 wl_event_queue *surface_queue;
157 } // namespace wayland