Refactor encoder info

This commit is contained in:
Florian RICHER 2024-10-04 00:13:27 +02:00
parent f479143eba
commit 0860a4cd7b

View file

@ -20,19 +20,7 @@ fn main() {
Ok(connector) => {
println!("\t{} ({:?})", connector.interface().as_str(), connector.state());
let current_encoder = connector
.current_encoder()
.and_then(|encoder_handle| gpu.get_encoder(encoder_handle).ok());
let encoder_info = match current_encoder {
Some(encoder) => {
let crtc_info = format_crtc(&gpu, encoder.crtc());
format!("{:?}, {}", encoder.kind(), crtc_info)
}
None => format!("No encoder found")
};
let encoder_info = format_encoder(&gpu, connector.current_encoder());
println!("\t\tEncoder: {}", encoder_info);
@ -43,6 +31,17 @@ fn main() {
}
}
fn format_encoder(gpu: &card::Card, encoder_handle: Option<drm::control::encoder::Handle>) -> String {
match encoder_handle.and_then(|handle| gpu.get_encoder(handle).ok()) {
Some(encoder) => {
let crtc_info = format_crtc(&gpu, encoder.crtc());
format!("{:?}, {}", encoder.kind(), crtc_info)
}
None => format!("No encoder found")
}
}
fn format_crtc(gpu: &card::Card, crtc_handle: Option<drm::control::crtc::Handle>) -> String {
match crtc_handle.and_then(|handle| Some(gpu.get_crtc(handle))) {
Some(crtc) => format!("{:?}", crtc),