deps: Update smithay

This commit is contained in:
Victoria Brekenfeld 2022-09-28 15:18:04 +02:00
parent 98f34e5279
commit 8e6537de39
7 changed files with 210 additions and 199 deletions

View file

@ -48,6 +48,7 @@ use smithay::{
use std::{
cell::RefCell,
collections::{HashMap, HashSet},
os::unix::io::{FromRawFd, OwnedFd},
path::PathBuf,
rc::Rc,
time::{Duration, Instant},
@ -308,21 +309,23 @@ impl State {
return Ok(());
}
let fd = SessionFd::new(
self.backend
.kms()
.session
.open(
&path,
OFlag::O_RDWR | OFlag::O_CLOEXEC | OFlag::O_NOCTTY | OFlag::O_NONBLOCK,
)
.with_context(|| {
format!(
"Failed to optain file descriptor for drm device: {}",
path.display()
let fd = SessionFd::new(unsafe {
OwnedFd::from_raw_fd(
self.backend
.kms()
.session
.open(
&path,
OFlag::O_RDWR | OFlag::O_CLOEXEC | OFlag::O_NOCTTY | OFlag::O_NONBLOCK,
)
})?,
);
.with_context(|| {
format!(
"Failed to optain file descriptor for drm device: {}",
path.display()
)
})?,
)
});
let mut drm = DrmDevice::new(fd.clone(), false, None)
.with_context(|| format!("Failed to initialize drm device for: {}", path.display()))?;
let drm_node = DrmNode::from_dev_id(dev)?;
@ -330,9 +333,11 @@ impl State {
let gbm = GbmDevice::new(fd)
.with_context(|| format!("Failed to initialize GBM device for {}", path.display()))?;
let egl_display = EGLDisplay::new(&gbm, None).with_context(|| {
format!("Failed to create EGLDisplay for device: {}", path.display())
})?;
let egl_display = unsafe {
EGLDisplay::new(&gbm, None).with_context(|| {
format!("Failed to create EGLDisplay for device: {}", path.display())
})?
};
let egl_device = EGLDevice::device_for_display(&egl_display).with_context(|| {
format!("Unable to find matching egl device for {}", path.display())
})?;

View file

@ -1,39 +1,38 @@
// SPDX-License-Identifier: GPL-3.0-only
use smithay::reexports::nix::unistd::close;
use std::{
fmt,
os::unix::io::{AsRawFd, RawFd},
os::unix::io::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd},
sync::Arc,
};
#[derive(Clone)]
pub struct SessionFd(Arc<DropFd>);
struct DropFd(RawFd);
pub struct SessionFd(Arc<OwnedFd>);
impl SessionFd {
pub fn new(fd: RawFd) -> SessionFd {
SessionFd(Arc::new(DropFd(fd)))
pub fn new(fd: OwnedFd) -> SessionFd {
SessionFd(Arc::new(fd))
}
}
impl fmt::Debug for SessionFd {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Session-provided File Descriptor [{}]", self.0 .0)
write!(
f,
"Session-provided File Descriptor [{}]",
self.0.as_raw_fd()
)
}
}
impl AsFd for SessionFd {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}
impl AsRawFd for SessionFd {
fn as_raw_fd(&self) -> RawFd {
self.0 .0
}
}
impl Drop for DropFd {
fn drop(&mut self) {
if let Err(err) = close(self.0) {
slog_scope::warn!("Failed to close file descriptor {}: {}", self.0, err);
}
self.0.as_raw_fd()
}
}

View file

@ -242,7 +242,8 @@ pub fn init_backend(
let device =
unsafe { GbmDevice::new_from_fd(fd) }.with_context(|| "Failed to create GBM device")?;
// Initialize EGL using the GBM device.
let egl = EGLDisplay::new(&device, None).with_context(|| "Failed to create EGL display")?;
let egl =
unsafe { EGLDisplay::new(&device, None).with_context(|| "Failed to create EGL display")? };
// Create the OpenGL context
let context = EGLContext::new(&egl, None).with_context(|| "Failed to create EGL context")?;
// Create a renderer

View file

@ -11,6 +11,7 @@ use smithay::{
use anyhow::{Context, Result};
use std::{
ffi::OsString,
os::unix::prelude::AsRawFd,
sync::{atomic::Ordering, Arc},
};
@ -117,7 +118,11 @@ fn init_wayland_display(
event_loop
.handle()
.insert_source(
Generic::new(display.backend().poll_fd(), Interest::READ, Mode::Level),
Generic::new(
display.backend().poll_fd().as_raw_fd(),
Interest::READ,
Mode::Level,
),
move |_, _, data: &mut state::Data| match data.display.dispatch_clients(&mut data.state)
{
Ok(_) => Ok(PostAction::Continue),

View file

@ -14,7 +14,7 @@ use smithay::{
use std::{
fs::File,
io::{Seek, SeekFrom},
os::unix::io::{FromRawFd, IntoRawFd},
os::unix::io::{AsRawFd, FromRawFd, IntoRawFd},
time::Instant,
};
@ -243,7 +243,8 @@ fn handle_capture(capture: Capture, frame: ZcosmicExportDmabufFrameV1, start_tim
.zip(dmabuf.offsets().zip(dmabuf.strides()))
.enumerate()
{
let mut file = unsafe { File::from_raw_fd(handle) };
// SAFETY: BorrowedFd is used for seeking
let mut file = unsafe { File::from_raw_fd(handle.as_raw_fd()) };
let size = match file.seek(SeekFrom::End(0)) {
Ok(size) => size,
Err(err) => {
@ -257,7 +258,9 @@ fn handle_capture(capture: Capture, frame: ZcosmicExportDmabufFrameV1, start_tim
frame.cancel(zcosmic_export_dmabuf_frame_v1::CancelReason::Temporary);
return;
}
// SAFETY: Converted back to raw_fd, no chance in ownership
let handle = file.into_raw_fd();
// FDs are dup'ed by wayland-rs before sending them
frame.object(i as u32, handle, size as u32, offset, stride, i as u32);
}