drivers/graphics/driver-graphics: Couple of fixups

This commit is contained in:
bjorn3
2026-05-14 16:00:30 +02:00
parent 0ee128ad8d
commit 5d6faacfb3
5 changed files with 61 additions and 65 deletions
@@ -22,8 +22,8 @@ pub struct KmsObjects<T: GraphicsAdapter> {
pub(super) connectors: Vec<KmsObjectId>,
pub(super) encoders: Vec<KmsObjectId>,
crtcs: Vec<KmsObjectId>,
framebuffers: Vec<KmsObjectId>,
planes: Vec<KmsObjectId>,
framebuffers: Vec<KmsObjectId>,
pub(super) objects: HashMap<KmsObjectId, KmsObject<T>>,
_marker: PhantomData<T>,
}
@@ -35,8 +35,8 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
connectors: vec![],
encoders: vec![],
crtcs: vec![],
framebuffers: vec![],
planes: vec![],
framebuffers: vec![],
objects: HashMap::new(),
_marker: PhantomData,
};
@@ -125,24 +125,6 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
self.get(id)
}
pub fn add_framebuffer(&mut self, fb: KmsFramebuffer<T>) -> KmsObjectId {
let id = self.add(fb);
self.framebuffers.push(id);
id
}
pub fn remove_framebuffer(&mut self, id: KmsObjectId) -> Result<()> {
self.remove::<KmsFramebuffer<T>>(id)
}
pub fn fb_ids(&self) -> &[KmsObjectId] {
&self.framebuffers
}
pub fn get_framebuffer(&self, id: KmsObjectId) -> Result<&KmsFramebuffer<T>> {
self.get(id)
}
pub fn add_plane(
&mut self,
crtcs: &[KmsObjectId],
@@ -196,6 +178,24 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
pub fn get_plane(&self, id: KmsObjectId) -> Result<&Mutex<KmsPlane<T>>> {
self.get(id)
}
pub fn add_framebuffer(&mut self, fb: KmsFramebuffer<T>) -> KmsObjectId {
let id = self.add(fb);
self.framebuffers.push(id);
id
}
pub fn remove_framebuffer(&mut self, id: KmsObjectId) -> Result<()> {
self.remove::<KmsFramebuffer<T>>(id)
}
pub fn fb_ids(&self) -> &[KmsObjectId] {
&self.framebuffers
}
pub fn get_framebuffer(&self, id: KmsObjectId) -> Result<&KmsFramebuffer<T>> {
self.get(id)
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
@@ -299,16 +299,6 @@ define_object_props!(object, KmsCrtc<T: GraphicsAdapter> {
}
});
#[derive(Debug)]
pub struct KmsFramebuffer<T: GraphicsAdapter> {
pub width: u32,
pub height: u32,
pub pixel_format: DrmFourcc,
pub pitch: u32,
pub buffer: Arc<T::Buffer>,
pub driver_data: T::Framebuffer,
}
pub trait KmsPlaneDriver: Debug {
type State: Clone + Debug;
}
@@ -361,3 +351,13 @@ pub struct KmsRect<T> {
pub width: u32,
pub height: u32,
}
#[derive(Debug)]
pub struct KmsFramebuffer<T: GraphicsAdapter> {
pub width: u32,
pub height: u32,
pub pixel_format: DrmFourcc,
pub pitch: u32,
pub buffer: Arc<T::Buffer>,
pub driver_data: T::Framebuffer,
}
+28 -30
View File
@@ -85,7 +85,6 @@ impl Damage {
pub trait GraphicsAdapter: Sized + Debug {
type Connector: KmsConnectorDriver;
type Crtc: KmsCrtcDriver;
type Plane: KmsPlaneDriver;
type Buffer: Buffer;
@@ -972,46 +971,43 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
}),
ipc::MODE_SET_PLANE => ipc::DrmModeSetPlane::with(payload, |data| {
let plane_id = KmsObjectId(data.plane_id());
let plane_mutex = self.objects.get_plane(plane_id)?;
let plane = self.objects.get_plane(plane_id)?;
let crtc_id = KmsObjectId(data.crtc_id());
let crtc_index = self.objects.get_crtc(crtc_id)?.lock().unwrap().crtc_index;
let new_state;
{
let mut plane = plane_mutex.lock().unwrap();
let mut new_state = {
let plane = plane.lock().unwrap();
if plane.possible_crtcs & (1 << crtc_index) == 0 {
return Err(Error::new(EINVAL));
}
let fb_id = if data.fb_id() != 0 {
KmsObjectId(data.fb_id())
} else {
KmsObjectId::INVALID
};
let mut state = plane.state.clone();
state.fb_id = Some(fb_id);
state.crtc_id = Some(crtc_id);
state.src_rect = KmsRect {
x: data.src_x(),
y: data.src_y(),
width: data.src_w(),
height: data.src_h(),
};
state.crtc_rect = KmsRect {
x: data.crtc_x() as i32,
y: data.crtc_y() as i32,
width: data.crtc_w(),
height: data.crtc_h(),
};
plane.state = state.clone();
new_state = state;
}
plane.state.clone()
};
let fb_id = if data.fb_id() != 0 {
KmsObjectId(data.fb_id())
} else {
KmsObjectId::INVALID
};
new_state.fb_id = Some(fb_id);
new_state.crtc_id = Some(crtc_id);
new_state.src_rect = KmsRect {
x: data.src_x(),
y: data.src_y(),
width: data.src_w(),
height: data.src_h(),
};
new_state.crtc_rect = KmsRect {
x: data.crtc_x() as i32,
y: data.crtc_y() as i32,
width: data.crtc_w(),
height: data.crtc_h(),
};
if *vt == self.active_vt {
self.adapter.set_plane(
&self.objects,
plane_mutex,
new_state,
plane,
new_state.clone(),
Damage {
x: 0,
y: 0,
@@ -1020,6 +1016,8 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
},
)?;
}
self.vts.get_mut(vt).unwrap().plane_state
[plane.lock().unwrap().plane_index as usize] = new_state;
Ok(0)
}),
ipc::MODE_GET_PLANE => ipc::DrmModeGetPlane::with(payload, |mut data| {
+1 -2
View File
@@ -41,12 +41,11 @@ impl Buffer for GpuBuffer {
impl GraphicsAdapter for Device {
type Connector = Connector;
type Crtc = Crtc;
type Plane = ();
type Buffer = GpuBuffer;
type Framebuffer = ();
type Plane = ();
fn name(&self) -> &'static [u8] {
b"ihdgd"
}
+1 -1
View File
@@ -33,11 +33,11 @@ impl KmsConnectorDriver for Connector {
impl GraphicsAdapter for FbAdapter {
type Connector = Connector;
type Crtc = ();
type Plane = ();
type Buffer = GraphicScreen;
type Framebuffer = ();
type Plane = ();
fn name(&self) -> &'static [u8] {
b"vesad"
+1 -2
View File
@@ -343,12 +343,11 @@ impl<'a> VirtGpuAdapter<'a> {
impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
type Connector = VirtGpuConnector;
type Crtc = ();
type Plane = ();
type Buffer = VirtGpuFramebuffer<'a>;
type Framebuffer = ();
type Plane = ();
fn name(&self) -> &'static [u8] {
b"virtio-gpud"
}