From 36951238befd78b274e1e967789bbe2e23979b8b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 8 Aug 2024 02:03:03 +0200 Subject: Fix possible capture lag (especially with desktop portal capture) --- src/capture/kms.c | 1 + src/capture/portal.c | 26 ++++++++++++++------------ src/pipewire.c | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/capture/kms.c b/src/capture/kms.c index 2ca31d4..ecd221e 100644 --- a/src/capture/kms.c +++ b/src/capture/kms.c @@ -338,6 +338,7 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c if(self->no_modifiers_fallback) { setup_dma_buf_attrs(img_attr, drm_fd->pixel_format, drm_fd->width, drm_fd->height, fds, offsets, pitches, modifiers, drm_fd->num_dma_bufs, false); + image = self->params.egl->eglCreateImage(self->params.egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, img_attr); } else { setup_dma_buf_attrs(img_attr, drm_fd->pixel_format, drm_fd->width, drm_fd->height, fds, offsets, pitches, modifiers, drm_fd->num_dma_bufs, true); while(self->params.egl->eglGetError() != EGL_SUCCESS){} diff --git a/src/capture/portal.c b/src/capture/portal.c index 00972e3..fa6f61f 100644 --- a/src/capture/portal.c +++ b/src/capture/portal.c @@ -320,18 +320,20 @@ static int gsr_capture_portal_capture(gsr_capture *cap, AVFrame *frame, gsr_colo (vec2i){region.x, region.y}, self->capture_size, 0.0f, false); - const vec2i cursor_pos = { - target_x + cursor_region.x, - target_y + cursor_region.y - }; - - self->params.egl->glEnable(GL_SCISSOR_TEST); - self->params.egl->glScissor(target_x, target_y, self->capture_size.x, self->capture_size.y); - gsr_color_conversion_draw(color_conversion, self->cursor_texture_id, - (vec2i){cursor_pos.x, cursor_pos.y}, (vec2i){cursor_region.width, cursor_region.height}, - (vec2i){0, 0}, (vec2i){cursor_region.width, cursor_region.height}, - 0.0f, false); - self->params.egl->glDisable(GL_SCISSOR_TEST); + if(self->params.record_cursor) { + const vec2i cursor_pos = { + target_x + cursor_region.x, + target_y + cursor_region.y + }; + + self->params.egl->glEnable(GL_SCISSOR_TEST); + self->params.egl->glScissor(target_x, target_y, self->capture_size.x, self->capture_size.y); + gsr_color_conversion_draw(color_conversion, self->cursor_texture_id, + (vec2i){cursor_pos.x, cursor_pos.y}, (vec2i){cursor_region.width, cursor_region.height}, + (vec2i){0, 0}, (vec2i){cursor_region.width, cursor_region.height}, + 0.0f, false); + self->params.egl->glDisable(GL_SCISSOR_TEST); + } //self->params.egl->glFlush(); //self->params.egl->glFinish(); diff --git a/src/pipewire.c b/src/pipewire.c index fae83cd..2e73b92 100644 --- a/src/pipewire.c +++ b/src/pipewire.c @@ -649,6 +649,7 @@ bool gsr_pipewire_map_texture(gsr_pipewire *self, unsigned int texture_id, unsig if(self->no_modifiers_fallback) { setup_dma_buf_attrs(img_attr, spa_video_format_to_drm_format(self->format.info.raw.format), self->format.info.raw.size.width, self->format.info.raw.size.height, fds, offsets, pitches, modifiers, self->dmabuf_num_planes, false); + image = self->egl->eglCreateImage(self->egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, img_attr); } else { setup_dma_buf_attrs(img_attr, spa_video_format_to_drm_format(self->format.info.raw.format), self->format.info.raw.size.width, self->format.info.raw.size.height, fds, offsets, pitches, modifiers, self->dmabuf_num_planes, true); -- cgit v1.2.3