2021-03-03 15:06:41 +00:00
|
|
|
/*
|
2025-04-01 09:27:18 +00:00
|
|
|
* Copyright (c) 2021-2025 Arm Limited.
|
2021-03-03 15:06:41 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-10-14 11:21:53 +00:00
|
|
|
#ifndef __STDC_VERSION__
|
|
|
|
|
#define __STDC_VERSION__ 0
|
|
|
|
|
#endif
|
2021-03-03 15:06:41 +00:00
|
|
|
#include <wayland-client.h>
|
|
|
|
|
#include <linux-dmabuf-unstable-v1-client-protocol.h>
|
2021-09-01 22:30:31 +01:00
|
|
|
#include <linux-explicit-synchronization-unstable-v1-protocol.h>
|
2024-09-17 18:27:34 +01:00
|
|
|
#include <presentation-time-client-protocol.h>
|
2025-04-01 09:27:18 +00:00
|
|
|
#include <memory>
|
2021-09-01 22:30:31 +01:00
|
|
|
#include <functional>
|
2021-03-03 15:06:41 +00:00
|
|
|
|
|
|
|
|
namespace wsi
|
|
|
|
|
{
|
|
|
|
|
namespace wayland
|
|
|
|
|
{
|
|
|
|
|
|
2021-09-01 22:30:31 +01:00
|
|
|
static inline void wayland_object_destroy(wl_registry *obj)
|
2021-03-03 15:06:41 +00:00
|
|
|
{
|
2021-09-01 22:30:31 +01:00
|
|
|
wl_registry_destroy(obj);
|
|
|
|
|
}
|
2021-03-03 15:06:41 +00:00
|
|
|
|
2021-09-01 22:30:31 +01:00
|
|
|
static inline void wayland_object_destroy(zwp_linux_dmabuf_v1 *obj)
|
|
|
|
|
{
|
|
|
|
|
zwp_linux_dmabuf_v1_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void wayland_object_destroy(zwp_linux_explicit_synchronization_v1 *obj)
|
|
|
|
|
{
|
|
|
|
|
zwp_linux_explicit_synchronization_v1_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void wayland_object_destroy(zwp_linux_surface_synchronization_v1 *obj)
|
|
|
|
|
{
|
|
|
|
|
zwp_linux_surface_synchronization_v1_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 18:27:34 +01:00
|
|
|
static inline void wayland_object_destroy(wp_presentation *obj)
|
|
|
|
|
{
|
|
|
|
|
wp_presentation_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 12:21:59 +01:00
|
|
|
static inline void wayland_object_destroy(wl_callback *obj)
|
|
|
|
|
{
|
|
|
|
|
wl_callback_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void wayland_object_destroy(wl_event_queue *obj)
|
|
|
|
|
{
|
|
|
|
|
wl_event_queue_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 09:27:18 +00:00
|
|
|
static inline void wayland_object_destroy(struct wp_presentation_feedback *obj)
|
|
|
|
|
{
|
|
|
|
|
wp_presentation_feedback_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-20 13:55:45 +00:00
|
|
|
static inline void wayland_object_destroy(wl_buffer *obj)
|
|
|
|
|
{
|
|
|
|
|
wl_buffer_destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 22:30:31 +01:00
|
|
|
template <typename T>
|
|
|
|
|
struct wayland_deleter
|
2021-03-03 15:06:41 +00:00
|
|
|
{
|
2021-09-01 22:30:31 +01:00
|
|
|
void operator()(T *obj) const
|
2021-03-03 15:06:41 +00:00
|
|
|
{
|
|
|
|
|
if (obj != nullptr)
|
|
|
|
|
{
|
2021-09-01 22:30:31 +01:00
|
|
|
wayland_object_destroy(obj);
|
2021-03-03 15:06:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-04 10:30:42 +01:00
|
|
|
template <typename T>
|
2021-09-01 22:30:31 +01:00
|
|
|
using wayland_owner = std::unique_ptr<T, wayland_deleter<T>>;
|
2021-07-22 23:49:15 +01:00
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
static std::unique_ptr<T, std::function<void(T *)>> make_proxy_with_queue(T *object, wl_event_queue *queue)
|
|
|
|
|
{
|
|
|
|
|
auto proxy = reinterpret_cast<T *>(wl_proxy_create_wrapper(object));
|
|
|
|
|
if (proxy != nullptr)
|
|
|
|
|
{
|
|
|
|
|
wl_proxy_set_queue(reinterpret_cast<wl_proxy *>(proxy), queue);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 09:55:55 +00:00
|
|
|
auto delete_proxy = [](T *wrapped_proxy) { wl_proxy_wrapper_destroy(reinterpret_cast<wl_proxy *>(wrapped_proxy)); };
|
2021-07-22 23:49:15 +01:00
|
|
|
|
|
|
|
|
return std::unique_ptr<T, std::function<void(T *)>>(proxy, delete_proxy);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 15:06:41 +00:00
|
|
|
} // namespace wayland
|
|
|
|
|
} // namespace wsi
|