forge
Explore
Log in

Don't you dare go Hollow

tty: Make sure to cleanup all CRTCs except used ones

Browse files at this commit

1ae489813ea36adb1dbf5c8b7d113ab8f3daeaffIvan MolodetskikhParent: c722634
Apparently a CRTC can be active and use bandwidth even without any
connectors on it.
src/backend/tty.rsmodified+16 -45
@@ -228,47 +228,31 @@ impl OutputDevice {
228228 ) -> anyhow::Result<()> {
229229 let _span = tracy_client::span!("OutputDevice::cleanup_disconnected_resources");
230230
231- let mut req = AtomicModeReq::new();
231+ let res_handles = self
232+ .drm
233+ .resource_handles()
234+ .context("error getting plane handles")?;
232235 let plane_handles = self
233236 .drm
234237 .plane_handles()
235238 .context("error getting plane handles")?;
236239
237- let mut cleanup = HashSet::new();
238- let mut should_be_off_conn = HashSet::new();
239-
240- for (conn, info) in self.drm_scanner.connectors() {
241- let Some(enc) = info.current_encoder() else {
242- // Not enabled.
243- continue;
244- };
245-
246- let enc = match self.drm.get_encoder(enc) {
247- Ok(x) => x,
248- Err(err) => {
249- debug!("couldn't get encoder: {err:?}");
250- continue;
251- }
252- };
240+ let mut req = AtomicModeReq::new();
253241
254- let Some(crtc) = enc.crtc() else {
255- // Encoder has no CRTC?
256- continue;
257- };
242+ // We want to disable all CRTCs that do not correspond to a connector we're using.
243+ let mut cleanup = HashSet::<crtc::Handle>::new();
244+ cleanup.extend(res_handles.crtcs());
258245
259- // All Connected connectors are returned by the DrmScanner and will be attempted for
260- // connection.
261- if info.state() == connector::State::Connected {
262- // But we also need to clear the connectors that should be off according to our
263- // config, since those ones will not be cleared elsewhere.
246+ for (conn, info) in self.drm_scanner.connectors() {
247+ // We only keep the connector if it has a CRTC and the output isn't off in niri.
248+ if let Some(crtc) = self.drm_scanner.crtc_for_connector(conn) {
264249 if !should_be_off(crtc, info) {
250+ // Keep the corresponding CRTC.
251+ cleanup.remove(&crtc);
265252 continue;
266253 }
267- should_be_off_conn.insert(conn);
268254 }
269255
270- cleanup.insert(crtc);
271-
272256 // Clear the connector.
273257 let Some((crtc_id, _, _)) = find_drm_property(&self.drm, *conn, "CRTC_ID") else {
274258 debug!("couldn't find connector CRTC_ID property");
@@ -278,24 +262,11 @@ impl OutputDevice {
278262 req.add_property(*conn, crtc_id, property::Value::CRTC(None));
279263 }
280264
281- // Don't cleanup CRTCs that also correspond to some connected connectors.
282- for (conn, crtc) in self.drm_scanner.crtcs() {
283- // If the connector is enabled, but we're about to disable it, then it will be present
284- // in the DrmScanner; keep it in the cleanup list.
285- if should_be_off_conn.contains(&conn.handle()) {
286- continue;
287- }
288-
289- cleanup.remove(&crtc);
290- }
291-
292265 // Legacy fallback.
293266 if !self.drm.is_atomic() {
294- if let Ok(res_handles) = self.drm.resource_handles() {
295- for crtc in res_handles.crtcs() {
296- #[allow(deprecated)]
297- let _ = self.drm.set_cursor(*crtc, Option::<&DumbBuffer>::None);
298- }
267+ for crtc in res_handles.crtcs() {
268+ #[allow(deprecated)]
269+ let _ = self.drm.set_cursor(*crtc, Option::<&DumbBuffer>::None);
299270 }
300271 for crtc in cleanup {
301272 let _ = self.drm.set_crtc(crtc, None, (0, 0), &[], None);