From de4d1e6d8c90e252e196910efd888cb22a4ef941 Mon Sep 17 00:00:00 2001 From: unvermuthet <40361609+unvermuthet@users.noreply.github.com> Date: Mon, 10 Mar 2025 14:41:01 +0100 Subject: [PATCH] fix(VideoStreamPlayer): Redraw when video resolution changes during playback --- scene/gui/video_stream_player.cpp | 29 +++++++++++++++++++++++++++-- scene/gui/video_stream_player.h | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp index eb6aff27dc9..641a02ac01b 100644 --- a/scene/gui/video_stream_player.cpp +++ b/scene/gui/video_stream_player.cpp @@ -176,7 +176,7 @@ void VideoStreamPlayer::_notification(int p_notification) { return; } - Size2 s = expand ? get_size() : texture->get_size(); + Size2 s = expand ? get_size() : texture_size; draw_texture_rect(texture, Rect2(Point2(), s), false); } break; @@ -212,9 +212,25 @@ void VideoStreamPlayer::_notification(int p_notification) { } } +void VideoStreamPlayer::texture_changed(const Ref &p_texture) { + const Size2 new_texture_size = p_texture.is_valid() ? p_texture->get_size() : Size2(); + + if (new_texture_size == texture_size) { + return; + } + + texture_size = new_texture_size; + + queue_redraw(); + + if (!expand) { + update_minimum_size(); + } +} + Size2 VideoStreamPlayer::get_minimum_size() const { if (!expand && texture.is_valid()) { - return texture->get_size(); + return texture_size; } else { return Size2(); } @@ -266,10 +282,19 @@ void VideoStreamPlayer::set_stream(const Ref &p_stream) { stream->connect_changed(callable_mp(this, &VideoStreamPlayer::set_stream).bind(stream)); } + if (texture.is_valid()) { + texture->disconnect_changed(callable_mp(this, &VideoStreamPlayer::texture_changed)); + } + if (playback.is_valid()) { playback->set_paused(paused); texture = playback->get_texture(); + if (texture.is_valid()) { + texture_size = texture->get_size(); + texture->connect_changed(callable_mp(this, &VideoStreamPlayer::texture_changed).bind(texture)); + } + const int channels = playback->get_channels(); AudioServer::get_singleton()->lock(); diff --git a/scene/gui/video_stream_player.h b/scene/gui/video_stream_player.h index 7e3b90797a1..9a71b14f1c2 100644 --- a/scene/gui/video_stream_player.h +++ b/scene/gui/video_stream_player.h @@ -51,6 +51,8 @@ class VideoStreamPlayer : public Control { RID stream_rid; Ref texture; + Size2 texture_size; + void texture_changed(const Ref &p_texture); AudioRBResampler resampler; Vector mix_buffer;