cargo fmt
This commit is contained in:
parent
671e2053e9
commit
c630bd9086
|
@ -3,9 +3,11 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
|
#[cfg(feature = "egl")]
|
||||||
|
use smithay::backend::{egl::display::EGLBufferReader, renderer::ImportEgl};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
renderer::{Frame, Renderer, Texture, Transform, ImportShm, ImportDma, BufferType, buffer_type},
|
renderer::{buffer_type, BufferType, Frame, ImportDma, ImportShm, Renderer, Texture, Transform},
|
||||||
SwapBuffersError,
|
SwapBuffersError,
|
||||||
},
|
},
|
||||||
reexports::wayland_server::protocol::{wl_buffer, wl_surface},
|
reexports::wayland_server::protocol::{wl_buffer, wl_surface},
|
||||||
|
@ -16,11 +18,6 @@ use smithay::{
|
||||||
seat::CursorImageRole,
|
seat::CursorImageRole,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "egl")]
|
|
||||||
use smithay::backend::{
|
|
||||||
egl::display::EGLBufferReader,
|
|
||||||
renderer::ImportEgl,
|
|
||||||
};
|
|
||||||
// hacky...
|
// hacky...
|
||||||
#[cfg(not(feature = "egl"))]
|
#[cfg(not(feature = "egl"))]
|
||||||
pub trait ImportEgl {}
|
pub trait ImportEgl {}
|
||||||
|
@ -46,8 +43,7 @@ pub fn draw_cursor<R, E, F, T>(
|
||||||
renderer: &mut R,
|
renderer: &mut R,
|
||||||
frame: &mut F,
|
frame: &mut F,
|
||||||
surface: &wl_surface::WlSurface,
|
surface: &wl_surface::WlSurface,
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
|
||||||
egl_buffer_reader: Option<&EGLBufferReader>,
|
|
||||||
(x, y): (i32, i32),
|
(x, y): (i32, i32),
|
||||||
token: MyCompositorToken,
|
token: MyCompositorToken,
|
||||||
log: &Logger,
|
log: &Logger,
|
||||||
|
@ -84,8 +80,7 @@ fn draw_surface_tree<R, E, F, T>(
|
||||||
renderer: &mut R,
|
renderer: &mut R,
|
||||||
frame: &mut F,
|
frame: &mut F,
|
||||||
root: &wl_surface::WlSurface,
|
root: &wl_surface::WlSurface,
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
|
||||||
egl_buffer_reader: Option<&EGLBufferReader>,
|
|
||||||
location: (i32, i32),
|
location: (i32, i32),
|
||||||
compositor_token: MyCompositorToken,
|
compositor_token: MyCompositorToken,
|
||||||
log: &Logger,
|
log: &Logger,
|
||||||
|
@ -110,7 +105,7 @@ where
|
||||||
let texture = match buffer_type(
|
let texture = match buffer_type(
|
||||||
&buffer,
|
&buffer,
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
egl_buffer_reader
|
egl_buffer_reader,
|
||||||
) {
|
) {
|
||||||
Some(BufferType::Shm) => {
|
Some(BufferType::Shm) => {
|
||||||
let damage = attributes
|
let damage = attributes
|
||||||
|
@ -126,10 +121,15 @@ where
|
||||||
buffer.release();
|
buffer.release();
|
||||||
// don't return the buffer as it is already released
|
// don't return the buffer as it is already released
|
||||||
Some((result, None))
|
Some((result, None))
|
||||||
},
|
}
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
Some(BufferType::Egl) => Some((renderer.import_egl_buffer(&buffer, egl_buffer_reader.unwrap()), Some(buffer))),
|
Some(BufferType::Egl) => Some((
|
||||||
Some(BufferType::Dma) => Some((renderer.import_dma_buffer(&buffer), Some(buffer))),
|
renderer.import_egl_buffer(&buffer, egl_buffer_reader.unwrap()),
|
||||||
|
Some(buffer),
|
||||||
|
)),
|
||||||
|
Some(BufferType::Dma) => {
|
||||||
|
Some((renderer.import_dma_buffer(&buffer), Some(buffer)))
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!(log, "Unknown buffer format for: {:?}", buffer);
|
error!(log, "Unknown buffer format for: {:?}", buffer);
|
||||||
buffer.release();
|
buffer.release();
|
||||||
|
@ -147,8 +147,8 @@ where
|
||||||
if let Some(buffer) = buffer {
|
if let Some(buffer) = buffer {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => {},
|
None => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,8 +204,7 @@ where
|
||||||
pub fn draw_windows<R, E, F, T>(
|
pub fn draw_windows<R, E, F, T>(
|
||||||
renderer: &mut R,
|
renderer: &mut R,
|
||||||
frame: &mut F,
|
frame: &mut F,
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
|
||||||
egl_buffer_reader: Option<&EGLBufferReader>,
|
|
||||||
window_map: &MyWindowMap,
|
window_map: &MyWindowMap,
|
||||||
output_rect: Option<Rectangle>,
|
output_rect: Option<Rectangle>,
|
||||||
compositor_token: MyCompositorToken,
|
compositor_token: MyCompositorToken,
|
||||||
|
@ -252,8 +251,7 @@ pub fn draw_dnd_icon<R, E, F, T>(
|
||||||
renderer: &mut R,
|
renderer: &mut R,
|
||||||
frame: &mut F,
|
frame: &mut F,
|
||||||
surface: &wl_surface::WlSurface,
|
surface: &wl_surface::WlSurface,
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
|
||||||
egl_buffer_reader: Option<&EGLBufferReader>,
|
|
||||||
(x, y): (i32, i32),
|
(x, y): (i32, i32),
|
||||||
token: MyCompositorToken,
|
token: MyCompositorToken,
|
||||||
log: &::slog::Logger,
|
log: &::slog::Logger,
|
||||||
|
@ -278,6 +276,6 @@ where
|
||||||
egl_buffer_reader,
|
egl_buffer_reader,
|
||||||
(x, y),
|
(x, y),
|
||||||
token,
|
token,
|
||||||
log
|
log,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{process::Command, sync::atomic::Ordering};
|
use std::{process::Command, sync::atomic::Ordering};
|
||||||
|
|
||||||
use crate::AnvilState;
|
|
||||||
#[cfg(feature = "udev")]
|
#[cfg(feature = "udev")]
|
||||||
use crate::udev::UdevData;
|
use crate::udev::UdevData;
|
||||||
#[cfg(feature = "winit")]
|
#[cfg(feature = "winit")]
|
||||||
use crate::winit::WinitData;
|
use crate::winit::WinitData;
|
||||||
|
use crate::AnvilState;
|
||||||
|
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::input::{
|
backend::input::{
|
||||||
|
|
|
@ -12,6 +12,11 @@ use std::{
|
||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
|
|
||||||
|
#[cfg(feature = "egl")]
|
||||||
|
use smithay::{
|
||||||
|
backend::{drm::DevPath, egl::display::EGLBufferReader, renderer::ImportDma, udev::primary_gpu},
|
||||||
|
wayland::dmabuf::init_dmabuf_global,
|
||||||
|
};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
drm::{DrmDevice, DrmError, DrmEvent, DrmRenderSurface},
|
drm::{DrmDevice, DrmError, DrmEvent, DrmRenderSurface},
|
||||||
|
@ -19,7 +24,7 @@ use smithay::{
|
||||||
libinput::{LibinputInputBackend, LibinputSessionInterface},
|
libinput::{LibinputInputBackend, LibinputSessionInterface},
|
||||||
renderer::{
|
renderer::{
|
||||||
gles2::{Gles2Renderer, Gles2Texture},
|
gles2::{Gles2Renderer, Gles2Texture},
|
||||||
Frame, Renderer, Transform
|
Frame, Renderer, Transform,
|
||||||
},
|
},
|
||||||
session::{auto::AutoSession, Session, Signal as SessionSignal},
|
session::{auto::AutoSession, Session, Signal as SessionSignal},
|
||||||
udev::{UdevBackend, UdevEvent},
|
udev::{UdevBackend, UdevEvent},
|
||||||
|
@ -55,11 +60,6 @@ use smithay::{
|
||||||
seat::CursorImageStatus,
|
seat::CursorImageStatus,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "egl")]
|
|
||||||
use smithay::{
|
|
||||||
backend::{drm::DevPath, egl::display::EGLBufferReader, udev::primary_gpu, renderer::ImportDma},
|
|
||||||
wayland::dmabuf::init_dmabuf_global,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::drawing::*;
|
use crate::drawing::*;
|
||||||
use crate::shell::{MyWindowMap, Roles};
|
use crate::shell::{MyWindowMap, Roles};
|
||||||
|
@ -122,7 +122,7 @@ pub fn run_udev(
|
||||||
let data = UdevData {
|
let data = UdevData {
|
||||||
session,
|
session,
|
||||||
output_map: Vec::new(),
|
output_map: Vec::new(),
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
primary_gpu,
|
primary_gpu,
|
||||||
backends: HashMap::new(),
|
backends: HashMap::new(),
|
||||||
signaler: session_signal.clone(),
|
signaler: session_signal.clone(),
|
||||||
|
@ -194,19 +194,24 @@ pub fn run_udev(
|
||||||
formats.extend(surface.borrow_mut().renderer().dmabuf_formats().cloned());
|
formats.extend(surface.borrow_mut().renderer().dmabuf_formats().cloned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_dmabuf_global(&mut *display.borrow_mut(), formats, |buffer, mut ddata| {
|
init_dmabuf_global(
|
||||||
let anvil_state = ddata.get::<AnvilState<UdevData>>().unwrap();
|
&mut *display.borrow_mut(),
|
||||||
for backend_data in anvil_state.backend_data.backends.values() {
|
formats,
|
||||||
let surfaces = backend_data.surfaces.borrow_mut();
|
|buffer, mut ddata| {
|
||||||
if let Some(surface) = surfaces.values().next() {
|
let anvil_state = ddata.get::<AnvilState<UdevData>>().unwrap();
|
||||||
if surface.borrow_mut().renderer().import_dmabuf(buffer).is_ok() {
|
for backend_data in anvil_state.backend_data.backends.values() {
|
||||||
return true;
|
let surfaces = backend_data.surfaces.borrow_mut();
|
||||||
|
if let Some(surface) = surfaces.values().next() {
|
||||||
|
if surface.borrow_mut().renderer().import_dmabuf(buffer).is_ok() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
false
|
||||||
false
|
},
|
||||||
}, log.clone());
|
log.clone(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let udev_event_source = event_loop
|
let udev_event_source = event_loop
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::{cell::RefCell, rc::Rc, sync::atomic::Ordering, time::Duration};
|
use std::{cell::RefCell, rc::Rc, sync::atomic::Ordering, time::Duration};
|
||||||
|
|
||||||
|
#[cfg(feature = "egl")]
|
||||||
|
use smithay::{backend::renderer::ImportDma, wayland::dmabuf::init_dmabuf_global};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{input::InputBackend, renderer::Frame, winit, SwapBuffersError},
|
backend::{input::InputBackend, renderer::Frame, winit, SwapBuffersError},
|
||||||
reexports::{
|
reexports::{
|
||||||
|
@ -11,11 +13,6 @@ use smithay::{
|
||||||
seat::CursorImageStatus,
|
seat::CursorImageStatus,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "egl")]
|
|
||||||
use smithay::{
|
|
||||||
backend::renderer::ImportDma,
|
|
||||||
wayland::dmabuf::init_dmabuf_global,
|
|
||||||
};
|
|
||||||
|
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
|
|
||||||
|
@ -45,11 +42,19 @@ pub fn run_winit(
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
if reader.is_some() {
|
if reader.is_some() {
|
||||||
info!(log, "EGL hardware-acceleration enabled");
|
info!(log, "EGL hardware-acceleration enabled");
|
||||||
let dmabuf_formats = renderer.borrow_mut().renderer().dmabuf_formats().cloned().collect::<Vec<_>>();
|
let dmabuf_formats = renderer
|
||||||
|
.borrow_mut()
|
||||||
|
.renderer()
|
||||||
|
.dmabuf_formats()
|
||||||
|
.cloned()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
let renderer = renderer.clone();
|
let renderer = renderer.clone();
|
||||||
init_dmabuf_global(&mut *display.borrow_mut(), dmabuf_formats, move |buffer, _| {
|
init_dmabuf_global(
|
||||||
renderer.borrow_mut().renderer().import_dmabuf(buffer).is_ok()
|
&mut *display.borrow_mut(),
|
||||||
}, log.clone());
|
dmabuf_formats,
|
||||||
|
move |buffer, _| renderer.borrow_mut().renderer().import_dmabuf(buffer).is_ok(),
|
||||||
|
log.clone(),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let (w, h): (u32, u32) = renderer.borrow().window_size().physical_size.into();
|
let (w, h): (u32, u32) = renderer.borrow().window_size().physical_size.into();
|
||||||
|
|
|
@ -96,15 +96,15 @@ fn main() {
|
||||||
.supported_formats(surface.plane())
|
.supported_formats(surface.plane())
|
||||||
.expect("Unable to readout formats for surface")
|
.expect("Unable to readout formats for surface")
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|format| if format.code == Fourcc::Argb8888 { Some(format.modifier) } else { None })
|
.filter_map(|format| {
|
||||||
|
if format.code == Fourcc::Argb8888 {
|
||||||
|
Some(format.modifier)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut swapchain = Swapchain::new(
|
let mut swapchain = Swapchain::new(allocator, w.into(), h.into(), Fourcc::Argb8888, mods);
|
||||||
allocator,
|
|
||||||
w.into(),
|
|
||||||
h.into(),
|
|
||||||
Fourcc::Argb8888,
|
|
||||||
mods,
|
|
||||||
);
|
|
||||||
let first_buffer: Slot<DumbBuffer<FdWrapper>, _> = swapchain.acquire().unwrap().unwrap();
|
let first_buffer: Slot<DumbBuffer<FdWrapper>, _> = swapchain.acquire().unwrap().unwrap();
|
||||||
let framebuffer = surface.add_framebuffer(first_buffer.handle(), 32, 32).unwrap();
|
let framebuffer = surface.add_framebuffer(first_buffer.handle(), 32, 32).unwrap();
|
||||||
*first_buffer.userdata() = Some(framebuffer);
|
*first_buffer.userdata() = Some(framebuffer);
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
//! the lifetime of the buffer. E.g. when you are only caching associated resources for a dmabuf.
|
//! the lifetime of the buffer. E.g. when you are only caching associated resources for a dmabuf.
|
||||||
|
|
||||||
use super::{Buffer, Format, Fourcc, Modifier};
|
use super::{Buffer, Format, Fourcc, Modifier};
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
use std::os::unix::io::{IntoRawFd, RawFd};
|
use std::os::unix::io::{IntoRawFd, RawFd};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::hash::{Hash, Hasher};
|
|
||||||
|
|
||||||
/// Maximum amount of planes this implementation supports
|
/// Maximum amount of planes this implementation supports
|
||||||
pub const MAX_PLANES: usize = 4;
|
pub const MAX_PLANES: usize = 4;
|
||||||
|
|
|
@ -28,19 +28,16 @@ use crate::backend::egl::{
|
||||||
};
|
};
|
||||||
use crate::backend::SwapBuffersError;
|
use crate::backend::SwapBuffersError;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
|
||||||
|
use super::ImportEgl;
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
use crate::{
|
use super::{ImportDma, ImportShm};
|
||||||
utils::Rectangle,
|
|
||||||
wayland::compositor::SurfaceAttributes,
|
|
||||||
};
|
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
|
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
|
||||||
use crate::backend::egl::{display::EGLBufferReader, Format as EGLFormat};
|
use crate::backend::egl::{display::EGLBufferReader, Format as EGLFormat};
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
use wayland_server::protocol::{wl_buffer, wl_shm};
|
use crate::{utils::Rectangle, wayland::compositor::SurfaceAttributes};
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
use super::{ImportShm, ImportDma};
|
use wayland_server::protocol::{wl_buffer, wl_shm};
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
|
|
||||||
use super::ImportEgl;
|
|
||||||
|
|
||||||
#[allow(clippy::all, missing_docs)]
|
#[allow(clippy::all, missing_docs)]
|
||||||
pub mod ffi {
|
pub mod ffi {
|
||||||
|
@ -480,8 +477,7 @@ impl Gles2Renderer {
|
||||||
fn cleanup(&mut self) -> Result<(), Gles2Error> {
|
fn cleanup(&mut self) -> Result<(), Gles2Error> {
|
||||||
self.make_current()?;
|
self.make_current()?;
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
self.dmabuf_cache
|
self.dmabuf_cache.retain(|entry, _tex| entry.upgrade().is_some());
|
||||||
.retain(|entry, _tex| entry.upgrade().is_some());
|
|
||||||
for resource in self.destruction_callback.try_iter() {
|
for resource in self.destruction_callback.try_iter() {
|
||||||
match resource {
|
match resource {
|
||||||
CleanupResource::Texture(texture) => unsafe {
|
CleanupResource::Texture(texture) => unsafe {
|
||||||
|
@ -618,7 +614,11 @@ impl ImportShm for Gles2Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
impl ImportEgl for Gles2Renderer {
|
impl ImportEgl for Gles2Renderer {
|
||||||
fn import_egl_buffer(
|
fn import_egl_buffer(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -664,10 +664,7 @@ impl ImportEgl for Gles2Renderer {
|
||||||
|
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
impl ImportDma for Gles2Renderer {
|
impl ImportDma for Gles2Renderer {
|
||||||
fn import_dmabuf(
|
fn import_dmabuf(&mut self, buffer: &Dmabuf) -> Result<Gles2Texture, Gles2Error> {
|
||||||
&mut self,
|
|
||||||
buffer: &Dmabuf,
|
|
||||||
) -> Result<Gles2Texture, Gles2Error> {
|
|
||||||
if !self.extensions.iter().any(|ext| ext == "GL_OES_EGL_image") {
|
if !self.extensions.iter().any(|ext| ext == "GL_OES_EGL_image") {
|
||||||
return Err(Gles2Error::GLExtensionNotSupported(&["GL_OES_EGL_image"]));
|
return Err(Gles2Error::GLExtensionNotSupported(&["GL_OES_EGL_image"]));
|
||||||
}
|
}
|
||||||
|
@ -676,7 +673,10 @@ impl ImportDma for Gles2Renderer {
|
||||||
let is_external = !self.egl.dmabuf_render_formats().contains(&buffer.format());
|
let is_external = !self.egl.dmabuf_render_formats().contains(&buffer.format());
|
||||||
|
|
||||||
self.make_current()?;
|
self.make_current()?;
|
||||||
let image = self.egl.display.create_image_from_dmabuf(&buffer)
|
let image = self
|
||||||
|
.egl
|
||||||
|
.display
|
||||||
|
.create_image_from_dmabuf(&buffer)
|
||||||
.map_err(Gles2Error::BindBufferEGLError)?;
|
.map_err(Gles2Error::BindBufferEGLError)?;
|
||||||
|
|
||||||
let tex = self.import_egl_image(image, is_external, None)?;
|
let tex = self.import_egl_image(image, is_external, None)?;
|
||||||
|
@ -695,7 +695,7 @@ impl ImportDma for Gles2Renderer {
|
||||||
Ok(texture)
|
Ok(texture)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
fn dmabuf_formats<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Format> + 'a> {
|
fn dmabuf_formats<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Format> + 'a> {
|
||||||
Box::new(self.egl.dmabuf_texture_formats().iter())
|
Box::new(self.egl.dmabuf_texture_formats().iter())
|
||||||
|
@ -704,10 +704,7 @@ impl ImportDma for Gles2Renderer {
|
||||||
|
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
impl Gles2Renderer {
|
impl Gles2Renderer {
|
||||||
fn existing_dmabuf_texture(
|
fn existing_dmabuf_texture(&self, buffer: &Dmabuf) -> Result<Option<Gles2Texture>, Gles2Error> {
|
||||||
&self,
|
|
||||||
buffer: &Dmabuf,
|
|
||||||
) -> Result<Option<Gles2Texture>, Gles2Error> {
|
|
||||||
let existing_texture = self
|
let existing_texture = self
|
||||||
.dmabuf_cache
|
.dmabuf_cache
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -20,7 +20,11 @@ use wayland_server::protocol::{wl_buffer, wl_shm};
|
||||||
pub mod gles2;
|
pub mod gles2;
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
use crate::backend::allocator::{dmabuf::Dmabuf, Format};
|
use crate::backend::allocator::{dmabuf::Dmabuf, Format};
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
use crate::backend::egl::display::EGLBufferReader;
|
use crate::backend::egl::display::EGLBufferReader;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||||
|
@ -270,14 +274,18 @@ pub trait ImportShm: Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
/// Trait for Renderers supporting importing wl_drm-based buffers.
|
/// Trait for Renderers supporting importing wl_drm-based buffers.
|
||||||
pub trait ImportEgl: Renderer {
|
pub trait ImportEgl: Renderer {
|
||||||
/// Import a given wl_drm-based buffer into the renderer (see [`buffer_type`]).
|
/// Import a given wl_drm-based buffer into the renderer (see [`buffer_type`]).
|
||||||
///
|
///
|
||||||
/// Returns a texture_id, which can be used with [`Frame::render_texture`] (or [`Frame::render_texture_at`])
|
/// Returns a texture_id, which can be used with [`Frame::render_texture`] (or [`Frame::render_texture_at`])
|
||||||
/// or implementation-specific functions.
|
/// or implementation-specific functions.
|
||||||
///
|
///
|
||||||
/// If not otherwise defined by the implementation, this texture id is only valid for the renderer, that created it.
|
/// If not otherwise defined by the implementation, this texture id is only valid for the renderer, that created it.
|
||||||
///
|
///
|
||||||
/// This operation needs no bound or default rendering target.
|
/// This operation needs no bound or default rendering target.
|
||||||
|
@ -314,14 +322,14 @@ pub trait ImportDma: Renderer {
|
||||||
&mut self,
|
&mut self,
|
||||||
buffer: &wl_buffer::WlBuffer,
|
buffer: &wl_buffer::WlBuffer,
|
||||||
) -> Result<<Self as Renderer>::TextureId, <Self as Renderer>::Error> {
|
) -> Result<<Self as Renderer>::TextureId, <Self as Renderer>::Error> {
|
||||||
let dmabuf = buffer
|
let dmabuf = buffer
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.user_data()
|
.user_data()
|
||||||
.get::<Dmabuf>()
|
.get::<Dmabuf>()
|
||||||
.expect("import_dma_buffer without checking buffer type?");
|
.expect("import_dma_buffer without checking buffer type?");
|
||||||
self.import_dmabuf(dmabuf)
|
self.import_dmabuf(dmabuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import a given raw dmabuf into the renderer.
|
/// Import a given raw dmabuf into the renderer.
|
||||||
///
|
///
|
||||||
/// Returns a texture_id, which can be used with [`Frame::render_texture`] (or [`Frame::render_texture_at`])
|
/// Returns a texture_id, which can be used with [`Frame::render_texture`] (or [`Frame::render_texture_at`])
|
||||||
|
@ -343,7 +351,11 @@ pub trait ImportDma: Renderer {
|
||||||
// pub type ImportAll = Renderer + ImportShm + ImportEgl;
|
// pub type ImportAll = Renderer + ImportShm + ImportEgl;
|
||||||
|
|
||||||
/// Common trait for renderers of any wayland buffer type
|
/// Common trait for renderers of any wayland buffer type
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
pub trait ImportAll: Renderer + ImportShm + ImportEgl {
|
pub trait ImportAll: Renderer + ImportShm + ImportEgl {
|
||||||
/// Import a given buffer into the renderer.
|
/// Import a given buffer into the renderer.
|
||||||
///
|
///
|
||||||
|
@ -361,7 +373,7 @@ pub trait ImportAll: Renderer + ImportShm + ImportEgl {
|
||||||
///
|
///
|
||||||
/// The `damage` argument provides a list of rectangle locating parts of the buffer that need to be updated. When provided
|
/// The `damage` argument provides a list of rectangle locating parts of the buffer that need to be updated. When provided
|
||||||
/// with an empty list `&[]`, the renderer is allowed to not update the texture at all.
|
/// with an empty list `&[]`, the renderer is allowed to not update the texture at all.
|
||||||
///
|
///
|
||||||
/// Returns `None`, if the buffer type cannot be determined.
|
/// Returns `None`, if the buffer type cannot be determined.
|
||||||
fn import_buffer(
|
fn import_buffer(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -377,7 +389,11 @@ pub trait ImportAll: Renderer + ImportShm + ImportEgl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
impl<R: Renderer + ImportShm + ImportEgl> ImportAll for R {}
|
impl<R: Renderer + ImportShm + ImportEgl> ImportAll for R {}
|
||||||
|
|
||||||
#[cfg(feature = "wayland_frontend")]
|
#[cfg(feature = "wayland_frontend")]
|
||||||
|
@ -394,20 +410,19 @@ pub enum BufferType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the *type* of a wl_buffer
|
/// Returns the *type* of a wl_buffer
|
||||||
///
|
///
|
||||||
/// Returns `None` if the type is not known to smithay
|
/// Returns `None` if the type is not known to smithay
|
||||||
/// or otherwise not supported (e.g. not initialized using one of smithays [`crate::wayland`]-handlers).
|
/// or otherwise not supported (e.g. not initialized using one of smithays [`crate::wayland`]-handlers).
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
pub fn buffer_type(
|
pub fn buffer_type(
|
||||||
buffer: &wl_buffer::WlBuffer,
|
buffer: &wl_buffer::WlBuffer,
|
||||||
egl_buffer_reader: Option<&EGLBufferReader>,
|
egl_buffer_reader: Option<&EGLBufferReader>,
|
||||||
) -> Option<BufferType> {
|
) -> Option<BufferType> {
|
||||||
if buffer
|
if buffer.as_ref().user_data().get::<Dmabuf>().is_some() {
|
||||||
.as_ref()
|
|
||||||
.user_data()
|
|
||||||
.get::<Dmabuf>()
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
Some(BufferType::Dma)
|
Some(BufferType::Dma)
|
||||||
} else if egl_buffer_reader
|
} else if egl_buffer_reader
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -415,8 +430,7 @@ pub fn buffer_type(
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
Some(BufferType::Egl)
|
Some(BufferType::Egl)
|
||||||
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok()
|
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok() {
|
||||||
{
|
|
||||||
Some(BufferType::Shm)
|
Some(BufferType::Shm)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -424,19 +438,16 @@ pub fn buffer_type(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the *type* of a wl_buffer
|
/// Returns the *type* of a wl_buffer
|
||||||
///
|
///
|
||||||
/// Returns `None` if the type is not recognized by smithay or otherwise not supported.
|
/// Returns `None` if the type is not recognized by smithay or otherwise not supported.
|
||||||
#[cfg(all(feature = "wayland_frontend", not(all(feature = "backend_egl", feature = "use_system_lib"))))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
not(all(feature = "backend_egl", feature = "use_system_lib"))
|
||||||
|
))]
|
||||||
pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
|
pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
|
||||||
if buffer
|
if buffer.as_ref().user_data().get::<Dmabuf>().is_some() {
|
||||||
.as_ref()
|
|
||||||
.user_data()
|
|
||||||
.get::<Dmabuf>()
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
Some(BufferType::Dma)
|
Some(BufferType::Dma)
|
||||||
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok()
|
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok() {
|
||||||
{
|
|
||||||
Some(BufferType::Shm)
|
Some(BufferType::Shm)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -444,9 +455,13 @@ pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the dimensions of a wl_buffer
|
/// Returns the dimensions of a wl_buffer
|
||||||
///
|
///
|
||||||
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
|
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
|
||||||
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
feature = "backend_egl",
|
||||||
|
feature = "use_system_lib"
|
||||||
|
))]
|
||||||
pub fn buffer_dimensions(
|
pub fn buffer_dimensions(
|
||||||
buffer: &wl_buffer::WlBuffer,
|
buffer: &wl_buffer::WlBuffer,
|
||||||
egl_buffer_reader: Option<&EGLBufferReader>,
|
egl_buffer_reader: Option<&EGLBufferReader>,
|
||||||
|
@ -472,7 +487,10 @@ pub fn buffer_dimensions(
|
||||||
/// Returns the dimensions of a wl_buffer
|
/// Returns the dimensions of a wl_buffer
|
||||||
///
|
///
|
||||||
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
|
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
|
||||||
#[cfg(all(feature = "wayland_frontend", not(all(feature = "backend_egl", feature = "use_system_lib"))))]
|
#[cfg(all(
|
||||||
|
feature = "wayland_frontend",
|
||||||
|
not(all(feature = "backend_egl", feature = "use_system_lib"))
|
||||||
|
))]
|
||||||
pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<(i32, i32)> {
|
pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<(i32, i32)> {
|
||||||
use crate::backend::allocator::Buffer;
|
use crate::backend::allocator::Buffer;
|
||||||
|
|
||||||
|
@ -485,4 +503,4 @@ pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<(i32, i32)> {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,10 @@ use winit::{
|
||||||
window::{Window as WinitWindow, WindowBuilder},
|
window::{Window as WinitWindow, WindowBuilder},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "use_system_lib")]
|
|
||||||
use wayland_server::Display;
|
|
||||||
#[cfg(feature = "use_system_lib")]
|
#[cfg(feature = "use_system_lib")]
|
||||||
use crate::backend::egl::display::EGLBufferReader;
|
use crate::backend::egl::display::EGLBufferReader;
|
||||||
|
#[cfg(feature = "use_system_lib")]
|
||||||
|
use wayland_server::Display;
|
||||||
|
|
||||||
/// Errors thrown by the `winit` backends
|
/// Errors thrown by the `winit` backends
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
|
|
@ -63,8 +63,7 @@ use crate::backend::allocator::{
|
||||||
|
|
||||||
/// Handler trait for dmabuf validation
|
/// Handler trait for dmabuf validation
|
||||||
///
|
///
|
||||||
/// You need to provide an implementation of this trait
|
/// You need to provide an implementation of this trait
|
||||||
|
|
||||||
|
|
||||||
/// Initialize a dmabuf global.
|
/// Initialize a dmabuf global.
|
||||||
///
|
///
|
||||||
|
@ -136,7 +135,9 @@ where
|
||||||
height,
|
height,
|
||||||
format,
|
format,
|
||||||
flags,
|
flags,
|
||||||
} => handler.create_immed(&*params, buffer_id, width, height, format, flags, ddata),
|
} => {
|
||||||
|
handler.create_immed(&*params, buffer_id, width, height, format, flags, ddata)
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -169,7 +170,7 @@ struct ParamsHandler<H: for<'a> FnMut(&Dmabuf, DispatchData<'a>) -> bool + 'stat
|
||||||
|
|
||||||
impl<H> ParamsHandler<H>
|
impl<H> ParamsHandler<H>
|
||||||
where
|
where
|
||||||
H: for<'a> FnMut(&Dmabuf, DispatchData<'a>) -> bool + 'static
|
H: for<'a> FnMut(&Dmabuf, DispatchData<'a>) -> bool + 'static,
|
||||||
{
|
{
|
||||||
fn add(
|
fn add(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -216,7 +217,15 @@ where
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create<'a>(&mut self, params: &BufferParams, width: i32, height: i32, format: u32, flags: u32, ddata: DispatchData<'a>) {
|
fn create<'a>(
|
||||||
|
&mut self,
|
||||||
|
params: &BufferParams,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
format: u32,
|
||||||
|
flags: u32,
|
||||||
|
ddata: DispatchData<'a>,
|
||||||
|
) {
|
||||||
// Cannot reuse a params:
|
// Cannot reuse a params:
|
||||||
if self.used {
|
if self.used {
|
||||||
params.as_ref().post_error(
|
params.as_ref().post_error(
|
||||||
|
@ -273,7 +282,7 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut handler = self.handler.borrow_mut();
|
let mut handler = self.handler.borrow_mut();
|
||||||
if handler(&dmabuf, ddata) {
|
if handler(&dmabuf, ddata) {
|
||||||
if let Some(buffer) = params
|
if let Some(buffer) = params
|
||||||
|
@ -285,7 +294,7 @@ where
|
||||||
buffer.quick_assign(|_, _, _| {});
|
buffer.quick_assign(|_, _, _| {});
|
||||||
|
|
||||||
trace!(self.log, "Created a new validated dma wl_buffer.");
|
trace!(self.log, "Created a new validated dma wl_buffer.");
|
||||||
params.created(&buffer);
|
params.created(&buffer);
|
||||||
} else {
|
} else {
|
||||||
trace!(self.log, "Failed to create a wl_buffer");
|
trace!(self.log, "Failed to create a wl_buffer");
|
||||||
params.failed();
|
params.failed();
|
||||||
|
@ -362,7 +371,7 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut handler = self.handler.borrow_mut();
|
let mut handler = self.handler.borrow_mut();
|
||||||
if handler(&dmabuf, ddata) {
|
if handler(&dmabuf, ddata) {
|
||||||
buffer.as_ref().user_data().set_threadsafe(|| dmabuf);
|
buffer.as_ref().user_data().set_threadsafe(|| dmabuf);
|
||||||
|
@ -378,8 +387,6 @@ where
|
||||||
"create_immed resulted in an invalid buffer.".into(),
|
"create_immed resulted in an invalid buffer.".into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue