diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-12-08 02:17:41 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-12-08 02:17:41 +0100 |
commit | c259a19b9d8ca646824acad60b599b03252bc1c0 (patch) | |
tree | d3c7f3090735b3ae225868d514a9163c02941489 /src/capture | |
parent | 655fd3756be4507030aac1d497e579cfc0070f3c (diff) |
Refactor windowing from egl to window_x11/window_wayland, yolo
Diffstat (limited to 'src/capture')
-rw-r--r-- | src/capture/kms.c | 14 | ||||
-rw-r--r-- | src/capture/nvfbc.c | 14 | ||||
-rw-r--r-- | src/capture/xcomposite.c | 29 |
3 files changed, 36 insertions, 21 deletions
diff --git a/src/capture/kms.c b/src/capture/kms.c index fcf3b85..d692929 100644 --- a/src/capture/kms.c +++ b/src/capture/kms.c @@ -2,6 +2,7 @@ #include "../../include/utils.h" #include "../../include/color_conversion.h" #include "../../include/cursor.h" +#include "../../include/window/window.h" #include "../../kms/client/kms_client.h" #include <stdlib.h> @@ -183,10 +184,12 @@ static int gsr_capture_kms_start(gsr_capture *cap, AVCodecContext *video_codec_c if(kms_init_res != 0) return kms_init_res; - self->is_x11 = gsr_egl_get_display_server(self->params.egl) == GSR_DISPLAY_SERVER_X11; + self->is_x11 = gsr_window_get_display_server(self->params.egl->window) == GSR_DISPLAY_SERVER_X11; const gsr_connection_type connection_type = self->is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM; - if(self->is_x11) - gsr_cursor_init(&self->x11_cursor, self->params.egl, self->params.egl->x11.dpy); + if(self->is_x11) { + Display *display = gsr_window_get_display(self->params.egl->window); + gsr_cursor_init(&self->x11_cursor, self->params.egl, display); + } MonitorCallbackUserdata monitor_callback_userdata = { &self->monitor_id, @@ -240,7 +243,7 @@ static void gsr_capture_kms_on_event(gsr_capture *cap, gsr_egl *egl) { if(!self->is_x11) return; - XEvent *xev = gsr_egl_get_event_data(egl); + XEvent *xev = gsr_window_get_event_data(egl->window); gsr_cursor_on_event(&self->x11_cursor, xev); } @@ -525,7 +528,8 @@ static void render_x11_cursor(gsr_capture_kms *self, gsr_color_conversion *color self->capture_size.y == 0 ? 0 : (double)output_size.y / (double)self->capture_size.y }; - gsr_cursor_tick(&self->x11_cursor, DefaultRootWindow(self->params.egl->x11.dpy)); + Display *display = gsr_window_get_display(self->params.egl->window); + gsr_cursor_tick(&self->x11_cursor, DefaultRootWindow(display)); const vec2i cursor_pos = { target_pos.x + (self->x11_cursor.position.x - self->x11_cursor.hotspot.x - capture_pos.x) * scale.x, diff --git a/src/capture/nvfbc.c b/src/capture/nvfbc.c index d5a270e..676d269 100644 --- a/src/capture/nvfbc.c +++ b/src/capture/nvfbc.c @@ -3,12 +3,14 @@ #include "../../include/egl.h" #include "../../include/utils.h" #include "../../include/color_conversion.h" +#include "../../include/window/window.h" #include <dlfcn.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <math.h> +#include <assert.h> #include <X11/Xlib.h> #include <libavcodec/avcodec.h> @@ -136,7 +138,10 @@ static void set_vertical_sync_enabled(gsr_egl *egl, int enabled) { int result = 0; if(egl->glXSwapIntervalEXT) { - egl->glXSwapIntervalEXT(egl->x11.dpy, egl->x11.window, enabled ? 1 : 0); + assert(gsr_window_get_display_server(egl->window) == GSR_DISPLAY_SERVER_X11); + Display *display = gsr_window_get_display(egl->window); + const Window window = (Window)gsr_window_get_window(egl->window); + egl->glXSwapIntervalEXT(display, window, enabled ? 1 : 0); } else if(egl->glXSwapIntervalMESA) { result = egl->glXSwapIntervalMESA(enabled ? 1 : 0); } else if(egl->glXSwapIntervalSGI) { @@ -219,8 +224,11 @@ static int gsr_capture_nvfbc_setup_handle(gsr_capture_nvfbc *self) { goto error_cleanup; } - self->tracking_width = XWidthOfScreen(DefaultScreenOfDisplay(self->params.egl->x11.dpy)); - self->tracking_height = XHeightOfScreen(DefaultScreenOfDisplay(self->params.egl->x11.dpy)); + assert(gsr_window_get_display_server(self->params.egl->window) == GSR_DISPLAY_SERVER_X11); + Display *display = gsr_window_get_display(self->params.egl->window); + + self->tracking_width = XWidthOfScreen(DefaultScreenOfDisplay(display)); + self->tracking_height = XHeightOfScreen(DefaultScreenOfDisplay(display)); self->tracking_type = strcmp(self->params.display_to_capture, "screen") == 0 ? NVFBC_TRACKING_SCREEN : NVFBC_TRACKING_OUTPUT; if(self->tracking_type == NVFBC_TRACKING_OUTPUT) { if(!status_params.bXRandRAvailable) { diff --git a/src/capture/xcomposite.c b/src/capture/xcomposite.c index 79cd60a..66c700d 100644 --- a/src/capture/xcomposite.c +++ b/src/capture/xcomposite.c @@ -3,6 +3,7 @@ #include "../../include/utils.h" #include "../../include/cursor.h" #include "../../include/color_conversion.h" +#include "../../include/window/window.h" #include <stdlib.h> #include <stdio.h> @@ -16,6 +17,7 @@ typedef struct { gsr_capture_xcomposite_params params; + Display *display; bool should_stop; bool stop_is_error; @@ -66,12 +68,12 @@ static int gsr_capture_xcomposite_start(gsr_capture *cap, AVCodecContext *video_ gsr_capture_xcomposite *self = cap->priv; if(self->params.follow_focused) { - self->net_active_window_atom = XInternAtom(self->params.egl->x11.dpy, "_NET_ACTIVE_WINDOW", False); + self->net_active_window_atom = XInternAtom(self->display, "_NET_ACTIVE_WINDOW", False); if(!self->net_active_window_atom) { fprintf(stderr, "gsr error: gsr_capture_xcomposite_start failed: failed to get _NET_ACTIVE_WINDOW atom\n"); return -1; } - self->window = get_focused_window(self->params.egl->x11.dpy, self->net_active_window_atom); + self->window = get_focused_window(self->display, self->net_active_window_atom); } else { self->window = self->params.window; } @@ -79,7 +81,7 @@ static int gsr_capture_xcomposite_start(gsr_capture *cap, AVCodecContext *video_ /* TODO: Do these in tick, and allow error if follow_focused */ XWindowAttributes attr; - if(!XGetWindowAttributes(self->params.egl->x11.dpy, self->window, &attr) && !self->params.follow_focused) { + if(!XGetWindowAttributes(self->display, self->window, &attr) && !self->params.follow_focused) { fprintf(stderr, "gsr error: gsr_capture_xcomposite_start failed: invalid window id: %lu\n", self->window); return -1; } @@ -88,19 +90,19 @@ static int gsr_capture_xcomposite_start(gsr_capture *cap, AVCodecContext *video_ self->window_size.y = max_int(attr.height, 0); if(self->params.follow_focused) - XSelectInput(self->params.egl->x11.dpy, DefaultRootWindow(self->params.egl->x11.dpy), PropertyChangeMask); + XSelectInput(self->display, DefaultRootWindow(self->display), PropertyChangeMask); // TODO: Get select and add these on top of it and then restore at the end. Also do the same in other xcomposite - XSelectInput(self->params.egl->x11.dpy, self->window, StructureNotifyMask | ExposureMask); + XSelectInput(self->display, self->window, StructureNotifyMask | ExposureMask); /* Disable vsync */ self->params.egl->eglSwapInterval(self->params.egl->egl_display, 0); - if(window_texture_init(&self->window_texture, self->params.egl->x11.dpy, self->window, self->params.egl) != 0 && !self->params.follow_focused) { + if(window_texture_init(&self->window_texture, self->display, self->window, self->params.egl) != 0 && !self->params.follow_focused) { fprintf(stderr, "gsr error: gsr_capture_xcomposite_start: failed to get window texture for window %ld\n", self->window); return -1; } - if(gsr_cursor_init(&self->cursor, self->params.egl, self->params.egl->x11.dpy) != 0) { + if(gsr_cursor_init(&self->cursor, self->params.egl, self->display) != 0) { gsr_capture_xcomposite_stop(self); return -1; } @@ -143,24 +145,24 @@ static void gsr_capture_xcomposite_tick(gsr_capture *cap) { if(self->init_new_window) { self->init_new_window = false; - Window focused_window = get_focused_window(self->params.egl->x11.dpy, self->net_active_window_atom); + Window focused_window = get_focused_window(self->display, self->net_active_window_atom); if(focused_window != self->window || !self->follow_focused_initialized) { self->follow_focused_initialized = true; - XSelectInput(self->params.egl->x11.dpy, self->window, 0); + XSelectInput(self->display, self->window, 0); self->window = focused_window; - XSelectInput(self->params.egl->x11.dpy, self->window, StructureNotifyMask | ExposureMask); + XSelectInput(self->display, self->window, StructureNotifyMask | ExposureMask); XWindowAttributes attr; attr.width = 0; attr.height = 0; - if(!XGetWindowAttributes(self->params.egl->x11.dpy, self->window, &attr)) + if(!XGetWindowAttributes(self->display, self->window, &attr)) fprintf(stderr, "gsr error: gsr_capture_xcomposite_tick failed: invalid window id: %lu\n", self->window); self->window_size.x = max_int(attr.width, 0); self->window_size.y = max_int(attr.height, 0); window_texture_deinit(&self->window_texture); - window_texture_init(&self->window_texture, self->params.egl->x11.dpy, self->window, self->params.egl); // TODO: Do not do the below window_texture_on_resize after this + window_texture_init(&self->window_texture, self->display, self->window, self->params.egl); // TODO: Do not do the below window_texture_on_resize after this self->texture_size.x = 0; self->texture_size.y = 0; @@ -200,7 +202,7 @@ static void gsr_capture_xcomposite_tick(gsr_capture *cap) { static void gsr_capture_xcomposite_on_event(gsr_capture *cap, gsr_egl *egl) { gsr_capture_xcomposite *self = cap->priv; - XEvent *xev = gsr_egl_get_event_data(egl); + XEvent *xev = gsr_window_get_event_data(egl->window); switch(xev->type) { case DestroyNotify: { /* Window died (when not following focused window), so we stop recording */ @@ -350,6 +352,7 @@ gsr_capture* gsr_capture_xcomposite_create(const gsr_capture_xcomposite_params * } cap_xcomp->params = *params; + cap_xcomp->display = gsr_window_get_display(params->egl->window); *cap = (gsr_capture) { .start = gsr_capture_xcomposite_start, |