diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-18 13:38:29 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-18 13:38:29 +0200 |
commit | 8efc371038b7f88f6f08f354cd3821f4800f2eb4 (patch) | |
tree | e24d988c70b0fed9029e629c7dd602bd23ec0011 | |
parent | 6b8e547737afa8e75eb3a92dc5d3f1d5ece06c91 (diff) |
Small refactor in pipewire code, remove unused extra/install_preserve_video_memory.sh script
-rwxr-xr-x | extra/install_preserve_video_memory.sh | 8 | ||||
-rw-r--r-- | src/pipewire.c | 89 |
2 files changed, 51 insertions, 46 deletions
diff --git a/extra/install_preserve_video_memory.sh b/extra/install_preserve_video_memory.sh deleted file mode 100755 index c5cf658..0000000 --- a/extra/install_preserve_video_memory.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -script_dir=$(dirname "$0") -cd "$script_dir" - -[ $(id -u) -ne 0 ] && echo "You need root privileges to run the install script" && exit 1 - -install -Dm644 gsr-nvidia.conf /etc/modprobe.d/gsr-nvidia.conf diff --git a/src/pipewire.c b/src/pipewire.c index 5c38392..403e1fd 100644 --- a/src/pipewire.c +++ b/src/pipewire.c @@ -627,29 +627,7 @@ static EGLImage gsr_pipewire_create_egl_image(gsr_pipewire *self, const int *fds return image; } -static bool gsr_pipewire_bind_image_to_texture(gsr_pipewire *self, EGLImage image, unsigned int texture_id, bool external_texture) { - const int texture_target = external_texture ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; - while(self->egl->glGetError() != 0){} - self->egl->glBindTexture(texture_target, texture_id); - self->egl->glEGLImageTargetTexture2DOES(texture_target, image); - const bool success = self->egl->glGetError() == 0; - self->egl->glBindTexture(texture_target, 0); - return success; -} - -bool gsr_pipewire_map_texture(gsr_pipewire *self, gsr_texture_map texture_map, gsr_pipewire_region *region, gsr_pipewire_region *cursor_region, int *plane_fds, int *num_plane_fds, bool *using_external_image) { - for(int i = 0; i < GSR_PIPEWIRE_DMABUF_MAX_PLANES; ++i) { - plane_fds[i] = -1; - } - *num_plane_fds = 0; - *using_external_image = self->external_texture_fallback; - pthread_mutex_lock(&self->mutex); - - if(!self->negotiated || self->dmabuf_data[0].fd <= 0) { - pthread_mutex_unlock(&self->mutex); - return false; - } - +static EGLImage gsr_pipewire_create_egl_image_with_fallback(gsr_pipewire *self) { int fds[GSR_PIPEWIRE_DMABUF_MAX_PLANES]; uint32_t offsets[GSR_PIPEWIRE_DMABUF_MAX_PLANES]; uint32_t pitches[GSR_PIPEWIRE_DMABUF_MAX_PLANES]; @@ -667,12 +645,25 @@ bool gsr_pipewire_map_texture(gsr_pipewire *self, gsr_texture_map texture_map, g } else { image = gsr_pipewire_create_egl_image(self, fds, offsets, pitches, modifiers, true); if(!image) { - fprintf(stderr, "gsr error: gsr_pipewire_map_texture: failed to create egl image with modifiers, trying without modifiers\n"); + fprintf(stderr, "gsr error: gsr_pipewire_create_egl_image_with_fallback: failed to create egl image with modifiers, trying without modifiers\n"); self->no_modifiers_fallback = true; image = gsr_pipewire_create_egl_image(self, fds, offsets, pitches, modifiers, false); } } + return image; +} +static bool gsr_pipewire_bind_image_to_texture(gsr_pipewire *self, EGLImage image, unsigned int texture_id, bool external_texture) { + const int texture_target = external_texture ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; + while(self->egl->glGetError() != 0){} + self->egl->glBindTexture(texture_target, texture_id); + self->egl->glEGLImageTargetTexture2DOES(texture_target, image); + const bool success = self->egl->glGetError() == 0; + self->egl->glBindTexture(texture_target, 0); + return success; +} + +static void gsr_pipewire_bind_image_to_texture_with_fallback(gsr_pipewire *self, gsr_texture_map texture_map, EGLImage image, bool *using_external_image) { if(self->external_texture_fallback) { gsr_pipewire_bind_image_to_texture(self, image, texture_map.external_texture_id, true); *using_external_image = true; @@ -684,24 +675,46 @@ bool gsr_pipewire_map_texture(gsr_pipewire *self, gsr_texture_map texture_map, g *using_external_image = true; } } +} - if(image) - self->egl->eglDestroyImage(self->egl->egl_display, image); +static void gsr_pipewire_update_cursor_texture(gsr_pipewire *self, gsr_texture_map texture_map) { + if(!self->cursor.data) + return; - if(self->cursor.data) { - self->egl->glBindTexture(GL_TEXTURE_2D, texture_map.cursor_texture_id); - // TODO: glTextureSubImage2D if same size - self->egl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, self->cursor.width, self->cursor.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, self->cursor.data); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - self->egl->glBindTexture(GL_TEXTURE_2D, 0); - - free(self->cursor.data); - self->cursor.data = NULL; + self->egl->glBindTexture(GL_TEXTURE_2D, texture_map.cursor_texture_id); + // TODO: glTextureSubImage2D if same size + self->egl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, self->cursor.width, self->cursor.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, self->cursor.data); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + self->egl->glBindTexture(GL_TEXTURE_2D, 0); + + free(self->cursor.data); + self->cursor.data = NULL; +} + +bool gsr_pipewire_map_texture(gsr_pipewire *self, gsr_texture_map texture_map, gsr_pipewire_region *region, gsr_pipewire_region *cursor_region, int *plane_fds, int *num_plane_fds, bool *using_external_image) { + for(int i = 0; i < GSR_PIPEWIRE_DMABUF_MAX_PLANES; ++i) { + plane_fds[i] = -1; + } + *num_plane_fds = 0; + *using_external_image = self->external_texture_fallback; + pthread_mutex_lock(&self->mutex); + + if(!self->negotiated || self->dmabuf_data[0].fd <= 0) { + pthread_mutex_unlock(&self->mutex); + return false; } + EGLImage image = gsr_pipewire_create_egl_image_with_fallback(self); + if(image) { + gsr_pipewire_bind_image_to_texture_with_fallback(self, texture_map, image, using_external_image); + self->egl->eglDestroyImage(self->egl->egl_display, image); + } + + gsr_pipewire_update_cursor_texture(self, texture_map); + region->x = 0; region->y = 0; |