deps: Switch from edid-rs to libdisplay-info

This commit is contained in:
Victoria Brekenfeld 2025-01-02 20:19:04 +01:00 committed by Victoria Brekenfeld
parent 546966bf15
commit adcb81bbe0
4 changed files with 153 additions and 166 deletions

View file

@ -677,7 +677,9 @@ fn create_output_for_conn(drm: &mut DrmDevice, conn: connector::Handle) -> Resul
.get_connector(conn, false)
.with_context(|| "Failed to query connector info")?;
let interface = drm_helpers::interface_name(drm, conn)?;
let edid_info = drm_helpers::edid_info(drm, conn);
let edid_info = drm_helpers::edid_info(drm, conn)
.inspect_err(|err| warn!(?err, "failed to get EDID for {}", interface))
.ok();
let (phys_w, phys_h) = conn_info.size().unwrap_or((0, 0));
Ok(Output::new(
@ -694,12 +696,12 @@ fn create_output_for_conn(drm: &mut DrmDevice, conn: connector::Handle) -> Resul
},
make: edid_info
.as_ref()
.map(|info| info.manufacturer.clone())
.unwrap_or_else(|_| String::from("Unknown")),
.and_then(|info| info.make())
.unwrap_or_else(|| String::from("Unknown")),
model: edid_info
.as_ref()
.map(|info| info.model.clone())
.unwrap_or_else(|_| String::from("Unknown")),
.and_then(|info| info.model())
.unwrap_or_else(|| String::from("Unknown")),
},
))
}

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use libdisplay_info::{edid::DisplayDescriptorTag, info::Info};
use smithay::{
reexports::drm::control::{
atomic::AtomicModeReq,
@ -12,11 +13,7 @@ use smithay::{
},
utils::Transform,
};
use std::{
collections::HashMap,
ops::Range,
panic::{catch_unwind, AssertUnwindSafe},
};
use std::{collections::HashMap, ops::Range};
pub fn display_configuration(
device: &mut impl ControlDevice,
@ -169,59 +166,24 @@ pub fn interface_name(device: &impl ControlDevice, connector: connector::Handle)
))
}
pub struct EdidInfo {
pub model: String,
pub manufacturer: String,
}
pub fn edid_info(device: &impl ControlDevice, connector: connector::Handle) -> Result<EdidInfo> {
use edid_rs::{parse as edid_parse, MonitorDescriptor};
pub fn edid_info(device: &impl ControlDevice, connector: connector::Handle) -> Result<Info> {
let edid_prop = get_prop(device, connector, "EDID")?;
let edid_info = device.get_property(edid_prop)?;
let mut manufacturer = "Unknown".into();
let mut model = "Unknown".into();
let mut edid = None;
let props = device.get_properties(connector)?;
let (ids, vals) = props.as_props_and_values();
for (&id, &val) in ids.iter().zip(vals.iter()) {
if id == edid_prop {
if let property::Value::Blob(edid_blob) = edid_info.value_type().convert_value(val) {
let blob = device.get_property_blob(edid_blob)?;
let mut reader = std::io::Cursor::new(blob);
if let Some(edid) =
catch_unwind(AssertUnwindSafe(move || edid_parse(&mut reader).ok()))
.ok()
.flatten()
{
manufacturer = {
let id = edid.product.manufacturer_id;
let code = [id.0, id.1, id.2];
get_manufacturer(&code).into()
};
model = if let Some(MonitorDescriptor::MonitorName(name)) = edid
.descriptors
.0
.iter()
.find(|x| matches!(x, MonitorDescriptor::MonitorName(_)))
{
let mut name = name.clone();
if let Some(idx) = name.find('\0') {
name.truncate(idx);
}
name
} else {
format!("{}", edid.product.product_code)
};
}
edid = Some(Info::parse_edid(&blob).context("Unable to parse edid")?);
}
break;
}
}
Ok(EdidInfo {
model,
manufacturer,
})
edid.ok_or(anyhow!("No EDID found"))
}
pub fn get_prop(
@ -257,78 +219,6 @@ pub fn get_property_val(
anyhow::bail!("No prop found for {}", name)
}
fn get_manufacturer(vendor: &[char; 3]) -> &'static str {
match vendor {
['A', 'A', 'A'] => "Avolites Ltd",
['A', 'C', 'I'] => "Ancor Communications Inc",
['A', 'C', 'R'] => "Acer Technologies",
['A', 'D', 'A'] => "Addi-Data GmbH",
['A', 'P', 'P'] => "Apple Computer Inc",
['A', 'S', 'K'] => "Ask A/S",
['A', 'V', 'T'] => "Avtek (Electronics) Pty Ltd",
['B', 'N', 'O'] => "Bang & Olufsen",
['B', 'N', 'Q'] => "BenQ Corporation",
['C', 'M', 'N'] => "Chimei Innolux Corporation",
['C', 'M', 'O'] => "Chi Mei Optoelectronics corp.",
['C', 'R', 'O'] => "Extraordinary Technologies PTY Limited",
['D', 'E', 'L'] => "Dell Inc.",
['D', 'G', 'C'] => "Data General Corporation",
['D', 'O', 'N'] => "DENON, Ltd.",
['E', 'N', 'C'] => "Eizo Nanao Corporation",
['E', 'P', 'H'] => "Epiphan Systems Inc.",
['E', 'X', 'P'] => "Data Export Corporation",
['F', 'N', 'I'] => "Funai Electric Co., Ltd.",
['F', 'U', 'S'] => "Fujitsu Siemens Computers GmbH",
['G', 'S', 'M'] => "Goldstar Company Ltd",
['H', 'I', 'Q'] => "Kaohsiung Opto Electronics Americas, Inc.",
['H', 'S', 'D'] => "HannStar Display Corp",
['H', 'T', 'C'] => "Hitachi Ltd",
['H', 'W', 'P'] => "Hewlett Packard",
['I', 'N', 'T'] => "Interphase Corporation",
['I', 'N', 'X'] => "Communications Supply Corporation (A division of WESCO)",
['I', 'T', 'E'] => "Integrated Tech Express Inc",
['I', 'V', 'M'] => "Iiyama North America",
['L', 'E', 'N'] => "Lenovo Group Limited",
['M', 'A', 'X'] => "Rogen Tech Distribution Inc",
['M', 'E', 'G'] => "Abeam Tech Ltd",
['M', 'E', 'I'] => "Panasonic Industry Company",
['M', 'T', 'C'] => "Mars-Tech Corporation",
['M', 'T', 'X'] => "Matrox",
['N', 'E', 'C'] => "NEC Corporation",
['N', 'E', 'X'] => "Nexgen Mediatech Inc.",
['O', 'N', 'K'] => "ONKYO Corporation",
['O', 'R', 'N'] => "ORION ELECTRIC CO., LTD.",
['O', 'T', 'M'] => "Optoma Corporation",
['O', 'V', 'R'] => "Oculus VR, Inc.",
['P', 'H', 'L'] => "Philips Consumer Electronics Company",
['P', 'I', 'O'] => "Pioneer Electronic Corporation",
['P', 'N', 'R'] => "Planar Systems, Inc.",
['Q', 'D', 'S'] => "Quanta Display Inc.",
['R', 'A', 'T'] => "Rent-A-Tech",
['R', 'E', 'N'] => "Renesas Technology Corp.",
['S', 'A', 'M'] => "Samsung Electric Company",
['S', 'A', 'N'] => "Sanyo Electric Co., Ltd.",
['S', 'E', 'C'] => "Seiko Epson Corporation",
['S', 'H', 'P'] => "Sharp Corporation",
['S', 'I', 'I'] => "Silicon Image, Inc.",
['S', 'N', 'Y'] => "Sony",
['S', 'T', 'D'] => "STD Computer Inc",
['S', 'V', 'S'] => "SVSI",
['S', 'Y', 'N'] => "Synaptics Inc",
['T', 'C', 'L'] => "Technical Concepts Ltd",
['T', 'O', 'P'] => "Orion Communications Co., Ltd.",
['T', 'S', 'B'] => "Toshiba America Info Systems Inc",
['T', 'S', 'T'] => "Transtream Inc",
['U', 'N', 'K'] => "Unknown",
['V', 'E', 'S'] => "Vestel Elektronik Sanayi ve Ticaret A. S.",
['V', 'I', 'T'] => "Visitech AS",
['V', 'I', 'Z'] => "VIZIO, Inc",
['V', 'S', 'C'] => "ViewSonic Corporation",
['Y', 'M', 'H'] => "Yamaha Corporation",
_ => "Unknown",
}
}
// Returns refresh rate in milliherz
pub fn calculate_refresh_rate(mode: Mode) -> u32 {
let htotal = mode.hsync().2 as u32;