Browse Source

Merge pull request #103912 from unvermuthet/texture-size-changed

VideoStreamPlayer: Redraw when stream resolution changes
Rémi Verschelde 5 months ago
parent
commit
e0c9978cff
2 changed files with 29 additions and 2 deletions
  1. 27 2
      scene/gui/video_stream_player.cpp
  2. 2 0
      scene/gui/video_stream_player.h

+ 27 - 2
scene/gui/video_stream_player.cpp

@@ -176,7 +176,7 @@ void VideoStreamPlayer::_notification(int p_notification) {
 				return;
 				return;
 			}
 			}
 
 
-			Size2 s = expand ? get_size() : texture->get_size();
+			Size2 s = expand ? get_size() : texture_size;
 			draw_texture_rect(texture, Rect2(Point2(), s), false);
 			draw_texture_rect(texture, Rect2(Point2(), s), false);
 		} break;
 		} break;
 
 
@@ -212,9 +212,25 @@ void VideoStreamPlayer::_notification(int p_notification) {
 	}
 	}
 }
 }
 
 
+void VideoStreamPlayer::texture_changed(const Ref<Texture2D> &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 {
 Size2 VideoStreamPlayer::get_minimum_size() const {
 	if (!expand && texture.is_valid()) {
 	if (!expand && texture.is_valid()) {
-		return texture->get_size();
+		return texture_size;
 	} else {
 	} else {
 		return Size2();
 		return Size2();
 	}
 	}
@@ -266,10 +282,19 @@ void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) {
 		stream->connect_changed(callable_mp(this, &VideoStreamPlayer::set_stream).bind(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()) {
 	if (playback.is_valid()) {
 		playback->set_paused(paused);
 		playback->set_paused(paused);
 		texture = playback->get_texture();
 		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();
 		const int channels = playback->get_channels();
 
 
 		AudioServer::get_singleton()->lock();
 		AudioServer::get_singleton()->lock();

+ 2 - 0
scene/gui/video_stream_player.h

@@ -51,6 +51,8 @@ class VideoStreamPlayer : public Control {
 	RID stream_rid;
 	RID stream_rid;
 
 
 	Ref<Texture2D> texture;
 	Ref<Texture2D> texture;
+	Size2 texture_size;
+	void texture_changed(const Ref<Texture2D> &p_texture);
 
 
 	AudioRBResampler resampler;
 	AudioRBResampler resampler;
 	Vector<AudioFrame> mix_buffer;
 	Vector<AudioFrame> mix_buffer;