Return RenderResult from render()
Browse files at this commit29053a807b8969d3e2eb88c7065a087aaa137a31Parent: 0a327473 changed files +32 -6
- src/backend/mod.rs +11 -1
- src/backend/tty.rs +12 -4
- src/backend/winit.rs +9 -1
src/backend/mod.rsmodified+11 -1
| @@ -20,6 +20,16 @@ pub enum Backend { | ||
| 20 | 20 | Winit(Winit), |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | +#[derive(PartialEq, Eq)] | |
| 24 | +pub enum RenderResult { | |
| 25 | + /// The frame was submitted to the backend for presentation. | |
| 26 | + Submitted, | |
| 27 | + /// Rendering succeeded, but there was no damage. | |
| 28 | + NoDamage, | |
| 29 | + /// An error has occurred, the frame was not submitted. | |
| 30 | + Error, | |
| 31 | +} | |
| 32 | + | |
| 23 | 33 | impl Backend { |
| 24 | 34 | pub fn init(&mut self, niri: &mut Niri) { |
| 25 | 35 | match self { |
| @@ -48,7 +58,7 @@ impl Backend { | ||
| 48 | 58 | output: &Output, |
| 49 | 59 | elements: &[OutputRenderElements<GlesRenderer>], |
| 50 | 60 | target_presentation_time: Duration, |
| 51 | - ) { | |
| 61 | + ) -> RenderResult { | |
| 52 | 62 | match self { |
| 53 | 63 | Backend::Tty(tty) => tty.render(niri, output, elements, target_presentation_time), |
| 54 | 64 | Backend::Winit(winit) => winit.render(niri, output, elements), |
src/backend/tty.rsmodified+12 -4
| @@ -43,6 +43,8 @@ use crate::niri::{OutputRenderElements, State, RedrawState}; | ||
| 43 | 43 | use crate::utils::get_monotonic_time; |
| 44 | 44 | use crate::Niri; |
| 45 | 45 | |
| 46 | +use super::RenderResult; | |
| 47 | + | |
| 46 | 48 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; |
| 47 | 49 | |
| 48 | 50 | pub struct Tty { |
| @@ -837,18 +839,20 @@ impl Tty { | ||
| 837 | 839 | output: &Output, |
| 838 | 840 | elements: &[OutputRenderElements<GlesRenderer>], |
| 839 | 841 | target_presentation_time: Duration, |
| 840 | - ) { | |
| 842 | + ) -> RenderResult { | |
| 841 | 843 | let span = tracy_client::span!("Tty::render"); |
| 842 | 844 | |
| 845 | + let mut rv = RenderResult::Error; | |
| 846 | + | |
| 843 | 847 | let Some(device) = self.output_device.as_mut() else { |
| 844 | 848 | error!("missing output device"); |
| 845 | - return; | |
| 849 | + return rv; | |
| 846 | 850 | }; |
| 847 | 851 | |
| 848 | 852 | let tty_state: &TtyOutputState = output.user_data().get().unwrap(); |
| 849 | 853 | let Some(surface) = device.surfaces.get_mut(&tty_state.crtc) else { |
| 850 | 854 | error!("missing surface"); |
| 851 | - return; | |
| 855 | + return rv; | |
| 852 | 856 | }; |
| 853 | 857 | |
| 854 | 858 | span.emit_text(&surface.name); |
| @@ -896,12 +900,14 @@ impl Tty { | ||
| 896 | 900 | } |
| 897 | 901 | }; |
| 898 | 902 | |
| 899 | - return; | |
| 903 | + return RenderResult::Submitted; | |
| 900 | 904 | } |
| 901 | 905 | Err(err) => { |
| 902 | 906 | error!("error queueing frame: {err}"); |
| 903 | 907 | } |
| 904 | 908 | } |
| 909 | + } else { | |
| 910 | + rv = RenderResult::NoDamage; | |
| 905 | 911 | } |
| 906 | 912 | } |
| 907 | 913 | Err(err) => { |
| @@ -915,6 +921,8 @@ impl Tty { | ||
| 915 | 921 | |
| 916 | 922 | // Queue a timer to fire at the predicted vblank time. |
| 917 | 923 | queue_estimated_vblank_timer(niri, output.clone(), target_presentation_time); |
| 924 | + | |
| 925 | + rv | |
| 918 | 926 | } |
| 919 | 927 | |
| 920 | 928 | pub fn change_vt(&mut self, vt: i32) { |
src/backend/winit.rsmodified+9 -1
| @@ -17,6 +17,7 @@ use smithay::reexports::winit::dpi::LogicalSize; | ||
| 17 | 17 | use smithay::reexports::winit::window::WindowBuilder; |
| 18 | 18 | use smithay::utils::Transform; |
| 19 | 19 | |
| 20 | +use super::RenderResult; | |
| 20 | 21 | use crate::config::Config; |
| 21 | 22 | use crate::niri::{OutputRenderElements, RedrawState, State}; |
| 22 | 23 | use crate::utils::get_monotonic_time; |
| @@ -151,7 +152,7 @@ impl Winit { | ||
| 151 | 152 | niri: &mut Niri, |
| 152 | 153 | output: &Output, |
| 153 | 154 | elements: &[OutputRenderElements<GlesRenderer>], |
| 154 | - ) { | |
| 155 | + ) -> RenderResult { | |
| 155 | 156 | let _span = tracy_client::span!("Winit::render"); |
| 156 | 157 | |
| 157 | 158 | self.backend.bind().unwrap(); |
| @@ -164,6 +165,7 @@ impl Winit { | ||
| 164 | 165 | |
| 165 | 166 | niri.update_primary_scanout_output(output, &res.states); |
| 166 | 167 | |
| 168 | + let rv; | |
| 167 | 169 | if let Some(damage) = res.damage { |
| 168 | 170 | if self |
| 169 | 171 | .config |
| @@ -186,6 +188,10 @@ impl Winit { | ||
| 186 | 188 | 0, |
| 187 | 189 | wp_presentation_feedback::Kind::empty(), |
| 188 | 190 | ); |
| 191 | + | |
| 192 | + rv = RenderResult::Submitted; | |
| 193 | + } else { | |
| 194 | + rv = RenderResult::NoDamage; | |
| 189 | 195 | } |
| 190 | 196 | |
| 191 | 197 | let output_state = niri.output_state.get_mut(output).unwrap(); |
| @@ -200,6 +206,8 @@ impl Winit { | ||
| 200 | 206 | if output_state.unfinished_animations_remain { |
| 201 | 207 | self.backend.window().request_redraw(); |
| 202 | 208 | } |
| 209 | + | |
| 210 | + rv | |
| 203 | 211 | } |
| 204 | 212 | |
| 205 | 213 | pub fn toggle_debug_tint(&mut self) { |