From ec3e8146b28d148be7f9546e68d6ed9bb4d395fc Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 7 Jul 2021 11:05:34 -0300 Subject: [PATCH] pipewire: Properly pass sizes to gs_draw_sprite_subregion The gs_draw_sprite_subregion() function is used when a cropping rectangle is received from PipeWire. It is usually used by compositors to implement window screencast - where a large and mostly empty frame is sent, the window contents are only a small part of it, and the crop rectangle tells us that. Recently the wlroots implementation of portals started to use it to implement cropping, and it exposed a bug in the PipeWire code in OBS Studio. The gs_draw_sprite_subregion() function takes a pair of integers representing position (x, y) and a pair of integers representing size (width, height). The PipeWire code, however, passes a second pair of positions (x2, y2) instead of sizes, and it causes overrendering the crop area. This bug wasn't hit yet because both GNOME and KDE implementations always send (0, 0) as position, which practically never trigger this condition. Pass only width and height to gs_draw_sprite_subregion(), instead of adding x and y to them. Fixes https://github.com/obsproject/obs-studio/issues/4982 --- plugins/linux-capture/pipewire.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/linux-capture/pipewire.c b/plugins/linux-capture/pipewire.c index c9acdf634..154658856 100644 --- a/plugins/linux-capture/pipewire.c +++ b/plugins/linux-capture/pipewire.c @@ -1200,9 +1200,8 @@ void obs_pipewire_video_render(obs_pipewire_data *obs_pw, gs_effect_t *effect) if (has_effective_crop(obs_pw)) { gs_draw_sprite_subregion(obs_pw->texture, 0, obs_pw->crop.x, - obs_pw->crop.y, - obs_pw->crop.x + obs_pw->crop.width, - obs_pw->crop.y + obs_pw->crop.height); + obs_pw->crop.y, obs_pw->crop.width, + obs_pw->crop.height); } else { gs_draw_sprite(obs_pw->texture, 0, 0, 0); }