-
Notifications
You must be signed in to change notification settings - Fork 208
Fix VRAM leak: use weak references in ToplevelHandleState and stop capture sessions #2095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
91e0b34
688e1e5
b42621a
1af79b0
cb89e77
44f78cf
0f411a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ use smithay::{ | |
| }, | ||
| }; | ||
|
|
||
| use smithay::utils::user_data::UserDataMap; | ||
|
|
||
| use crate::shell::{CosmicSurface, Workspace}; | ||
|
|
||
| type ImageCopySessionsData = RefCell<ImageCopySessions>; | ||
|
|
@@ -33,6 +35,25 @@ pub struct ImageCopySessions { | |
| cursor_sessions: Vec<CursorSession>, | ||
| } | ||
|
|
||
| /// Drop all capture sessions stored in the given `UserDataMap`. | ||
| /// | ||
| /// When a toplevel is destroyed, its owned `Session` objects must be dropped | ||
| /// so that `Session::drop()` fires — this fails active frames and sends | ||
| /// `stopped` to the client, releasing GPU buffers. | ||
| /// | ||
| /// Smithay doesn't automatically stop sessions when their capture source's | ||
| /// underlying toplevel dies. A cleaner long-term fix would be in smithay's | ||
| /// `ImageCopyCaptureState::cleanup()` — e.g. stopping sessions whose | ||
| /// `source().alive()` is false — so all compositors benefit without manual | ||
| /// session management. For now, we handle it on the cosmic-comp side. | ||
| pub fn stop_all_capture_sessions(user_data: &UserDataMap) { | ||
| if let Some(data) = user_data.get::<ImageCopySessionsData>() { | ||
| let mut data = data.borrow_mut(); | ||
| data.sessions.clear(); | ||
| data.cursor_sessions.clear(); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole function seems unnecessary and the documentation wrong? As long as (Looking at our code this, it might be that output-session which are created with a |
||
| } | ||
|
|
||
| pub trait SessionHolder { | ||
| fn add_session(&mut self, session: Session); | ||
| fn remove_session(&mut self, session: &SessionRef); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ use super::{ | |
| workspace::{WorkspaceHandle, WorkspaceHandler}, | ||
| }; | ||
| use crate::{ | ||
| shell::CosmicSurface, | ||
| shell::WeakCosmicSurface, | ||
| }; | ||
| use cosmic_protocols::image_capture_source::v1::server::{ | ||
| zcosmic_workspace_image_capture_source_manager_v1::{ | ||
|
|
@@ -30,11 +30,17 @@ pub struct WorkspaceImageCaptureSourceManagerGlobalData { | |
| filter: Box<dyn for<'a> Fn(&'a Client) -> bool + Send + Sync>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq)] | ||
| /// What a capture source targets. | ||
| /// | ||
| /// `Toplevel` uses `WeakCosmicSurface` (not a strong `CosmicSurface`) so | ||
| /// that capture sources created by cosmic-workspaces for window thumbnails | ||
| /// don't prevent the underlying window from being dropped. `Output` already | ||
| /// uses `WeakOutput` for the same reason. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please drop this comment. |
||
| #[derive(Debug, Clone)] | ||
| pub enum ImageCaptureSourceKind { | ||
| Output(WeakOutput), | ||
| Workspace(WorkspaceHandle), | ||
| Toplevel(CosmicSurface), | ||
| Toplevel(WeakCosmicSurface), | ||
| Destroyed, | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can just return, we need to invalidate the session here.