2020-01-24 23:31:01 +01:00
|
|
|
#ifndef SCREENCAST_COMMON_H
|
|
|
|
#define SCREENCAST_COMMON_H
|
|
|
|
|
2021-06-22 03:07:51 +02:00
|
|
|
#include <gbm.h>
|
2020-01-24 23:31:01 +01:00
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
#include <spa/param/video/format-utils.h>
|
|
|
|
#include <wayland-client-protocol.h>
|
2022-05-05 23:41:53 +02:00
|
|
|
#include <xf86drm.h>
|
2022-12-04 22:12:57 +01:00
|
|
|
#include "hyprland-toplevel-export-v1-client-protocol.h"
|
2020-01-24 23:31:01 +01:00
|
|
|
|
2020-12-23 19:47:10 +01:00
|
|
|
#include "fps_limit.h"
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
// this seems to be right based on
|
|
|
|
// https://github.com/flatpak/xdg-desktop-portal/blob/309a1fc0cf2fb32cceb91dbc666d20cf0a3202c2/src/screen-cast.c#L955
|
|
|
|
#define XDP_CAST_PROTO_VER 2
|
|
|
|
|
|
|
|
enum cursor_modes {
|
|
|
|
HIDDEN = 1,
|
|
|
|
EMBEDDED = 2,
|
|
|
|
METADATA = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum source_types {
|
|
|
|
MONITOR = 1,
|
|
|
|
WINDOW = 2,
|
|
|
|
};
|
|
|
|
|
2021-06-17 21:51:16 +02:00
|
|
|
enum buffer_type {
|
|
|
|
WL_SHM = 0,
|
|
|
|
DMABUF = 1,
|
|
|
|
};
|
|
|
|
|
2020-10-10 16:20:06 +02:00
|
|
|
enum xdpw_chooser_types {
|
|
|
|
XDPW_CHOOSER_DEFAULT,
|
|
|
|
XDPW_CHOOSER_NONE,
|
|
|
|
XDPW_CHOOSER_SIMPLE,
|
|
|
|
XDPW_CHOOSER_DMENU,
|
|
|
|
};
|
|
|
|
|
2021-08-18 22:33:27 +02:00
|
|
|
enum xdpw_frame_state {
|
|
|
|
XDPW_FRAME_STATE_NONE,
|
2022-03-03 00:25:42 +01:00
|
|
|
XDPW_FRAME_STATE_STARTED,
|
2021-08-18 22:33:27 +02:00
|
|
|
XDPW_FRAME_STATE_RENEG,
|
|
|
|
XDPW_FRAME_STATE_FAILED,
|
|
|
|
XDPW_FRAME_STATE_SUCCESS,
|
|
|
|
};
|
|
|
|
|
2020-10-10 16:20:06 +02:00
|
|
|
struct xdpw_output_chooser {
|
|
|
|
enum xdpw_chooser_types type;
|
|
|
|
char *cmd;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_frame_damage {
|
2020-01-24 23:31:01 +01:00
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_frame {
|
2021-06-16 02:38:44 +02:00
|
|
|
bool y_invert;
|
|
|
|
uint64_t tv_sec;
|
|
|
|
uint32_t tv_nsec;
|
|
|
|
struct xdpw_frame_damage damage;
|
2022-03-02 01:57:11 +01:00
|
|
|
struct xdpw_buffer *xdpw_buffer;
|
2022-03-02 17:57:07 +01:00
|
|
|
struct pw_buffer *pw_buffer;
|
2021-06-16 02:38:44 +02:00
|
|
|
};
|
|
|
|
|
2022-03-03 00:32:57 +01:00
|
|
|
struct xdpw_screencopy_frame_info {
|
2020-01-24 23:31:01 +01:00
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t stride;
|
2021-06-17 23:18:24 +02:00
|
|
|
uint32_t format;
|
2020-01-24 23:31:01 +01:00
|
|
|
};
|
|
|
|
|
2022-03-02 01:57:11 +01:00
|
|
|
struct xdpw_buffer {
|
|
|
|
struct wl_list link;
|
2021-06-17 21:51:16 +02:00
|
|
|
enum buffer_type buffer_type;
|
2022-03-02 01:57:11 +01:00
|
|
|
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
2021-06-17 23:18:24 +02:00
|
|
|
uint32_t format;
|
2022-04-16 02:23:13 +02:00
|
|
|
int plane_count;
|
2022-03-02 01:57:11 +01:00
|
|
|
|
2022-04-16 02:23:13 +02:00
|
|
|
int fd[4];
|
|
|
|
uint32_t size[4];
|
|
|
|
uint32_t stride[4];
|
|
|
|
uint32_t offset[4];
|
2022-03-02 01:57:11 +01:00
|
|
|
|
2021-06-22 03:49:13 +02:00
|
|
|
struct gbm_bo *bo;
|
|
|
|
|
2022-03-02 01:57:11 +01:00
|
|
|
struct wl_buffer *buffer;
|
|
|
|
};
|
|
|
|
|
2021-07-10 19:06:55 +02:00
|
|
|
struct xdpw_format_modifier_pair {
|
|
|
|
uint32_t fourcc;
|
|
|
|
uint64_t modifier;
|
|
|
|
};
|
|
|
|
|
2022-05-05 23:41:53 +02:00
|
|
|
struct xdpw_dmabuf_feedback_data {
|
|
|
|
void *format_table_data;
|
|
|
|
uint32_t format_table_size;
|
|
|
|
bool device_used;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_screencast_context {
|
|
|
|
|
|
|
|
// xdpw
|
|
|
|
struct xdpw_state *state;
|
|
|
|
|
2020-01-24 23:31:01 +01:00
|
|
|
// pipewire
|
2020-03-13 23:19:19 +01:00
|
|
|
struct pw_context *pwr_context;
|
2020-01-24 23:31:01 +01:00
|
|
|
struct pw_core *core;
|
|
|
|
|
|
|
|
// wlroots
|
|
|
|
struct wl_list output_list;
|
|
|
|
struct wl_registry *registry;
|
|
|
|
struct zwlr_screencopy_manager_v1 *screencopy_manager;
|
2020-12-23 19:47:10 +01:00
|
|
|
struct zxdg_output_manager_v1 *xdg_output_manager;
|
2020-01-24 23:31:01 +01:00
|
|
|
struct wl_shm *shm;
|
2021-06-17 23:56:47 +02:00
|
|
|
struct zwp_linux_dmabuf_v1 *linux_dmabuf;
|
2022-05-05 23:41:53 +02:00
|
|
|
struct zwp_linux_dmabuf_feedback_v1 *linux_dmabuf_feedback;
|
|
|
|
struct xdpw_dmabuf_feedback_data feedback_data;
|
2022-05-25 21:27:25 +02:00
|
|
|
struct wl_array format_modifier_pairs;
|
2020-01-24 23:31:01 +01:00
|
|
|
|
2022-12-04 22:12:57 +01:00
|
|
|
// hyprland
|
|
|
|
struct hyprland_toplevel_export_manager_v1 *hyprland_toplevel_manager;
|
2022-12-10 21:19:22 +01:00
|
|
|
struct zwlr_foreign_toplevel_manager_v1 *wlroots_toplevel_manager;
|
|
|
|
struct wl_list toplevel_resource_list;
|
2022-12-04 22:12:57 +01:00
|
|
|
|
2021-06-22 03:07:51 +02:00
|
|
|
// gbm
|
|
|
|
struct gbm_device *gbm;
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
// sessions
|
|
|
|
struct wl_list screencast_instances;
|
|
|
|
};
|
|
|
|
|
2022-12-03 23:42:21 +01:00
|
|
|
struct xdpw_wlr_output {
|
|
|
|
struct wl_list link;
|
|
|
|
uint32_t id;
|
|
|
|
struct wl_output *output;
|
|
|
|
struct zxdg_output_v1 *xdg_output;
|
|
|
|
char *make;
|
|
|
|
char *model;
|
|
|
|
char *name;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
float framerate;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xdpw_share {
|
|
|
|
struct xdpw_wlr_output *output;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
2022-12-04 22:12:57 +01:00
|
|
|
int window_handle;
|
2022-12-03 23:42:21 +01:00
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_screencast_instance {
|
|
|
|
// list
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
// xdpw
|
|
|
|
uint32_t refcount;
|
|
|
|
struct xdpw_screencast_context *ctx;
|
|
|
|
bool initialized;
|
2021-06-16 02:38:44 +02:00
|
|
|
struct xdpw_frame current_frame;
|
2021-08-18 22:33:27 +02:00
|
|
|
enum xdpw_frame_state frame_state;
|
2022-03-02 01:57:11 +01:00
|
|
|
struct wl_list buffer_list;
|
2022-04-24 14:38:44 +02:00
|
|
|
bool avoid_dmabufs;
|
2020-04-16 10:21:55 +02:00
|
|
|
|
|
|
|
// pipewire
|
|
|
|
struct pw_stream *stream;
|
|
|
|
struct spa_hook stream_listener;
|
|
|
|
struct spa_video_info_raw pwr_format;
|
|
|
|
uint32_t seq;
|
|
|
|
uint32_t node_id;
|
|
|
|
bool pwr_stream_state;
|
2021-06-13 20:33:34 +02:00
|
|
|
uint32_t framerate;
|
2020-04-16 10:21:55 +02:00
|
|
|
|
|
|
|
// wlroots
|
|
|
|
struct zwlr_screencopy_frame_v1 *frame_callback;
|
2022-12-03 23:42:21 +01:00
|
|
|
struct xdpw_share target;
|
2021-06-13 19:04:19 +02:00
|
|
|
uint32_t max_framerate;
|
2020-04-16 10:21:55 +02:00
|
|
|
struct zwlr_screencopy_frame_v1 *wlr_frame;
|
2021-06-17 21:51:16 +02:00
|
|
|
struct xdpw_screencopy_frame_info screencopy_frame_info[2];
|
2020-04-16 10:21:55 +02:00
|
|
|
bool with_cursor;
|
2020-01-24 23:31:01 +01:00
|
|
|
int err;
|
|
|
|
bool quit;
|
2021-12-27 10:16:28 +01:00
|
|
|
bool teardown;
|
2021-06-17 21:51:16 +02:00
|
|
|
enum buffer_type buffer_type;
|
2020-12-23 19:47:10 +01:00
|
|
|
|
2022-12-04 22:12:57 +01:00
|
|
|
// hyprland
|
|
|
|
struct hyprland_toplevel_export_frame_v1 *frame_callback_hyprland;
|
|
|
|
struct hyprland_toplevel_export_frame_v1 *hyprland_frame;
|
|
|
|
|
2020-12-23 19:47:10 +01:00
|
|
|
// fps limit
|
|
|
|
struct fps_limit_state fps_limit;
|
2020-01-24 23:31:01 +01:00
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
void randname(char *buf);
|
2022-05-05 23:41:53 +02:00
|
|
|
struct gbm_device *xdpw_gbm_device_create(drmDevice *device);
|
2022-03-02 01:57:11 +01:00
|
|
|
struct xdpw_buffer *xdpw_buffer_create(struct xdpw_screencast_instance *cast,
|
2021-06-17 21:51:16 +02:00
|
|
|
enum buffer_type buffer_type, struct xdpw_screencopy_frame_info *frame_info);
|
2022-03-02 01:57:11 +01:00
|
|
|
void xdpw_buffer_destroy(struct xdpw_buffer *buffer);
|
2021-07-10 23:24:49 +02:00
|
|
|
bool wlr_query_dmabuf_modifiers(struct xdpw_screencast_context *ctx, uint32_t drm_format,
|
|
|
|
uint32_t num_modifiers, uint64_t *modifiers, uint32_t *max_modifiers);
|
2021-06-17 23:18:24 +02:00
|
|
|
enum wl_shm_format xdpw_format_wl_shm_from_drm_fourcc(uint32_t format);
|
|
|
|
uint32_t xdpw_format_drm_fourcc_from_wl_shm(enum wl_shm_format format);
|
|
|
|
enum spa_video_format xdpw_format_pw_from_drm_fourcc(uint32_t format);
|
2020-05-03 16:33:45 +02:00
|
|
|
enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format);
|
2020-01-24 23:31:01 +01:00
|
|
|
|
2020-10-10 16:20:06 +02:00
|
|
|
enum xdpw_chooser_types get_chooser_type(const char *chooser_type);
|
|
|
|
const char *chooser_type_str(enum xdpw_chooser_types chooser_type);
|
2020-01-24 23:31:01 +01:00
|
|
|
#endif /* SCREENCAST_COMMON_H */
|