gtk4: Flush frames from the paintable when shutting down the sink

Otherwise it will continue showing the last frames forever and keep
around the frames forever instead of rendering black.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/281

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1024>
This commit is contained in:
Sebastian Dröge 2022-12-22 20:44:25 +02:00 committed by GStreamer Marge Bot
parent 71c268da14
commit 0c8e69ed7c
3 changed files with 20 additions and 0 deletions

View file

@ -221,6 +221,14 @@ impl ElementImpl for PaintableSink {
gst::StateChange::PausedToReady => { gst::StateChange::PausedToReady => {
let _ = self.info.lock().unwrap().take(); let _ = self.info.lock().unwrap().take();
let _ = self.pending_frame.lock().unwrap().take(); let _ = self.pending_frame.lock().unwrap().take();
let self_ = self.to_owned();
utils::invoke_on_main_thread(move || {
let paintable = self_.paintable.lock().unwrap();
if let Some(paintable) = &*paintable {
paintable.get().handle_flush_frames();
}
});
} }
_ => (), _ => (),
} }

View file

@ -196,4 +196,12 @@ impl Paintable {
self.obj().invalidate_contents(); self.obj().invalidate_contents();
} }
} }
pub(super) fn handle_flush_frames(&self) {
gst::debug!(CAT, imp: self, "Flushing frames");
self.paintables.borrow_mut().clear();
self.cached_textures.borrow_mut().clear();
self.obj().invalidate_size();
self.obj().invalidate_contents();
}
} }

View file

@ -33,4 +33,8 @@ impl Paintable {
pub(crate) fn handle_frame_changed(&self, frame: Option<Frame>) { pub(crate) fn handle_frame_changed(&self, frame: Option<Frame>) {
self.imp().handle_frame_changed(frame); self.imp().handle_frame_changed(frame);
} }
pub(crate) fn handle_flush_frames(&self) {
self.imp().handle_flush_frames();
}
} }