screencopy: Make threadsafe
This commit is contained in:
parent
e78e199663
commit
aae16c49dc
3 changed files with 22 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Borrow, cell::RefCell, collections::HashMap};
|
||||
use std::{borrow::Borrow, collections::HashMap, sync::Mutex};
|
||||
|
||||
use smithay::{
|
||||
backend::{
|
||||
|
|
@ -92,8 +92,8 @@ impl ScreencopyHandler for State {
|
|||
return;
|
||||
};
|
||||
|
||||
session.user_data().insert_if_missing(|| {
|
||||
RefCell::new(SessionUserData::new(OutputDamageTracker::from_output(
|
||||
session.user_data().insert_if_missing_threadsafe(|| {
|
||||
Mutex::new(SessionUserData::new(OutputDamageTracker::from_output(
|
||||
&output,
|
||||
)))
|
||||
});
|
||||
|
|
@ -107,8 +107,8 @@ impl ScreencopyHandler for State {
|
|||
return;
|
||||
};
|
||||
|
||||
session.user_data().insert_if_missing(|| {
|
||||
RefCell::new(SessionUserData::new(OutputDamageTracker::from_output(
|
||||
session.user_data().insert_if_missing_threadsafe(|| {
|
||||
Mutex::new(SessionUserData::new(OutputDamageTracker::from_output(
|
||||
workspace.output(),
|
||||
)))
|
||||
});
|
||||
|
|
@ -116,8 +116,8 @@ impl ScreencopyHandler for State {
|
|||
}
|
||||
ImageSourceData::Toplevel(mut toplevel) => {
|
||||
let size = toplevel.geometry().size.to_physical(1);
|
||||
session.user_data().insert_if_missing(|| {
|
||||
RefCell::new(SessionUserData::new(OutputDamageTracker::new(
|
||||
session.user_data().insert_if_missing_threadsafe(|| {
|
||||
Mutex::new(SessionUserData::new(OutputDamageTracker::new(
|
||||
size,
|
||||
1.0,
|
||||
Transform::Normal,
|
||||
|
|
@ -153,8 +153,8 @@ impl ScreencopyHandler for State {
|
|||
(pointer_loc, pointer_size, hotspot)
|
||||
};
|
||||
|
||||
session.user_data().insert_if_missing(|| {
|
||||
RefCell::new(SessionUserData::new(OutputDamageTracker::new(
|
||||
session.user_data().insert_if_missing_threadsafe(|| {
|
||||
Mutex::new(SessionUserData::new(OutputDamageTracker::new(
|
||||
pointer_size.to_logical(1, Transform::Normal).to_physical(1),
|
||||
1.0,
|
||||
Transform::Normal,
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ where
|
|||
#[cfg(feature = "debug")]
|
||||
puffin::profile_function!();
|
||||
|
||||
let mut session_damage_tracking = session.borrow_mut();
|
||||
let mut session_damage_tracking = session.lock().unwrap();
|
||||
|
||||
let buffer = frame.buffer();
|
||||
let age = session_damage_tracking.age_for_buffer(&buffer);
|
||||
|
|
@ -212,7 +212,7 @@ pub fn render_workspace_to_buffer(
|
|||
};
|
||||
session.update_constraints(constraints);
|
||||
if let Some(data) = session.user_data().get::<SessionData>() {
|
||||
*data.borrow_mut() = SessionUserData::new(OutputDamageTracker::from_output(&output));
|
||||
*data.lock().unwrap() = SessionUserData::new(OutputDamageTracker::from_output(&output));
|
||||
}
|
||||
frame.fail(FailureReason::BufferConstraints);
|
||||
return;
|
||||
|
|
@ -478,7 +478,7 @@ pub fn render_window_to_buffer(
|
|||
session.update_constraints(constraints);
|
||||
if let Some(data) = session.user_data().get::<SessionData>() {
|
||||
let size = geometry.size.to_physical(1);
|
||||
*data.borrow_mut() =
|
||||
*data.lock().unwrap() =
|
||||
SessionUserData::new(OutputDamageTracker::new(size, 1.0, Transform::Normal));
|
||||
}
|
||||
frame.fail(FailureReason::BufferConstraints);
|
||||
|
|
@ -736,7 +736,7 @@ pub fn render_cursor_to_buffer(
|
|||
};
|
||||
session.update_constraints(constraints);
|
||||
if let Some(data) = session.user_data().get::<SessionData>() {
|
||||
*data.borrow_mut() = SessionUserData::new(OutputDamageTracker::new(
|
||||
*data.lock().unwrap() = SessionUserData::new(OutputDamageTracker::new(
|
||||
cursor_size.to_logical(1, Transform::Normal).to_physical(1),
|
||||
1.0,
|
||||
Transform::Normal,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::{
|
|||
cell::RefCell,
|
||||
collections::HashMap,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
use smithay::{
|
||||
|
|
@ -16,9 +17,9 @@ use crate::{
|
|||
};
|
||||
|
||||
type ScreencopySessionsData = RefCell<ScreencopySessions>;
|
||||
type PendingScreencopyBuffers = RefCell<Vec<(Session, DropableFrame)>>;
|
||||
type PendingScreencopyBuffers = Mutex<Vec<(Session, DropableFrame)>>;
|
||||
|
||||
pub type SessionData = RefCell<SessionUserData>;
|
||||
pub type SessionData = Mutex<SessionUserData>;
|
||||
|
||||
pub struct SessionUserData {
|
||||
pub dt: OutputDamageTracker,
|
||||
|
|
@ -148,16 +149,17 @@ impl SessionHolder for Output {
|
|||
impl FrameHolder for Output {
|
||||
fn add_frame(&mut self, session: Session, frame: Frame) {
|
||||
self.user_data()
|
||||
.insert_if_missing(PendingScreencopyBuffers::default);
|
||||
.insert_if_missing_threadsafe(PendingScreencopyBuffers::default);
|
||||
self.user_data()
|
||||
.get::<PendingScreencopyBuffers>()
|
||||
.unwrap()
|
||||
.borrow_mut()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push((session, DropableFrame(Some(frame))));
|
||||
}
|
||||
fn remove_frame(&mut self, frame: &Frame) {
|
||||
if let Some(pending) = self.user_data().get::<PendingScreencopyBuffers>() {
|
||||
pending.borrow_mut().retain(|(_, f)| f != frame);
|
||||
pending.lock().unwrap().retain(|(_, f)| f != frame);
|
||||
}
|
||||
}
|
||||
fn take_pending_frames(&self) -> Vec<(Session, Frame)> {
|
||||
|
|
@ -165,7 +167,8 @@ impl FrameHolder for Output {
|
|||
.get::<PendingScreencopyBuffers>()
|
||||
.map(|pending| {
|
||||
pending
|
||||
.borrow_mut()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.split_off(0)
|
||||
.into_iter()
|
||||
.map(|(s, mut f)| (s, f.0.take().unwrap()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue