Move card path to egl struct, use egl struct for monitor enumeration

This commit is contained in:
dec05eba
2024-02-09 00:23:52 +01:00
parent 463393a0c0
commit 3eb7bae12c
15 changed files with 92 additions and 135 deletions

View File

@@ -154,12 +154,12 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
if(cap_xcomp->params.follow_focused) {
cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.dpy, "_NET_ACTIVE_WINDOW", False);
cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.egl->x11.dpy, "_NET_ACTIVE_WINDOW", False);
if(!cap_xcomp->net_active_window_atom) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start failed: failed to get _NET_ACTIVE_WINDOW atom\n");
return -1;
}
cap_xcomp->window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom);
cap_xcomp->window = get_focused_window(cap_xcomp->params.egl->x11.dpy, cap_xcomp->net_active_window_atom);
} else {
cap_xcomp->window = cap_xcomp->params.window;
}
@@ -169,7 +169,7 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
XWindowAttributes attr;
attr.width = 0;
attr.height = 0;
if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr) && !cap_xcomp->params.follow_focused) {
if(!XGetWindowAttributes(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, &attr) && !cap_xcomp->params.follow_focused) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start failed: invalid window id: %lu\n", cap_xcomp->window);
return -1;
}
@@ -178,12 +178,12 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
cap_xcomp->window_size.y = max_int(attr.height, 0);
if(cap_xcomp->params.follow_focused)
XSelectInput(cap_xcomp->params.dpy, DefaultRootWindow(cap_xcomp->params.dpy), PropertyChangeMask);
XSelectInput(cap_xcomp->params.egl->x11.dpy, DefaultRootWindow(cap_xcomp->params.egl->x11.dpy), PropertyChangeMask);
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0);
if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.dpy, cap_xcomp->window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) {
if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start: failed to get window texture for window %ld\n", cap_xcomp->window);
return -1;
}
@@ -214,7 +214,7 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
return -1;
}
if(!gsr_cuda_load(&cap_xcomp->cuda, cap_xcomp->params.dpy, cap_xcomp->params.overclock)) {
if(!gsr_cuda_load(&cap_xcomp->cuda, cap_xcomp->params.egl->x11.dpy, cap_xcomp->params.overclock)) {
gsr_capture_xcomposite_cuda_stop(cap, video_codec_context);
return -1;
}
@@ -262,22 +262,19 @@ static void gsr_capture_xcomposite_cuda_stop(gsr_capture *cap, AVCodecContext *v
gsr_cuda_unload(&cap_xcomp->cuda);
if(cap_xcomp->params.dpy) {
if(cap_xcomp->params.egl->x11.dpy) {
// TODO: This causes a crash, why? maybe some other library dlclose xlib and that also happened to unload this???
//XCloseDisplay(cap_xcomp->dpy);
cap_xcomp->params.dpy = NULL;
cap_xcomp->params.egl->x11.dpy = NULL;
}
}
static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) {
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
bool init_new_window = false;
while(XPending(cap_xcomp->params.dpy)) {
XNextEvent(cap_xcomp->params.dpy, &cap_xcomp->xev);
while(XPending(cap_xcomp->params.egl->x11.dpy)) {
XNextEvent(cap_xcomp->params.egl->x11.dpy, &cap_xcomp->xev);
switch(cap_xcomp->xev.type) {
case DestroyNotify: {
@@ -321,17 +318,17 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v
}
if(init_new_window) {
Window focused_window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom);
Window focused_window = get_focused_window(cap_xcomp->params.egl->x11.dpy, cap_xcomp->net_active_window_atom);
if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) {
cap_xcomp->follow_focused_initialized = true;
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, 0);
XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, 0);
cap_xcomp->window = focused_window;
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
XWindowAttributes attr;
attr.width = 0;
attr.height = 0;
if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr))
if(!XGetWindowAttributes(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, &attr))
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_tick failed: invalid window id: %lu\n", cap_xcomp->window);
cap_xcomp->window_size.x = max_int(attr.width, 0);
@@ -339,7 +336,7 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v
cap_xcomp->window_resized = true;
window_texture_deinit(&cap_xcomp->window_texture);
window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.dpy, cap_xcomp->window, cap_xcomp->params.egl); // TODO: Do not do the below window_texture_on_resize after this
window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, cap_xcomp->params.egl); // TODO: Do not do the below window_texture_on_resize after this
cap_xcomp->texture_size.x = 0;
cap_xcomp->texture_size.y = 0;
@@ -424,6 +421,9 @@ static bool gsr_capture_xcomposite_cuda_should_stop(gsr_capture *cap, bool *err)
static int gsr_capture_xcomposite_cuda_capture(gsr_capture *cap, AVFrame *frame) {
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
vec2i source_pos = { 0, 0 };
vec2i source_size = cap_xcomp->texture_size;