io-uring: add readable/writable
This commit is contained in:
parent
25d817b722
commit
dcdd91c0b0
31 changed files with 285 additions and 189 deletions
|
|
@ -4,7 +4,7 @@ mod video;
|
|||
|
||||
use {
|
||||
crate::{
|
||||
async_engine::{AsyncError, AsyncFd, SpawnedFuture},
|
||||
async_engine::SpawnedFuture,
|
||||
backend::{
|
||||
Backend, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId,
|
||||
InputEvent, KeyState, TransformMatrix,
|
||||
|
|
@ -103,8 +103,6 @@ pub enum MetalError {
|
|||
CreateEncoder(#[source] DrmError),
|
||||
#[error(transparent)]
|
||||
DrmError(#[from] DrmError),
|
||||
#[error("Could not create an async fd")]
|
||||
CreateAsyncFd(#[source] AsyncError),
|
||||
#[error("Could not create device-paused signal handler")]
|
||||
DevicePauseSignalHandler(#[source] DbusError),
|
||||
#[error("Could not create device-resumed signal handler")]
|
||||
|
|
@ -115,9 +113,9 @@ pub struct MetalBackend {
|
|||
state: Rc<State>,
|
||||
udev: Rc<Udev>,
|
||||
monitor: Rc<UdevMonitor>,
|
||||
monitor_fd: AsyncFd,
|
||||
monitor_fd: Rc<OwnedFd>,
|
||||
libinput: Rc<LibInput>,
|
||||
libinput_fd: AsyncFd,
|
||||
libinput_fd: Rc<OwnedFd>,
|
||||
device_holder: Rc<DeviceHolder>,
|
||||
session: Session,
|
||||
pause_handler: Cell<Option<SignalHandler>>,
|
||||
|
|
@ -204,12 +202,9 @@ impl Backend for MetalBackend {
|
|||
}
|
||||
}
|
||||
|
||||
fn dup_async_fd(state: &Rc<State>, fd: c::c_int) -> Result<AsyncFd, MetalError> {
|
||||
fn dup_fd(fd: c::c_int) -> Result<Rc<OwnedFd>, MetalError> {
|
||||
match uapi::fcntl_dupfd_cloexec(fd, 0) {
|
||||
Ok(m) => match state.eng.fd(&Rc::new(m)) {
|
||||
Ok(fd) => Ok(fd),
|
||||
Err(e) => Err(MetalError::CreateAsyncFd(e)),
|
||||
},
|
||||
Ok(m) => Ok(Rc::new(m)),
|
||||
Err(e) => Err(MetalError::Dup(e.into())),
|
||||
}
|
||||
}
|
||||
|
|
@ -238,8 +233,8 @@ pub async fn create(state: &Rc<State>) -> Result<Rc<MetalBackend>, MetalError> {
|
|||
monitor.add_match_subsystem_devtype(Some("drm"), None)?;
|
||||
monitor.enable_receiving()?;
|
||||
let libinput = Rc::new(LibInput::new(device_holder.clone())?);
|
||||
let monitor_fd = dup_async_fd(&state, monitor.fd())?;
|
||||
let libinput_fd = dup_async_fd(&state, libinput.fd())?;
|
||||
let monitor_fd = dup_fd(monitor.fd())?;
|
||||
let libinput_fd = dup_fd(libinput.fd())?;
|
||||
let metal = Rc::new(MetalBackend {
|
||||
state: state.clone(),
|
||||
udev,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use {
|
||||
crate::{
|
||||
async_engine::FdStatus,
|
||||
backend::{AxisSource, InputEvent, KeyState, ScrollAxis},
|
||||
backends::metal::MetalBackend,
|
||||
fixed::Fixed,
|
||||
|
|
@ -12,9 +11,10 @@ use {
|
|||
},
|
||||
event::LibInputEvent,
|
||||
},
|
||||
utils::errorfmt::ErrorFmt,
|
||||
utils::{bitflags::BitflagsExt, errorfmt::ErrorFmt},
|
||||
},
|
||||
std::rc::Rc,
|
||||
uapi::c,
|
||||
};
|
||||
|
||||
macro_rules! unpack {
|
||||
|
|
@ -49,7 +49,7 @@ macro_rules! unpack {
|
|||
impl MetalBackend {
|
||||
pub async fn handle_libinput_events(self: Rc<Self>) {
|
||||
loop {
|
||||
match self.libinput_fd.readable().await {
|
||||
match self.state.ring.readable(&self.libinput_fd).await {
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
"Cannot wait for libinput fd to become readable: {}",
|
||||
|
|
@ -57,7 +57,7 @@ impl MetalBackend {
|
|||
);
|
||||
break;
|
||||
}
|
||||
Ok(FdStatus::Err) => {
|
||||
Ok(n) if n.intersects(c::POLLERR | c::POLLHUP) => {
|
||||
log::error!("libinput fd fd is in an error state");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use {
|
||||
crate::{
|
||||
async_engine::FdStatus,
|
||||
backend::BackendEvent,
|
||||
backends::metal::{
|
||||
video::{MetalDrmDevice, PendingDrmDevice},
|
||||
|
|
@ -8,7 +7,7 @@ use {
|
|||
},
|
||||
dbus::TRUE,
|
||||
udev::UdevDevice,
|
||||
utils::{errorfmt::ErrorFmt, nonblock::set_nonblock},
|
||||
utils::{bitflags::BitflagsExt, errorfmt::ErrorFmt, nonblock::set_nonblock},
|
||||
video::drm::DrmMaster,
|
||||
wire_dbus::org::freedesktop::login1::session::{PauseDevice, ResumeDevice},
|
||||
},
|
||||
|
|
@ -33,7 +32,7 @@ fn is_primary_node(n: &[u8]) -> bool {
|
|||
impl MetalBackend {
|
||||
pub async fn monitor_devices(self: Rc<Self>) {
|
||||
loop {
|
||||
match self.monitor_fd.readable().await {
|
||||
match self.state.ring.readable(&self.monitor_fd).await {
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
"Cannot wait for udev_monitor to become readable: {}",
|
||||
|
|
@ -41,7 +40,7 @@ impl MetalBackend {
|
|||
);
|
||||
break;
|
||||
}
|
||||
Ok(FdStatus::Err) => {
|
||||
Ok(n) if n.intersects(c::POLLERR | c::POLLHUP) => {
|
||||
log::error!("udev_monitor fd is in an error state");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
async_engine::{AsyncFd, Phase, SpawnedFuture},
|
||||
async_engine::{Phase, SpawnedFuture},
|
||||
backend::{
|
||||
BackendDrmDevice, BackendEvent, Connector, ConnectorEvent, ConnectorId,
|
||||
ConnectorKernelId, DrmDeviceId, MonitorInfo,
|
||||
|
|
@ -64,7 +64,6 @@ pub struct MetalDrmDeviceStatic {
|
|||
pub min_height: u32,
|
||||
pub max_height: u32,
|
||||
pub gbm: GbmDevice,
|
||||
pub async_fd: AsyncFd,
|
||||
pub handle_events: HandleEvents,
|
||||
}
|
||||
|
||||
|
|
@ -749,10 +748,6 @@ impl MetalBackend {
|
|||
Ok(g) => g,
|
||||
Err(e) => return Err(MetalError::GbmDevice(e)),
|
||||
};
|
||||
let async_fd = match self.state.eng.fd(master.fd()) {
|
||||
Ok(f) => f,
|
||||
Err(e) => return Err(MetalError::CreateAsyncFd(e)),
|
||||
};
|
||||
|
||||
let dev = Rc::new(MetalDrmDeviceStatic {
|
||||
id: pending.id,
|
||||
|
|
@ -767,7 +762,6 @@ impl MetalBackend {
|
|||
min_height: resources.min_height,
|
||||
max_height: resources.max_height,
|
||||
gbm,
|
||||
async_fd,
|
||||
handle_events: HandleEvents {
|
||||
handle_events: Cell::new(None),
|
||||
},
|
||||
|
|
@ -883,7 +877,7 @@ impl MetalBackend {
|
|||
|
||||
async fn handle_drm_events(self: Rc<Self>, dev: Rc<MetalDrmDevice>) {
|
||||
loop {
|
||||
if let Err(e) = dev.dev.async_fd.readable().await {
|
||||
if let Err(e) = self.state.ring.readable(dev.dev.master.fd()).await {
|
||||
log::error!("Could not register the DRM fd for reading: {}", ErrorFmt(e));
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ pub enum XBackendError {
|
|||
}
|
||||
|
||||
pub async fn create(state: &Rc<State>) -> Result<Rc<XBackend>, XBackendError> {
|
||||
let c = match Xcon::connect(state.eng.clone()).await {
|
||||
let c = match Xcon::connect(state).await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(XBackendError::CannotConnect(e)),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue