drivers/graphics/driver-graphics: Introduce set_connector_edid helper
And don't create a new blob unless the EDID actually changes.
This commit is contained in:
@@ -68,6 +68,23 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
|
||||
self.get(id)
|
||||
}
|
||||
|
||||
pub fn set_connector_edid(&mut self, id: KmsObjectId, edid: Vec<u8>) {
|
||||
let mut connector = self.get_connector(id).unwrap().lock().unwrap();
|
||||
connector.update_from_edid(&edid);
|
||||
let old_edid = connector.edid;
|
||||
drop(connector);
|
||||
|
||||
if old_edid != KmsObjectId::INVALID {
|
||||
if self.get_blob(old_edid).unwrap() == edid {
|
||||
return; // EDID is unchanged; nothing to do
|
||||
}
|
||||
self.remove_blob(old_edid).unwrap();
|
||||
}
|
||||
|
||||
let blob = self.add_blob(edid);
|
||||
self.get_connector(id).unwrap().lock().unwrap().edid = blob;
|
||||
}
|
||||
|
||||
pub fn encoder_ids(&self) -> &[KmsObjectId] {
|
||||
&self.encoders
|
||||
}
|
||||
@@ -142,7 +159,7 @@ impl<T: GraphicsAdapter> KmsConnector<T> {
|
||||
self.modes = vec![modeinfo_for_size(width, height)];
|
||||
}
|
||||
|
||||
pub fn update_from_edid(&mut self, edid: &[u8]) {
|
||||
fn update_from_edid(&mut self, edid: &[u8]) {
|
||||
let edid = edid::parse(edid).unwrap().1;
|
||||
|
||||
if let Some(first_detailed_timing) =
|
||||
|
||||
@@ -80,6 +80,18 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
|
||||
self.add(KmsBlob { data })
|
||||
}
|
||||
|
||||
pub fn remove_blob(&mut self, id: KmsObjectId) -> Result<()> {
|
||||
let Some(object) = self.objects.get(&id) else {
|
||||
return Err(Error::new(ENOENT));
|
||||
};
|
||||
let KmsObject::Blob(_) = object else {
|
||||
return Err(Error::new(ENOENT));
|
||||
};
|
||||
self.objects.remove(&id).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_blob(&self, id: KmsObjectId) -> Result<&[u8]> {
|
||||
Ok(&self.get::<KmsBlob>(id)?.data)
|
||||
}
|
||||
|
||||
@@ -395,12 +395,8 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
|
||||
};
|
||||
|
||||
if self.has_edid {
|
||||
connector.update_from_edid(&display.edid);
|
||||
|
||||
drop(connector);
|
||||
|
||||
let blob = objects.add_blob(display.edid.clone());
|
||||
objects.get_connector(id).unwrap().lock().unwrap().edid = blob;
|
||||
objects.set_connector_edid(id, display.edid.clone());
|
||||
} else {
|
||||
connector.update_from_size(display.width, display.height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user