Remove wayland capture (wlroots)

This commit is contained in:
dec05eba
2024-02-09 00:38:23 +01:00
parent 3eb7bae12c
commit ac73d9cb13
8 changed files with 129 additions and 605 deletions

View File

@@ -37,8 +37,6 @@ typedef struct {
gsr_kms_client kms_client;
gsr_kms_response kms_response;
gsr_kms_response_fd wayland_kms_data;
bool using_wayland_capture;
vec2i capture_pos;
vec2i capture_size;
@@ -144,32 +142,24 @@ static int gsr_capture_kms_cuda_start(gsr_capture *cap, AVCodecContext *video_co
gsr_monitor monitor;
cap_kms->monitor_id.num_connector_ids = 0;
if(gsr_egl_start_capture(cap_kms->params.egl, cap_kms->params.display_to_capture)) {
if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_WAYLAND, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_cuda_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_cuda_stop(cap, video_codec_context);
return -1;
}
cap_kms->using_wayland_capture = true;
} else {
int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.egl->card_path);
if(kms_init_res != 0) {
gsr_capture_kms_cuda_stop(cap, video_codec_context);
return kms_init_res;
}
MonitorCallbackUserdata monitor_callback_userdata = {
cap_kms,
cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture),
0
};
for_each_active_monitor_output(cap_kms->params.egl, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata);
int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.egl->card_path);
if(kms_init_res != 0) {
gsr_capture_kms_cuda_stop(cap, video_codec_context);
return kms_init_res;
}
if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_cuda_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_cuda_stop(cap, video_codec_context);
return -1;
}
MonitorCallbackUserdata monitor_callback_userdata = {
cap_kms,
cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture),
0
};
for_each_active_monitor_output(cap_kms->params.egl, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata);
if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_cuda_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_cuda_stop(cap, video_codec_context);
return -1;
}
cap_kms->capture_pos = monitor.pos;
@@ -407,62 +397,37 @@ static int gsr_capture_kms_cuda_capture(gsr_capture *cap, AVFrame *frame) {
gsr_kms_response_fd *drm_fd = NULL;
gsr_kms_response_fd *cursor_drm_fd = NULL;
bool capture_is_combined_plane = false;
if(cap_kms->using_wayland_capture) {
gsr_egl_update(cap_kms->params.egl);
cap_kms->wayland_kms_data.fd = cap_kms->params.egl->fd;
cap_kms->wayland_kms_data.width = cap_kms->params.egl->width;
cap_kms->wayland_kms_data.height = cap_kms->params.egl->height;
cap_kms->wayland_kms_data.pitch = cap_kms->params.egl->pitch;
cap_kms->wayland_kms_data.offset = cap_kms->params.egl->offset;
cap_kms->wayland_kms_data.pixel_format = cap_kms->params.egl->pixel_format;
cap_kms->wayland_kms_data.modifier = cap_kms->params.egl->modifier;
cap_kms->wayland_kms_data.connector_id = 0;
cap_kms->wayland_kms_data.is_combined_plane = false;
cap_kms->wayland_kms_data.is_cursor = false;
cap_kms->wayland_kms_data.x = cap_kms->wayland_kms_data.x; // TODO: Use these
cap_kms->wayland_kms_data.y = cap_kms->wayland_kms_data.y;
cap_kms->wayland_kms_data.src_w = cap_kms->wayland_kms_data.width;
cap_kms->wayland_kms_data.src_h = cap_kms->wayland_kms_data.height;
cap_kms->capture_pos.x = cap_kms->wayland_kms_data.x;
cap_kms->capture_pos.y = cap_kms->wayland_kms_data.y;
if(cap_kms->wayland_kms_data.fd <= 0)
return -1;
drm_fd = &cap_kms->wayland_kms_data;
} else {
if(gsr_kms_client_get_kms(&cap_kms->kms_client, &cap_kms->kms_response) != 0) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_capture: failed to get kms, error: %d (%s)\n", cap_kms->kms_response.result, cap_kms->kms_response.err_msg);
return -1;
}
if(cap_kms->kms_response.num_fds == 0) {
static bool error_shown = false;
if(!error_shown) {
error_shown = true;
fprintf(stderr, "gsr error: no drm found, capture will fail\n");
}
return -1;
}
for(int i = 0; i < cap_kms->monitor_id.num_connector_ids; ++i) {
drm_fd = find_drm_by_connector_id(&cap_kms->kms_response, cap_kms->monitor_id.connector_ids[i]);
if(drm_fd)
break;
}
// Will never happen on wayland unless the target monitor has been disconnected
if(!drm_fd) {
drm_fd = find_first_combined_drm(&cap_kms->kms_response);
if(!drm_fd)
drm_fd = find_largest_drm(&cap_kms->kms_response);
capture_is_combined_plane = true;
}
cursor_drm_fd = find_cursor_drm(&cap_kms->kms_response);
if(gsr_kms_client_get_kms(&cap_kms->kms_client, &cap_kms->kms_response) != 0) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_capture: failed to get kms, error: %d (%s)\n", cap_kms->kms_response.result, cap_kms->kms_response.err_msg);
return -1;
}
if(cap_kms->kms_response.num_fds == 0) {
static bool error_shown = false;
if(!error_shown) {
error_shown = true;
fprintf(stderr, "gsr error: no drm found, capture will fail\n");
}
return -1;
}
for(int i = 0; i < cap_kms->monitor_id.num_connector_ids; ++i) {
drm_fd = find_drm_by_connector_id(&cap_kms->kms_response, cap_kms->monitor_id.connector_ids[i]);
if(drm_fd)
break;
}
// Will never happen on wayland unless the target monitor has been disconnected
if(!drm_fd) {
drm_fd = find_first_combined_drm(&cap_kms->kms_response);
if(!drm_fd)
drm_fd = find_largest_drm(&cap_kms->kms_response);
capture_is_combined_plane = true;
}
cursor_drm_fd = find_cursor_drm(&cap_kms->kms_response);
if(!drm_fd)
return -1;
@@ -551,8 +516,6 @@ static void gsr_capture_kms_cuda_capture_end(gsr_capture *cap, AVFrame *frame) {
(void)frame;
gsr_capture_kms_cuda *cap_kms = cap->priv;
gsr_egl_cleanup_frame(cap_kms->params.egl);
for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) {
if(cap_kms->kms_response.fds[i].fd > 0)
close(cap_kms->kms_response.fds[i].fd);

View File

@@ -29,8 +29,6 @@ typedef struct {
gsr_kms_client kms_client;
gsr_kms_response kms_response;
gsr_kms_response_fd wayland_kms_data;
bool using_wayland_capture;
vec2i capture_pos;
vec2i capture_size;
@@ -138,32 +136,24 @@ static int gsr_capture_kms_vaapi_start(gsr_capture *cap, AVCodecContext *video_c
gsr_monitor monitor;
cap_kms->monitor_id.num_connector_ids = 0;
if(gsr_egl_start_capture(cap_kms->params.egl, cap_kms->params.display_to_capture)) {
if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_WAYLAND, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return -1;
}
cap_kms->using_wayland_capture = true;
} else {
int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.egl->card_path);
if(kms_init_res != 0) {
gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return kms_init_res;
}
MonitorCallbackUserdata monitor_callback_userdata = {
cap_kms,
cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture),
0,
};
for_each_active_monitor_output(cap_kms->params.egl, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata);
int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.egl->card_path);
if(kms_init_res != 0) {
gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return kms_init_res;
}
if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return -1;
}
MonitorCallbackUserdata monitor_callback_userdata = {
cap_kms,
cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture),
0,
};
for_each_active_monitor_output(cap_kms->params.egl, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata);
if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return -1;
}
cap_kms->capture_pos = monitor.pos;
@@ -398,26 +388,6 @@ static gsr_kms_response_fd* find_cursor_drm(gsr_kms_response *kms_response) {
return NULL;
}
static void copy_wayland_surface_data_to_drm_buffer(gsr_capture_kms_vaapi *cap_kms) {
cap_kms->wayland_kms_data.fd = cap_kms->params.egl->fd;
cap_kms->wayland_kms_data.width = cap_kms->params.egl->width;
cap_kms->wayland_kms_data.height = cap_kms->params.egl->height;
cap_kms->wayland_kms_data.pitch = cap_kms->params.egl->pitch;
cap_kms->wayland_kms_data.offset = cap_kms->params.egl->offset;
cap_kms->wayland_kms_data.pixel_format = cap_kms->params.egl->pixel_format;
cap_kms->wayland_kms_data.modifier = cap_kms->params.egl->modifier;
cap_kms->wayland_kms_data.connector_id = 0;
cap_kms->wayland_kms_data.is_combined_plane = false;
cap_kms->wayland_kms_data.is_cursor = false;
cap_kms->wayland_kms_data.x = cap_kms->wayland_kms_data.x; // TODO: Use these
cap_kms->wayland_kms_data.y = cap_kms->wayland_kms_data.y;
cap_kms->wayland_kms_data.src_w = cap_kms->wayland_kms_data.width;
cap_kms->wayland_kms_data.src_h = cap_kms->wayland_kms_data.height;
cap_kms->capture_pos.x = cap_kms->wayland_kms_data.x;
cap_kms->capture_pos.y = cap_kms->wayland_kms_data.y;
}
#define HDMI_STATIC_METADATA_TYPE1 0
#define HDMI_EOTF_SMPTE_ST2084 2
@@ -471,46 +441,37 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) {
gsr_kms_response_fd *drm_fd = NULL;
gsr_kms_response_fd *cursor_drm_fd = NULL;
bool capture_is_combined_plane = false;
if(cap_kms->using_wayland_capture) {
gsr_egl_update(cap_kms->params.egl);
copy_wayland_surface_data_to_drm_buffer(cap_kms);
if(cap_kms->wayland_kms_data.fd <= 0)
return -1;
drm_fd = &cap_kms->wayland_kms_data;
} else {
if(gsr_kms_client_get_kms(&cap_kms->kms_client, &cap_kms->kms_response) != 0) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_capture: failed to get kms, error: %d (%s)\n", cap_kms->kms_response.result, cap_kms->kms_response.err_msg);
return -1;
}
if(cap_kms->kms_response.num_fds == 0) {
static bool error_shown = false;
if(!error_shown) {
error_shown = true;
fprintf(stderr, "gsr error: no drm found, capture will fail\n");
}
return -1;
}
for(int i = 0; i < cap_kms->monitor_id.num_connector_ids; ++i) {
drm_fd = find_drm_by_connector_id(&cap_kms->kms_response, cap_kms->monitor_id.connector_ids[i]);
if(drm_fd)
break;
}
// Will never happen on wayland unless the target monitor has been disconnected
if(!drm_fd) {
drm_fd = find_first_combined_drm(&cap_kms->kms_response);
if(!drm_fd)
drm_fd = find_largest_drm(&cap_kms->kms_response);
capture_is_combined_plane = true;
}
cursor_drm_fd = find_cursor_drm(&cap_kms->kms_response);
if(gsr_kms_client_get_kms(&cap_kms->kms_client, &cap_kms->kms_response) != 0) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_capture: failed to get kms, error: %d (%s)\n", cap_kms->kms_response.result, cap_kms->kms_response.err_msg);
return -1;
}
if(cap_kms->kms_response.num_fds == 0) {
static bool error_shown = false;
if(!error_shown) {
error_shown = true;
fprintf(stderr, "gsr error: no drm found, capture will fail\n");
}
return -1;
}
for(int i = 0; i < cap_kms->monitor_id.num_connector_ids; ++i) {
drm_fd = find_drm_by_connector_id(&cap_kms->kms_response, cap_kms->monitor_id.connector_ids[i]);
if(drm_fd)
break;
}
// Will never happen on wayland unless the target monitor has been disconnected
if(!drm_fd) {
drm_fd = find_first_combined_drm(&cap_kms->kms_response);
if(!drm_fd)
drm_fd = find_largest_drm(&cap_kms->kms_response);
capture_is_combined_plane = true;
}
cursor_drm_fd = find_cursor_drm(&cap_kms->kms_response);
if(!drm_fd)
return -1;
@@ -559,47 +520,40 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) {
vec2i capture_pos = cap_kms->capture_pos;
if(cap_kms->using_wayland_capture) {
gsr_color_conversion_draw(&cap_kms->color_conversion, cap_kms->input_texture,
(vec2i){0, 0}, cap_kms->capture_size,
(vec2i){0, 0}, cap_kms->capture_size,
if(!capture_is_combined_plane)
capture_pos = (vec2i){drm_fd->x, drm_fd->y};
float texture_rotation = 0.0f;
gsr_color_conversion_draw(&cap_kms->color_conversion, cap_kms->input_texture,
(vec2i){0, 0}, cap_kms->capture_size,
capture_pos, cap_kms->capture_size,
texture_rotation, false);
if(cursor_drm_fd) {
const intptr_t img_attr_cursor[] = {
EGL_LINUX_DRM_FOURCC_EXT, cursor_drm_fd->pixel_format,
EGL_WIDTH, cursor_drm_fd->width,
EGL_HEIGHT, cursor_drm_fd->height,
EGL_DMA_BUF_PLANE0_FD_EXT, cursor_drm_fd->fd,
EGL_DMA_BUF_PLANE0_OFFSET_EXT, cursor_drm_fd->offset,
EGL_DMA_BUF_PLANE0_PITCH_EXT, cursor_drm_fd->pitch,
EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, cursor_drm_fd->modifier & 0xFFFFFFFFULL,
EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, cursor_drm_fd->modifier >> 32ULL,
EGL_NONE
};
EGLImage cursor_image = cap_kms->params.egl->eglCreateImage(cap_kms->params.egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, img_attr_cursor);
cap_kms->params.egl->glBindTexture(GL_TEXTURE_2D, cap_kms->cursor_texture);
cap_kms->params.egl->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, cursor_image);
cap_kms->params.egl->eglDestroyImage(cap_kms->params.egl->egl_display, cursor_image);
cap_kms->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
vec2i cursor_size = {cursor_drm_fd->width, cursor_drm_fd->height};
gsr_color_conversion_draw(&cap_kms->color_conversion, cap_kms->cursor_texture,
(vec2i){cursor_drm_fd->x, cursor_drm_fd->y}, cursor_size,
(vec2i){0, 0}, cursor_size,
0.0f, false);
} else {
if(!capture_is_combined_plane)
capture_pos = (vec2i){drm_fd->x, drm_fd->y};
float texture_rotation = 0.0f;
gsr_color_conversion_draw(&cap_kms->color_conversion, cap_kms->input_texture,
(vec2i){0, 0}, cap_kms->capture_size,
capture_pos, cap_kms->capture_size,
texture_rotation, false);
if(cursor_drm_fd) {
const intptr_t img_attr_cursor[] = {
EGL_LINUX_DRM_FOURCC_EXT, cursor_drm_fd->pixel_format,
EGL_WIDTH, cursor_drm_fd->width,
EGL_HEIGHT, cursor_drm_fd->height,
EGL_DMA_BUF_PLANE0_FD_EXT, cursor_drm_fd->fd,
EGL_DMA_BUF_PLANE0_OFFSET_EXT, cursor_drm_fd->offset,
EGL_DMA_BUF_PLANE0_PITCH_EXT, cursor_drm_fd->pitch,
EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, cursor_drm_fd->modifier & 0xFFFFFFFFULL,
EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, cursor_drm_fd->modifier >> 32ULL,
EGL_NONE
};
EGLImage cursor_image = cap_kms->params.egl->eglCreateImage(cap_kms->params.egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, img_attr_cursor);
cap_kms->params.egl->glBindTexture(GL_TEXTURE_2D, cap_kms->cursor_texture);
cap_kms->params.egl->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, cursor_image);
cap_kms->params.egl->eglDestroyImage(cap_kms->params.egl->egl_display, cursor_image);
cap_kms->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
vec2i cursor_size = {cursor_drm_fd->width, cursor_drm_fd->height};
gsr_color_conversion_draw(&cap_kms->color_conversion, cap_kms->cursor_texture,
(vec2i){cursor_drm_fd->x, cursor_drm_fd->y}, cursor_size,
(vec2i){0, 0}, cursor_size,
0.0f, false);
}
}
cap_kms->params.egl->eglSwapBuffers(cap_kms->params.egl->egl_display, cap_kms->params.egl->egl_surface);
@@ -613,8 +567,6 @@ static void gsr_capture_kms_vaapi_capture_end(gsr_capture *cap, AVFrame *frame)
(void)frame;
gsr_capture_kms_vaapi *cap_kms = cap->priv;
gsr_egl_cleanup_frame(cap_kms->params.egl);
for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) {
if(cap_kms->kms_response.fds[i].fd > 0)
close(cap_kms->kms_response.fds[i].fd);

146
src/egl.c
View File

@@ -8,7 +8,6 @@
#include <wayland-client.h>
#include <wayland-egl.h>
#include "../external/wlr-export-dmabuf-unstable-v1-client-protocol.h"
#include <unistd.h>
#include <sys/capability.h>
@@ -105,12 +104,6 @@ static void registry_add_object(void *data, struct wl_registry *registry, uint32
.name = NULL,
};
wl_output_add_listener(gsr_output->output, &output_listener, gsr_output);
} else if(strcmp(interface, zwlr_export_dmabuf_manager_v1_interface.name) == 0) {
if(egl->wayland.export_manager) {
zwlr_export_dmabuf_manager_v1_destroy(egl->wayland.export_manager);
egl->wayland.export_manager = NULL;
}
egl->wayland.export_manager = wl_registry_bind(registry, name, &zwlr_export_dmabuf_manager_v1_interface, 1);
}
}
@@ -125,88 +118,6 @@ static struct wl_registry_listener registry_listener = {
.global_remove = registry_remove_object,
};
static void frame_capture_output(gsr_egl *egl);
static void frame_start(void *data, struct zwlr_export_dmabuf_frame_v1 *frame,
uint32_t width, uint32_t height, uint32_t offset_x, uint32_t offset_y,
uint32_t buffer_flags, uint32_t flags, uint32_t format,
uint32_t mod_high, uint32_t mod_low, uint32_t num_objects) {
(void)buffer_flags;
(void)flags;
(void)num_objects;
gsr_egl *egl = data;
//fprintf(stderr, "frame start %p, width: %u, height: %u, offset x: %u, offset y: %u, format: %u, num objects: %u\n", (void*)frame, width, height, offset_x, offset_y, format, num_objects);
egl->x = offset_x;
egl->y = offset_y;
egl->width = width;
egl->height = height;
egl->pixel_format = format;
egl->modifier = ((uint64_t)mod_high << 32) | (uint64_t)mod_low;
egl->wayland.current_frame = frame;
}
static void frame_object(void *data, struct zwlr_export_dmabuf_frame_v1 *frame,
uint32_t index, int32_t fd, uint32_t size, uint32_t offset,
uint32_t stride, uint32_t plane_index) {
// TODO: What if we get multiple objects? then we get multiple fd per frame
(void)frame;
(void)index;
(void)size;
(void)plane_index;
gsr_egl *egl = data;
if(egl->fd > 0) {
close(egl->fd);
egl->fd = 0;
}
egl->fd = fd;
egl->pitch = stride;
egl->offset = offset;
//fprintf(stderr, "new frame %p, fd: %d, index: %u, size: %u, offset: %u, stride: %u, plane_index: %u\n", (void*)frame, fd, index, size, offset, stride, plane_index);
}
static void frame_ready(void *data, struct zwlr_export_dmabuf_frame_v1 *frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec) {
(void)frame;
(void)tv_sec_hi;
(void)tv_sec_lo;
(void)tv_nsec;
frame_capture_output(data);
}
static void frame_cancel(void *data, struct zwlr_export_dmabuf_frame_v1 *frame, uint32_t reason) {
(void)frame;
(void)reason;
frame_capture_output(data);
}
static const struct zwlr_export_dmabuf_frame_v1_listener frame_listener = {
.frame = frame_start,
.object = frame_object,
.ready = frame_ready,
.cancel = frame_cancel,
};
static void frame_capture_output(gsr_egl *egl) {
assert(egl->wayland.output_to_capture);
bool with_cursor = true;
if(egl->wayland.frame_callback) {
zwlr_export_dmabuf_frame_v1_destroy(egl->wayland.frame_callback);
egl->wayland.frame_callback = NULL;
}
egl->wayland.frame_callback = zwlr_export_dmabuf_manager_v1_capture_output(egl->wayland.export_manager, with_cursor, egl->wayland.output_to_capture->output);
zwlr_export_dmabuf_frame_v1_add_listener(egl->wayland.frame_callback, &frame_listener, egl);
}
static gsr_wayland_output* get_wayland_output_by_name(gsr_egl *egl, const char *name) {
assert(name);
for(int i = 0; i < egl->wayland.num_outputs; ++i) {
if(egl->wayland.outputs[i].name && strcmp(egl->wayland.outputs[i].name, name) == 0)
return &egl->wayland.outputs[i];
}
return NULL;
}
static void reset_cap_nice(void) {
cap_t caps = cap_get_proc();
if(!caps)
@@ -492,18 +403,6 @@ void gsr_egl_unload(gsr_egl *self) {
self->x11.window = None;
}
gsr_egl_cleanup_frame(self);
if(self->wayland.frame_callback) {
zwlr_export_dmabuf_frame_v1_destroy(self->wayland.frame_callback);
self->wayland.frame_callback = NULL;
}
if(self->wayland.export_manager) {
zwlr_export_dmabuf_manager_v1_destroy(self->wayland.export_manager);
self->wayland.export_manager = NULL;
}
if(self->wayland.window) {
wl_egl_window_destroy(self->wayland.window);
self->wayland.window = NULL;
@@ -555,36 +454,6 @@ void gsr_egl_unload(gsr_egl *self) {
memset(self, 0, sizeof(gsr_egl));
}
bool gsr_egl_supports_wayland_capture(const gsr_egl *self) {
// TODO: wlroots capture is broken right now (black screen) on amd and multiple monitors
// so it has to be disabled right now. Find out why it happens and fix it.
(void)self;
return false;
//return !!self->wayland.export_manager && self->wayland.num_outputs > 0;
}
bool gsr_egl_start_capture(gsr_egl *self, const char *monitor_to_capture) {
assert(monitor_to_capture);
if(!monitor_to_capture)
return false;
if(!self->wayland.dpy)
return false;
if(!gsr_egl_supports_wayland_capture(self))
return false;
if(self->wayland.frame_callback)
return false;
self->wayland.output_to_capture = get_wayland_output_by_name(self, monitor_to_capture);
if(!self->wayland.output_to_capture)
return false;
frame_capture_output(self);
return true;
}
void gsr_egl_update(gsr_egl *self) {
if(!self->wayland.dpy)
return;
@@ -592,18 +461,3 @@ void gsr_egl_update(gsr_egl *self) {
// TODO: pselect on wl_display_get_fd before doing dispatch
wl_display_dispatch(self->wayland.dpy);
}
void gsr_egl_cleanup_frame(gsr_egl *self) {
if(!self->wayland.dpy)
return;
if(self->fd > 0) {
close(self->fd);
self->fd = 0;
}
if(self->wayland.current_frame) {
//zwlr_export_dmabuf_frame_v1_destroy(self->wayland.current_frame);
self->wayland.current_frame = NULL;
}
}

View File

@@ -1437,11 +1437,7 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
if(strcmp(window_str, "screen") == 0) {
FirstOutputCallback first_output;
first_output.output_name = NULL;
if(gsr_egl_supports_wayland_capture(&egl)) {
for_each_active_monitor_output(&egl, GSR_CONNECTION_WAYLAND, get_first_output, &first_output);
} else {
for_each_active_monitor_output(&egl, GSR_CONNECTION_DRM, get_first_output, &first_output);
}
for_each_active_monitor_output(&egl, GSR_CONNECTION_DRM, get_first_output, &first_output);
if(first_output.output_name) {
window_str = first_output.output_name;
@@ -1450,22 +1446,12 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
}
}
if(gsr_egl_supports_wayland_capture(&egl)) {
gsr_monitor gmon;
if(!get_monitor_by_name(&egl, GSR_CONNECTION_WAYLAND, window_str, &gmon)) {
fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str);
fprintf(stderr, " \"screen\"\n");
for_each_active_monitor_output(&egl, GSR_CONNECTION_WAYLAND, monitor_output_callback_print, NULL);
_exit(1);
}
} else {
gsr_monitor gmon;
if(!get_monitor_by_name(&egl, GSR_CONNECTION_DRM, window_str, &gmon)) {
fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str);
fprintf(stderr, " \"screen\"\n");
for_each_active_monitor_output(&egl, GSR_CONNECTION_DRM, monitor_output_callback_print, NULL);
_exit(1);
}
gsr_monitor gmon;
if(!get_monitor_by_name(&egl, GSR_CONNECTION_DRM, window_str, &gmon)) {
fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str);
fprintf(stderr, " \"screen\"\n");
for_each_active_monitor_output(&egl, GSR_CONNECTION_DRM, monitor_output_callback_print, NULL);
_exit(1);
}
} else {
if(strcmp(window_str, "screen") != 0 && strcmp(window_str, "screen-direct") != 0 && strcmp(window_str, "screen-direct-force") != 0) {

View File

@@ -100,9 +100,6 @@ static bool connector_get_property_by_name(int drmfd, drmModeConnectorPtr props,
}
static void for_each_active_monitor_output_wayland(const gsr_egl *egl, active_monitor_callback callback, void *userdata) {
if(!gsr_egl_supports_wayland_capture(egl))
return;
for(int i = 0; i < egl->wayland.num_outputs; ++i) {
if(!egl->wayland.outputs[i].name)
continue;