tty: Add Surface state struct
Browse files at this commitb54e1522ff47001763aed97158ed7da202706fd7Parent: 1b9e9a11 changed file +18 -6
- src/backend/tty.rs +18 -6
src/backend/tty.rsmodified+18 -6
| @@ -60,7 +60,7 @@ struct OutputDevice { | ||
| 60 | 60 | gles: GlesRenderer, |
| 61 | 61 | formats: HashSet<DrmFormat>, |
| 62 | 62 | drm_scanner: DrmScanner, |
| 63 | - surfaces: HashMap<crtc::Handle, (GbmDrmCompositor, DmabufFeedback)>, | |
| 63 | + surfaces: HashMap<crtc::Handle, Surface>, | |
| 64 | 64 | dmabuf_state: DmabufState, |
| 65 | 65 | // dmabuf_global: DmabufGlobal, |
| 66 | 66 | } |
| @@ -71,6 +71,11 @@ struct TtyOutputState { | ||
| 71 | 71 | crtc: crtc::Handle, |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | +struct Surface { | |
| 75 | + compositor: GbmDrmCompositor, | |
| 76 | + dmabuf_feedback: DmabufFeedback, | |
| 77 | +} | |
| 78 | + | |
| 74 | 79 | impl Tty { |
| 75 | 80 | pub fn new(event_loop: LoopHandle<'static, LoopData>) -> Self { |
| 76 | 81 | let (session, notifier) = LibSeatSession::new().unwrap(); |
| @@ -275,7 +280,8 @@ impl Tty { | ||
| 275 | 280 | trace!("vblank {metadata:?}"); |
| 276 | 281 | |
| 277 | 282 | let device = tty.output_device.as_mut().unwrap(); |
| 278 | - let drm_compositor = &mut device.surfaces.get_mut(&crtc).unwrap().0; | |
| 283 | + let drm_compositor = | |
| 284 | + &mut device.surfaces.get_mut(&crtc).unwrap().compositor; | |
| 279 | 285 | |
| 280 | 286 | let presentation_time = match metadata.as_mut().unwrap().time { |
| 281 | 287 | DrmEventTime::Monotonic(time) => time, |
| @@ -513,7 +519,11 @@ impl Tty { | ||
| 513 | 519 | .build() |
| 514 | 520 | .unwrap(); |
| 515 | 521 | |
| 516 | - let res = device.surfaces.insert(crtc, (compositor, dmabuf_feedback)); | |
| 522 | + let surface = Surface { | |
| 523 | + compositor, | |
| 524 | + dmabuf_feedback, | |
| 525 | + }; | |
| 526 | + let res = device.surfaces.insert(crtc, surface); | |
| 517 | 527 | assert!(res.is_none(), "crtc must not have already existed"); |
| 518 | 528 | |
| 519 | 529 | niri.add_output(output.clone(), Some(refresh_interval(*mode))); |
| @@ -567,7 +577,8 @@ impl Tty { | ||
| 567 | 577 | |
| 568 | 578 | let device = self.output_device.as_mut().unwrap(); |
| 569 | 579 | let tty_state: &TtyOutputState = output.user_data().get().unwrap(); |
| 570 | - let (drm_compositor, dmabuf_feedback) = device.surfaces.get_mut(&tty_state.crtc).unwrap(); | |
| 580 | + let surface = device.surfaces.get_mut(&tty_state.crtc).unwrap(); | |
| 581 | + let drm_compositor = &mut surface.compositor; | |
| 571 | 582 | |
| 572 | 583 | match drm_compositor.render_frame::<_, _, GlesTexture>( |
| 573 | 584 | &mut device.gles, |
| @@ -587,7 +598,7 @@ impl Tty { | ||
| 587 | 598 | .unwrap() |
| 588 | 599 | .waiting_for_vblank = true; |
| 589 | 600 | |
| 590 | - return Some(dmabuf_feedback); | |
| 601 | + return Some(&surface.dmabuf_feedback); | |
| 591 | 602 | } |
| 592 | 603 | Err(err) => { |
| 593 | 604 | error!("error queueing frame: {err}"); |
| @@ -618,7 +629,8 @@ impl Tty { | ||
| 618 | 629 | |
| 619 | 630 | pub fn toggle_debug_tint(&mut self) { |
| 620 | 631 | if let Some(device) = self.output_device.as_mut() { |
| 621 | - for (_, (compositor, _)) in &mut device.surfaces { | |
| 632 | + for surface in device.surfaces.values_mut() { | |
| 633 | + let compositor = &mut surface.compositor; | |
| 622 | 634 | compositor.set_debug_flags(compositor.debug_flags() ^ DebugFlags::TINT); |
| 623 | 635 | } |
| 624 | 636 | } |