From d1c49f35a5cca15ee17939c7f2a87224f494c5b3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 8 Feb 2024 19:06:09 +0100 Subject: Window capture: clear background with black color --- include/color_conversion.h | 3 ++- src/capture/xcomposite_cuda.c | 1 + src/capture/xcomposite_vaapi.c | 3 +++ src/color_conversion.c | 43 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/include/color_conversion.h b/include/color_conversion.h index d8e660e..07b29f6 100644 --- a/include/color_conversion.h +++ b/include/color_conversion.h @@ -45,6 +45,7 @@ typedef struct { int gsr_color_conversion_init(gsr_color_conversion *self, const gsr_color_conversion_params *params); void gsr_color_conversion_deinit(gsr_color_conversion *self); -int gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture); +void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture); +void gsr_color_conversion_clear(gsr_color_conversion *self); #endif /* GSR_COLOR_CONVERSION_H */ diff --git a/src/capture/xcomposite_cuda.c b/src/capture/xcomposite_cuda.c index 7e65efa..58af0be 100644 --- a/src/capture/xcomposite_cuda.c +++ b/src/capture/xcomposite_cuda.c @@ -272,6 +272,7 @@ static void gsr_capture_xcomposite_cuda_stop(gsr_capture *cap, AVCodecContext *v 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; diff --git a/src/capture/xcomposite_vaapi.c b/src/capture/xcomposite_vaapi.c index 687eb2d..f9efef5 100644 --- a/src/capture/xcomposite_vaapi.c +++ b/src/capture/xcomposite_vaapi.c @@ -199,6 +199,7 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext * gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv; // TODO: + 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; @@ -418,6 +419,8 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext * return; } } + + gsr_color_conversion_clear(&cap_xcomp->color_conversion); } } diff --git a/src/color_conversion.c b/src/color_conversion.c index 2bfb9c2..1d70b9e 100644 --- a/src/color_conversion.c +++ b/src/color_conversion.c @@ -362,7 +362,7 @@ void gsr_color_conversion_deinit(gsr_color_conversion *self) { } /* |source_pos| is in pixel coordinates and |source_size| */ -int gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture) { +void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture) { /* TODO: Do not call this every frame? */ vec2i dest_texture_size = {0, 0}; self->params.egl->glBindTexture(GL_TEXTURE_2D, self->params.destination_textures[0]); @@ -453,5 +453,44 @@ int gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_i gsr_shader_use_none(&self->shaders[0]); self->params.egl->glBindTexture(texture_target, 0); self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, 0); - return 0; +} + +void gsr_color_conversion_clear(gsr_color_conversion *self) { + float color1[4]; + float color2[4]; + + switch(self->params.destination_color) { + case GSR_DESTINATION_COLOR_BGR: { + color1[0] = 0.0f; + color1[1] = 0.0f; + color1[2] = 0.0f; + color1[3] = 1.0f; + break; + } + case GSR_DESTINATION_COLOR_NV12: + case GSR_DESTINATION_COLOR_P010: { + color1[0] = 0.0f; + color1[1] = 0.0f; + color1[2] = 0.0f; + color1[3] = 1.0f; + + color2[0] = 0.5f; + color2[1] = 0.5f; + color2[2] = 0.0f; + color2[3] = 1.0f; + break; + } + } + + self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffers[0]); + self->params.egl->glClearColor(color1[0], color1[1], color1[2], color1[3]); + self->params.egl->glClear(GL_COLOR_BUFFER_BIT); + + if(self->params.num_destination_textures > 1) { + self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffers[1]); + self->params.egl->glClearColor(color2[0], color2[1], color2[2], color2[3]); + self->params.egl->glClear(GL_COLOR_BUFFER_BIT); + } + + self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, 0); } -- cgit v1.2.3