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
48 class surface : public wsi::surface
52 struct init_parameters;
54 /** Constructor to allow for custom allocation, but require privately defined arguments. */
55 surface(const init_parameters&);
58 * @brief Allocates and initializes a surface
60 * @param allocator An allocator to use for host allocations needed for the surface.
61 * @param display The Wayland display used to create the VkSurface
62 * @param surf The Wayland surface used to create the VkSurface
64 * @return A constructed and initalized surface or nullptr on failure
66 static util::unique_ptr<surface> make_surface(const util::allocator &allocator, wl_display *display,
72 wsi::surface_properties &get_properties() override;
73 util::unique_ptr<swapchain_base> allocate_swapchain(layer::device_private_data &dev_data,
74 const VkAllocationCallbacks *allocator) override;
76 /** Returns the Wayland display */
77 wl_display *get_wl_display() const
79 return wayland_display;
82 /** Returns the Wayland surface */
83 wl_surface *get_wl_surface() const
85 return wayland_surface;
89 * @brief Returns a pointer to the Wayland zwp_linux_dmabuf_v1 interface.
91 * The raw pointer is valid throughout the lifetime of this surface.
93 zwp_linux_dmabuf_v1 *get_dmabuf_interface()
95 return dmabuf_interface.get();
99 * @brief Returns a reference to a list of DRM formats supported by the Wayland surface.
101 * The reference is valid throughout the lifetime of this surface.
103 const util::vector<drm_format_pair> &get_formats() const
105 return supported_formats;
110 * @brief Initialize the WSI surface by creating Wayland queues and linking to Wayland protocols.
112 * @return true on success, false otherwise.
116 /** The native Wayland display */
117 wl_display *wayland_display;
118 /** The native Wayland surface */
119 wl_surface *wayland_surface;
120 /** A list of DRM formats supported by the Wayland compositor on this surface */
121 util::vector<drm_format_pair> supported_formats;
122 /** Surface properties specific to the Wayland surface. */
123 surface_properties properties;
125 /** Container for the zwp_linux_dmabuf_v1 interface binding */
126 zwp_linux_dmabuf_v1_owner dmabuf_interface;
127 /** Private queue for surface events generated by the layer */
128 wl_event_queue *surface_queue;
131 } // namespace wayland