anvil: dmabuf support
This commit is contained in:
parent
a38592bc92
commit
5b70ca4206
|
@ -5,7 +5,7 @@ use std::cell::RefCell;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
renderer::{Frame, Renderer, Texture, Transform, ImportShm, BufferType, buffer_type},
|
renderer::{Frame, Renderer, Texture, Transform, ImportShm, ImportDma, BufferType, buffer_type},
|
||||||
SwapBuffersError,
|
SwapBuffersError,
|
||||||
},
|
},
|
||||||
reexports::wayland_server::protocol::{wl_buffer, wl_surface},
|
reexports::wayland_server::protocol::{wl_buffer, wl_surface},
|
||||||
|
@ -19,7 +19,7 @@ use smithay::{
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
use smithay::backend::{
|
use smithay::backend::{
|
||||||
egl::display::EGLBufferReader,
|
egl::display::EGLBufferReader,
|
||||||
renderer::ImportEgl
|
renderer::ImportEgl,
|
||||||
};
|
};
|
||||||
// hacky...
|
// hacky...
|
||||||
#[cfg(not(feature = "egl"))]
|
#[cfg(not(feature = "egl"))]
|
||||||
|
@ -53,7 +53,7 @@ pub fn draw_cursor<R, E, F, T>(
|
||||||
log: &Logger,
|
log: &Logger,
|
||||||
) -> Result<(), SwapBuffersError>
|
) -> Result<(), SwapBuffersError>
|
||||||
where
|
where
|
||||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl,
|
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl + ImportDma,
|
||||||
F: Frame<Error = E, TextureId = T>,
|
F: Frame<Error = E, TextureId = T>,
|
||||||
E: std::error::Error + Into<SwapBuffersError>,
|
E: std::error::Error + Into<SwapBuffersError>,
|
||||||
T: Texture + 'static,
|
T: Texture + 'static,
|
||||||
|
@ -91,7 +91,7 @@ fn draw_surface_tree<R, E, F, T>(
|
||||||
log: &Logger,
|
log: &Logger,
|
||||||
) -> Result<(), SwapBuffersError>
|
) -> Result<(), SwapBuffersError>
|
||||||
where
|
where
|
||||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl,
|
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl + ImportDma,
|
||||||
F: Frame<Error = E, TextureId = T>,
|
F: Frame<Error = E, TextureId = T>,
|
||||||
E: std::error::Error + Into<SwapBuffersError>,
|
E: std::error::Error + Into<SwapBuffersError>,
|
||||||
T: Texture + 'static,
|
T: Texture + 'static,
|
||||||
|
@ -130,6 +130,7 @@ where
|
||||||
},
|
},
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
Some(BufferType::Egl) => Some(renderer.import_egl_buffer(&buffer, egl_buffer_reader.unwrap())),
|
Some(BufferType::Egl) => Some(renderer.import_egl_buffer(&buffer, egl_buffer_reader.unwrap())),
|
||||||
|
Some(BufferType::Dma) => Some(renderer.import_dma_buffer(&buffer)),
|
||||||
_ => {
|
_ => {
|
||||||
error!(log, "Unknown buffer format for: {:?}", buffer);
|
error!(log, "Unknown buffer format for: {:?}", buffer);
|
||||||
None
|
None
|
||||||
|
@ -209,7 +210,7 @@ pub fn draw_windows<R, E, F, T>(
|
||||||
log: &::slog::Logger,
|
log: &::slog::Logger,
|
||||||
) -> Result<(), SwapBuffersError>
|
) -> Result<(), SwapBuffersError>
|
||||||
where
|
where
|
||||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl,
|
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl + ImportDma,
|
||||||
F: Frame<Error = E, TextureId = T>,
|
F: Frame<Error = E, TextureId = T>,
|
||||||
E: std::error::Error + Into<SwapBuffersError>,
|
E: std::error::Error + Into<SwapBuffersError>,
|
||||||
T: Texture + 'static,
|
T: Texture + 'static,
|
||||||
|
@ -256,7 +257,7 @@ pub fn draw_dnd_icon<R, E, F, T>(
|
||||||
log: &::slog::Logger,
|
log: &::slog::Logger,
|
||||||
) -> Result<(), SwapBuffersError>
|
) -> Result<(), SwapBuffersError>
|
||||||
where
|
where
|
||||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl,
|
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportShm + ImportEgl + ImportDma,
|
||||||
F: Frame<Error = E, TextureId = T>,
|
F: Frame<Error = E, TextureId = T>,
|
||||||
E: std::error::Error + Into<SwapBuffersError>,
|
E: std::error::Error + Into<SwapBuffersError>,
|
||||||
T: Texture + 'static,
|
T: Texture + 'static,
|
||||||
|
|
|
@ -12,8 +12,6 @@ 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, udev::primary_gpu};
|
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
drm::{DrmDevice, DrmError, DrmEvent, DrmRenderSurface},
|
drm::{DrmDevice, DrmError, DrmEvent, DrmRenderSurface},
|
||||||
|
@ -21,7 +19,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},
|
||||||
|
@ -57,6 +55,11 @@ 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};
|
||||||
|
@ -179,6 +182,33 @@ pub fn run_udev(
|
||||||
state.device_added(dev, path.into())
|
state.device_added(dev, path.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init dmabuf support with format list from all gpus
|
||||||
|
// TODO: We need to update this list, when the set of gpus changes
|
||||||
|
// TODO2: This does not necessarily depend on egl, but mesa makes no use of it without wl_drm right now
|
||||||
|
#[cfg(feature = "egl")]
|
||||||
|
{
|
||||||
|
let mut formats = Vec::new();
|
||||||
|
for backend_data in state.backend_data.backends.values() {
|
||||||
|
let surfaces = backend_data.surfaces.borrow_mut();
|
||||||
|
if let Some(surface) = surfaces.values().next() {
|
||||||
|
formats.extend(surface.borrow_mut().renderer().dmabuf_formats().cloned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init_dmabuf_global(&mut *display.borrow_mut(), formats, |buffer, mut ddata| {
|
||||||
|
let anvil_state = ddata.get::<AnvilState<UdevData>>().unwrap();
|
||||||
|
for backend_data in anvil_state.backend_data.backends.values() {
|
||||||
|
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
|
||||||
|
}, log.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let udev_event_source = event_loop
|
let udev_event_source = event_loop
|
||||||
.handle()
|
.handle()
|
||||||
.insert_source(udev_backend, move |event, _, state| match event {
|
.insert_source(udev_backend, move |event, _, state| match event {
|
||||||
|
|
|
@ -11,6 +11,11 @@ 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;
|
||||||
|
|
||||||
|
@ -40,6 +45,11 @@ 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 renderer = renderer.clone();
|
||||||
|
init_dmabuf_global(&mut *display.borrow_mut(), 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();
|
||||||
|
|
Loading…
Reference in New Issue