forge
Explore
Log in

Don't you dare go Hollow

tty: Cache GAMMA_LUT_SIZE value

Browse files at this commit

008992f4c9527b4dc451891425c48005726e88cfIvan MolodetskikhParent: 51f5533
Should be immutable, no need to query every time.
src/backend/tty.rsmodified+7 -29
@@ -398,7 +398,7 @@ pub struct SurfaceDmabufFeedback {
398 struct GammaProps {398 struct GammaProps {
399 crtc: crtc::Handle,399 crtc: crtc::Handle,
400 gamma_lut: property::Handle,400 gamma_lut: property::Handle,
401- gamma_lut_size: property::Handle,401+ gamma_lut_size: u32,
402 previous_blob: Option<NonZeroU64>,402 previous_blob: Option<NonZeroU64>,
403 }403 }
404 404
@@ -2093,7 +2093,7 @@ impl Tty {
2093 2093
2094 let surface = device.surfaces.get(&crtc).context("missing surface")?;2094 let surface = device.surfaces.get(&crtc).context("missing surface")?;
2095 if let Some(gamma_props) = &surface.gamma_props {2095 if let Some(gamma_props) = &surface.gamma_props {
2096- gamma_props.gamma_size(&device.drm)2096+ Ok(gamma_props.gamma_size())
2097 } else {2097 } else {
2098 let info = device2098 let info = device
2099 .drm2099 .drm
@@ -2630,7 +2630,7 @@ impl GammaProps {
2630 let props = device2630 let props = device
2631 .get_properties(crtc)2631 .get_properties(crtc)
2632 .context("error getting properties")?;2632 .context("error getting properties")?;
2633- for (prop, _) in props {2633+ for (prop, value) in props {
2634 let Ok(info) = device.get_property(prop) else {2634 let Ok(info) = device.get_property(prop) else {
2635 continue;2635 continue;
2636 };2636 };
@@ -2652,7 +2652,7 @@ impl GammaProps {
2652 matches!(info.value_type(), property::ValueType::UnsignedRange(_, _)),2652 matches!(info.value_type(), property::ValueType::UnsignedRange(_, _)),
2653 "wrong GAMMA_LUT_SIZE value type"2653 "wrong GAMMA_LUT_SIZE value type"
2654 );2654 );
2655- gamma_lut_size = Some(prop);2655+ gamma_lut_size = Some(value as u32);
2656 }2656 }
2657 _ => (),2657 _ => (),
2658 }2658 }
@@ -2669,19 +2669,15 @@ impl GammaProps {
2669 })2669 })
2670 }2670 }
2671 2671
2672- fn gamma_size(&self, device: &DrmDevice) -> anyhow::Result<u32> {2672+ fn gamma_size(&self) -> u32 {
2673- let value = get_drm_property(device, self.crtc, self.gamma_lut_size)2673+ self.gamma_lut_size
2674- .context("missing GAMMA_LUT_SIZE property")?;
2675- Ok(value as u32)
2676 }2674 }
2677 2675
2678 fn set_gamma(&mut self, device: &DrmDevice, gamma: Option<&[u16]>) -> anyhow::Result<()> {2676 fn set_gamma(&mut self, device: &DrmDevice, gamma: Option<&[u16]>) -> anyhow::Result<()> {
2679 let _span = tracy_client::span!("GammaProps::set_gamma");2677 let _span = tracy_client::span!("GammaProps::set_gamma");
2680 2678
2681 let blob = if let Some(gamma) = gamma {2679 let blob = if let Some(gamma) = gamma {
2682- let gamma_size = self2680+ let gamma_size = self.gamma_size() as usize;
2683- .gamma_size(device)
2684- .context("error getting gamma size")? as usize;
2685 2681
2686 ensure!(gamma.len() == gamma_size * 3, "wrong gamma length");2682 ensure!(gamma.len() == gamma_size * 3, "wrong gamma length");
2687 2683
@@ -2912,24 +2908,6 @@ fn find_drm_property(
2912 })2908 })
2913 }2909 }
2914 2910
2915-fn get_drm_property(
2916- drm: &DrmDevice,
2917- resource: impl ResourceHandle,
2918- prop: property::Handle,
2919-) -> Option<property::RawValue> {
2920- let props = match drm.get_properties(resource) {
2921- Ok(props) => props,
2922- Err(err) => {
2923- warn!("error getting properties: {err:?}");
2924- return None;
2925- }
2926- };
2927-
2928- props
2929- .into_iter()
2930- .find_map(|(handle, value)| (handle == prop).then_some(value))
2931-}
2932-
2933 fn refresh_interval(mode: DrmMode) -> Duration {2911 fn refresh_interval(mode: DrmMode) -> Duration {
2934 let clock = mode.clock() as u64;2912 let clock = mode.clock() as u64;
2935 let htotal = mode.hsync().2 as u64;2913 let htotal = mode.hsync().2 as u64;