screencopy: Use new error types
This commit is contained in:
parent
1eef3b3d78
commit
6eb7493ad7
3 changed files with 45 additions and 13 deletions
|
|
@ -26,6 +26,7 @@ use smithay::{
|
|||
allocator::dmabuf::Dmabuf,
|
||||
drm::DrmNode,
|
||||
renderer::{
|
||||
buffer_dimensions,
|
||||
damage::{
|
||||
DamageTrackedRenderer, DamageTrackedRendererError as RenderError, OutputNoMode,
|
||||
},
|
||||
|
|
@ -36,7 +37,7 @@ use smithay::{
|
|||
},
|
||||
},
|
||||
output::Output,
|
||||
utils::{Physical, Rectangle},
|
||||
utils::{Physical, Rectangle, Transform},
|
||||
};
|
||||
|
||||
pub mod cursor;
|
||||
|
|
@ -254,6 +255,13 @@ where
|
|||
if let Some((source, buffers)) = screencopy {
|
||||
if res.is_ok() {
|
||||
for (session, params) in buffers {
|
||||
let mode = output.current_mode().unwrap().size;
|
||||
let buffer_size = buffer_dimensions(¶ms.buffer).unwrap();
|
||||
if mode.to_logical(1).to_buffer(1, Transform::Normal) != buffer_size {
|
||||
session.failed(FailureReason::InvalidSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
match render_to_buffer(
|
||||
gpu.cloned(),
|
||||
renderer,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::{
|
||||
FailureReason, InputType,
|
||||
};
|
||||
|
|
@ -112,7 +113,7 @@ impl ScreencopyHandler for State {
|
|||
.unwrap()
|
||||
.0
|
||||
.borrow_mut()
|
||||
.push(DropableSession(session, FailureReason::OutputDisabled));
|
||||
.push(DropableSession(session, FailureReason::InvalidOutput));
|
||||
|
||||
formats
|
||||
}
|
||||
|
|
@ -134,7 +135,7 @@ impl ScreencopyHandler for State {
|
|||
let workspace = match self.common.shell.space_for_handle_mut(&handle) {
|
||||
Some(workspace) => workspace,
|
||||
None => {
|
||||
session.failed(FailureReason::Unspec);
|
||||
session.failed(FailureReason::InvalidWorkspace);
|
||||
return Vec::new();
|
||||
}
|
||||
};
|
||||
|
|
@ -145,7 +146,7 @@ impl ScreencopyHandler for State {
|
|||
|
||||
workspace
|
||||
.screencopy_sessions
|
||||
.push(DropableSession(session, FailureReason::InvalidOutput));
|
||||
.push(DropableSession(session, FailureReason::InvalidWorkspace));
|
||||
|
||||
formats
|
||||
}
|
||||
|
|
@ -217,7 +218,7 @@ impl ScreencopyHandler for State {
|
|||
.unwrap()
|
||||
.0
|
||||
.borrow_mut()
|
||||
.push(DropableSession(session, FailureReason::ToplevelDestroyed));
|
||||
.push(DropableSession(session, FailureReason::InvalidToplevel));
|
||||
|
||||
formats
|
||||
}
|
||||
|
|
@ -250,7 +251,7 @@ impl ScreencopyHandler for State {
|
|||
|
||||
if buffer_size.to_physical(1) != mode {
|
||||
slog_scope::warn!("Error during screencopy session: Buffer size doesn't match");
|
||||
session.failed(FailureReason::InvalidBuffer);
|
||||
session.failed(FailureReason::InvalidSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -258,7 +259,7 @@ impl ScreencopyHandler for State {
|
|||
let geometry = window.geometry();
|
||||
if buffer_size != geometry.size {
|
||||
slog_scope::warn!("Error during screencopy session: Buffer size doesn't match");
|
||||
session.failed(FailureReason::InvalidBuffer);
|
||||
session.failed(FailureReason::InvalidSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -302,7 +303,7 @@ impl ScreencopyHandler for State {
|
|||
SessionType::Workspace(_output, handle) => {
|
||||
match self.common.shell.space_for_handle_mut(&handle) {
|
||||
Some(workspace) => workspace.pending_buffers.push((session, params)),
|
||||
None => session.failed(FailureReason::OutputDisabled),
|
||||
None => session.failed(FailureReason::InvalidWorkspace),
|
||||
};
|
||||
}
|
||||
SessionType::Window(window) => {
|
||||
|
|
@ -397,7 +398,7 @@ fn formats_for_output(
|
|||
let mode = match output.current_mode() {
|
||||
Some(mode) => mode.size.to_logical(1).to_buffer(1, Transform::Normal),
|
||||
None => {
|
||||
return Err(FailureReason::OutputDisabled);
|
||||
return Err(FailureReason::InvalidOutput);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -557,6 +558,14 @@ pub fn render_output_to_buffer(
|
|||
params: BufferParams,
|
||||
output: &Output,
|
||||
) -> Result<bool, (FailureReason, anyhow::Error)> {
|
||||
let mode = output
|
||||
.current_mode()
|
||||
.map(|mode| mode.size.to_logical(1).to_buffer(1, Transform::Normal));
|
||||
let buffer_size = buffer_dimensions(¶ms.buffer).unwrap();
|
||||
if mode != Some(buffer_size) {
|
||||
return Err((FailureReason::InvalidSize, anyhow!("Output changed mode")));
|
||||
}
|
||||
|
||||
let node = node_from_params(¶ms, &mut state.backend, Some(output));
|
||||
let mut _tmp_multirenderer = None;
|
||||
let renderer = match &mut state.backend {
|
||||
|
|
@ -608,6 +617,14 @@ pub fn render_workspace_to_buffer(
|
|||
output: &Output,
|
||||
handle: &WorkspaceHandle,
|
||||
) -> Result<bool, (FailureReason, anyhow::Error)> {
|
||||
let mode = output
|
||||
.current_mode()
|
||||
.map(|mode| mode.size.to_logical(1).to_buffer(1, Transform::Normal));
|
||||
let buffer_size = buffer_dimensions(¶ms.buffer).unwrap();
|
||||
if mode != Some(buffer_size) {
|
||||
return Err((FailureReason::InvalidSize, anyhow!("Output changed mode")));
|
||||
}
|
||||
|
||||
let node = node_from_params(¶ms, &mut state.backend, Some(output));
|
||||
let mut _tmp_multirenderer = None;
|
||||
let renderer = match &mut state.backend {
|
||||
|
|
@ -660,6 +677,10 @@ pub fn render_window_to_buffer(
|
|||
window: &Window,
|
||||
) -> Result<bool, (FailureReason, anyhow::Error)> {
|
||||
let geometry = window.geometry();
|
||||
let buffer_size = buffer_dimensions(¶ms.buffer).unwrap();
|
||||
if buffer_size != geometry.size.to_buffer(1, Transform::Normal) {
|
||||
return Err((FailureReason::InvalidSize, anyhow!("Window changed size")));
|
||||
}
|
||||
|
||||
let node = node_from_params(¶ms, &mut state.backend, None);
|
||||
let mut _tmp_multirenderer = None;
|
||||
|
|
|
|||
|
|
@ -566,7 +566,10 @@ where
|
|||
|
||||
if let Err(err) = cursor.into_result() {
|
||||
slog_scope::warn!("Client did send unknown cursor mode: {}", err);
|
||||
session.failed(FailureReason::UnknownInput);
|
||||
session.post_error(
|
||||
zcosmic_screencopy_session_v1::Error::InvalidCursorMode,
|
||||
"Unknown cursor mode, wrong protocol version?",
|
||||
);
|
||||
return None;
|
||||
};
|
||||
let session = Session {
|
||||
|
|
@ -661,7 +664,7 @@ where
|
|||
return;
|
||||
}
|
||||
};
|
||||
session.obj.failed(FailureReason::ToplevelDestroyed);
|
||||
session.obj.failed(FailureReason::InvalidToplevel);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
|
@ -697,7 +700,7 @@ where
|
|||
return;
|
||||
}
|
||||
};
|
||||
session.failed(FailureReason::InvalidOutput);
|
||||
session.failed(FailureReason::InvalidWorkspace);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
|
@ -782,7 +785,7 @@ where
|
|||
return;
|
||||
}
|
||||
};
|
||||
session.failed(FailureReason::UnknownInput);
|
||||
session.failed(FailureReason::InvalidSeat);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue