protocols/screencopy: Make frame/session send stopped/fail on drop

Previously, `Frame` was stored in KMS frame udata, but in some cases the
udata was dropped without a capture happening, and `Frame` did not
implement `Drop`, so `fail` was never sent.

Instead, rename `DropableFrame` to `Frame` and `Frame` to `FrameRef`, so
we can have a single instance of `Frame`, that will send `fail` on drop.
This guarantees either `.success` or `.fail` are send, as long as its
not leaked.

This seems to fix https://github.com/pop-os/cosmic-comp/issues/1305.
xdg-desktop-portal-cosmic prints an error, buy retries (as it should for
an `Unknown` error; though maybe there should be a retry limit) and the
session continues working.

(Not sure if it should be sending `failed`, or queing it with the next
frame so it can send `success` to the client, but this works and is
desirable as a failsafe anyway.)

`Session` and `CursorSession` are similiarly updated.

`.fail()`, `.success()`, and `.stop()` now consume
`Frame`/`Session`/`CursorSession`. So to stop a session, it is now
necessary to call `.remove_session()`, but then simply dropping with
send `.stop()`.

Factoring out some `Request::Capture` handling into a `capture_frame`
function seems to clean up error handling and such a bit.
This commit is contained in:
Ian Douglas Scott 2025-04-30 14:32:33 -07:00 committed by Ian Douglas Scott
parent 9c7033df10
commit 194d5c8967
7 changed files with 346 additions and 367 deletions

View file

@ -5,7 +5,7 @@ use crate::{
config::{AdaptiveSync, EdidProduct, OutputConfig, OutputState, ScreenFilter},
shell::Shell,
utils::prelude::*,
wayland::protocols::screencopy::Frame as ScreencopyFrame,
wayland::protocols::screencopy::Frame,
};
use anyhow::{Context, Result};
@ -65,7 +65,7 @@ pub type GbmDrmOutputManager = DrmOutputManager<
GbmFramebufferExporter<DrmDeviceFd>,
Option<(
OutputPresentationFeedback,
Receiver<(ScreencopyFrame, Vec<Rectangle<i32, BufferCoords>>)>,
Receiver<(Frame, Vec<Rectangle<i32, BufferCoords>>)>,
Duration,
)>,
DrmDeviceFd,

View file

@ -13,7 +13,7 @@ use crate::{
wayland::{
handlers::screencopy::{submit_buffer, FrameHolder, SessionData},
protocols::screencopy::{
FailureReason, Frame as ScreencopyFrame, Session as ScreencopySession,
FailureReason, Frame as ScreencopyFrame, SessionRef as ScreencopySessionRef,
},
},
};
@ -1024,7 +1024,7 @@ impl SurfaceThreadState {
// so let's collect everything we need for screencopy now
let mut has_cursor_mode_none = false;
let frames: Vec<(
ScreencopySession,
ScreencopySessionRef,
ScreencopyFrame,
Result<(Option<Vec<Rectangle<i32, Physical>>>, RenderElementStates), OutputNoMode>,
)> = self