2021-07-21 20:19:52 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021 Arm Limited.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
|
* @brief Definitions for a Wayland WSI Surface
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-07-22 23:49:15 +01:00
|
|
|
#include <wayland-client.h>
|
|
|
|
|
|
2021-07-21 20:19:52 +01:00
|
|
|
#include "wsi/surface.hpp"
|
2021-07-22 23:49:15 +01:00
|
|
|
#include "surface_properties.hpp"
|
|
|
|
|
#include "wl_object_owner.hpp"
|
2021-07-21 20:19:52 +01:00
|
|
|
|
|
|
|
|
namespace wsi
|
|
|
|
|
{
|
|
|
|
|
namespace wayland
|
|
|
|
|
{
|
|
|
|
|
|
2021-07-22 23:49:15 +01:00
|
|
|
struct drm_format_pair
|
|
|
|
|
{
|
|
|
|
|
uint32_t fourcc;
|
|
|
|
|
uint64_t modifier;
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-21 20:19:52 +01:00
|
|
|
class surface : public wsi::surface
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-07-22 23:49:15 +01:00
|
|
|
surface() = delete;
|
|
|
|
|
struct init_parameters;
|
|
|
|
|
|
|
|
|
|
/** Constructor to allow for custom allocation, but require privately defined arguments. */
|
|
|
|
|
surface(const init_parameters&);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Allocates and initializes a surface
|
|
|
|
|
*
|
|
|
|
|
* @param allocator An allocator to use for host allocations needed for the surface.
|
|
|
|
|
* @param display The Wayland display used to create the VkSurface
|
|
|
|
|
* @param surf The Wayland surface used to create the VkSurface
|
|
|
|
|
*
|
|
|
|
|
* @return A constructed and initalized surface or nullptr on failure
|
|
|
|
|
*/
|
|
|
|
|
static util::unique_ptr<surface> make_surface(const util::allocator &allocator, wl_display *display,
|
|
|
|
|
wl_surface *surf);
|
|
|
|
|
|
|
|
|
|
/** Destructor */
|
|
|
|
|
~surface() override;
|
2021-07-21 20:19:52 +01:00
|
|
|
|
|
|
|
|
wsi::surface_properties &get_properties() override;
|
|
|
|
|
util::unique_ptr<swapchain_base> allocate_swapchain(layer::device_private_data &dev_data,
|
|
|
|
|
const VkAllocationCallbacks *allocator) override;
|
2021-07-22 23:49:15 +01:00
|
|
|
|
|
|
|
|
/** Returns the Wayland display */
|
|
|
|
|
wl_display *get_wl_display() const
|
|
|
|
|
{
|
|
|
|
|
return wayland_display;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns the Wayland surface */
|
|
|
|
|
wl_surface *get_wl_surface() const
|
|
|
|
|
{
|
|
|
|
|
return wayland_surface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Returns a pointer to the Wayland zwp_linux_dmabuf_v1 interface.
|
|
|
|
|
*
|
|
|
|
|
* The raw pointer is valid throughout the lifetime of this surface.
|
|
|
|
|
*/
|
|
|
|
|
zwp_linux_dmabuf_v1 *get_dmabuf_interface()
|
|
|
|
|
{
|
|
|
|
|
return dmabuf_interface.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Returns a reference to a list of DRM formats supported by the Wayland surface.
|
|
|
|
|
*
|
|
|
|
|
* The reference is valid throughout the lifetime of this surface.
|
|
|
|
|
*/
|
|
|
|
|
const util::vector<drm_format_pair> &get_formats() const
|
|
|
|
|
{
|
|
|
|
|
return supported_formats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* @brief Initialize the WSI surface by creating Wayland queues and linking to Wayland protocols.
|
|
|
|
|
*
|
|
|
|
|
* @return true on success, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
|
|
/** The native Wayland display */
|
|
|
|
|
wl_display *wayland_display;
|
|
|
|
|
/** The native Wayland surface */
|
|
|
|
|
wl_surface *wayland_surface;
|
|
|
|
|
/** A list of DRM formats supported by the Wayland compositor on this surface */
|
|
|
|
|
util::vector<drm_format_pair> supported_formats;
|
|
|
|
|
/** Surface properties specific to the Wayland surface. */
|
|
|
|
|
surface_properties properties;
|
|
|
|
|
|
|
|
|
|
/** Container for the zwp_linux_dmabuf_v1 interface binding */
|
|
|
|
|
zwp_linux_dmabuf_v1_owner dmabuf_interface;
|
|
|
|
|
/** Private queue for surface events generated by the layer */
|
|
|
|
|
wl_event_queue *surface_queue;
|
2021-07-21 20:19:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace wayland
|
|
|
|
|
} // namespace wsi
|