Draw background with a solid color buffer
Browse files at this commite73f33d6a3cfc8703d8ae79b97f29ad30bfa24e4Parent: 27e26483 changed files +30 -16
- src/backend/tty.rs +3 -6
- src/backend/winit.rs +2 -2
- src/niri.rs +25 -8
src/backend/tty.rsmodified+3 -6
| @@ -38,7 +38,7 @@ use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; | |||
| 38 | use smithay_drm_extras::edid::EdidInfo; | 38 | use smithay_drm_extras::edid::EdidInfo; |
| 39 | 39 | ||
| 40 | use crate::config::Config; | 40 | use crate::config::Config; |
| 41 | -use crate::niri::{OutputRenderElements, State, RedrawState, CLEAR_COLOR}; | 41 | +use crate::niri::{OutputRenderElements, State, RedrawState}; |
| 42 | use crate::utils::get_monotonic_time; | 42 | use crate::utils::get_monotonic_time; |
| 43 | use crate::Niri; | 43 | use crate::Niri; |
| 44 | 44 | ||
| @@ -859,11 +859,8 @@ impl Tty { | |||
| 859 | span.emit_text(&surface.name); | 859 | span.emit_text(&surface.name); |
| 860 | 860 | ||
| 861 | let drm_compositor = &mut surface.compositor; | 861 | let drm_compositor = &mut surface.compositor; |
| 862 | - match drm_compositor.render_frame::<_, _, GlesTexture>( | 862 | + match drm_compositor.render_frame::<_, _, GlesTexture>(&mut device.gles, elements, [0.; 4]) |
| 863 | - &mut device.gles, | 863 | + { |
| 864 | - elements, | ||
| 865 | - CLEAR_COLOR, | ||
| 866 | - ) { | ||
| 867 | Ok(res) => { | 864 | Ok(res) => { |
| 868 | if self | 865 | if self |
| 869 | .config | 866 | .config |
src/backend/winit.rsmodified+2 -2
| @@ -18,7 +18,7 @@ use smithay::utils::Transform; | |||
| 18 | 18 | ||
| 19 | use super::RenderResult; | 19 | use super::RenderResult; |
| 20 | use crate::config::Config; | 20 | use crate::config::Config; |
| 21 | -use crate::niri::{OutputRenderElements, RedrawState, State, CLEAR_COLOR}; | 21 | +use crate::niri::{OutputRenderElements, RedrawState, State}; |
| 22 | use crate::utils::get_monotonic_time; | 22 | use crate::utils::get_monotonic_time; |
| 23 | use crate::Niri; | 23 | use crate::Niri; |
| 24 | 24 | ||
| @@ -148,7 +148,7 @@ impl Winit { | |||
| 148 | let age = self.backend.buffer_age().unwrap(); | 148 | let age = self.backend.buffer_age().unwrap(); |
| 149 | let res = self | 149 | let res = self |
| 150 | .damage_tracker | 150 | .damage_tracker |
| 151 | - .render_output(self.backend.renderer(), age, elements, CLEAR_COLOR) | 151 | + .render_output(self.backend.renderer(), age, elements, [0.; 4]) |
| 152 | .unwrap(); | 152 | .unwrap(); |
| 153 | 153 | ||
| 154 | niri.update_primary_scanout_output(output, &res.states); | 154 | niri.update_primary_scanout_output(output, &res.states); |
src/niri.rsmodified+25 -8
| @@ -86,8 +86,8 @@ use crate::layout::{output_size, Layout, MonitorRenderElement}; | |||
| 86 | use crate::pw_utils::{Cast, PipeWire}; | 86 | use crate::pw_utils::{Cast, PipeWire}; |
| 87 | use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8}; | 87 | use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8}; |
| 88 | 88 | ||
| 89 | -pub const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.]; | 89 | +const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.]; |
| 90 | -pub const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.]; | 90 | +const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.]; |
| 91 | 91 | ||
| 92 | pub struct Niri { | 92 | pub struct Niri { |
| 93 | pub config: Rc<RefCell<Config>>, | 93 | pub config: Rc<RefCell<Config>>, |
| @@ -169,6 +169,9 @@ pub struct OutputState { | |||
| 169 | /// If there are no commits, then we won't have a timer running, so the estimated sequence will | 169 | /// If there are no commits, then we won't have a timer running, so the estimated sequence will |
| 170 | /// not increase. | 170 | /// not increase. |
| 171 | pub current_estimated_sequence: Option<u32>, | 171 | pub current_estimated_sequence: Option<u32>, |
| 172 | + /// Solid color buffer for the background that we use instead of clearing to avoid damage | ||
| 173 | + /// tracking issues and make screenshots easier. | ||
| 174 | + pub background_buffer: SolidColorBuffer, | ||
| 172 | pub lock_render_state: LockRenderState, | 175 | pub lock_render_state: LockRenderState, |
| 173 | pub lock_surface: Option<LockSurface>, | 176 | pub lock_surface: Option<LockSurface>, |
| 174 | pub lock_color_buffer: SolidColorBuffer, | 177 | pub lock_color_buffer: SolidColorBuffer, |
| @@ -750,6 +753,7 @@ impl Niri { | |||
| 750 | unfinished_animations_remain: false, | 753 | unfinished_animations_remain: false, |
| 751 | frame_clock: FrameClock::new(refresh_interval), | 754 | frame_clock: FrameClock::new(refresh_interval), |
| 752 | current_estimated_sequence: None, | 755 | current_estimated_sequence: None, |
| 756 | + background_buffer: SolidColorBuffer::new(size, CLEAR_COLOR), | ||
| 753 | lock_render_state, | 757 | lock_render_state, |
| 754 | lock_surface: None, | 758 | lock_surface: None, |
| 755 | lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED), | 759 | lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED), |
| @@ -817,12 +821,16 @@ impl Niri { | |||
| 817 | } | 821 | } |
| 818 | 822 | ||
| 819 | pub fn output_resized(&mut self, output: Output) { | 823 | pub fn output_resized(&mut self, output: Output) { |
| 824 | + let output_size = output_size(&output); | ||
| 825 | + let is_locked = self.is_locked(); | ||
| 826 | + | ||
| 820 | layer_map_for_output(&output).arrange(); | 827 | layer_map_for_output(&output).arrange(); |
| 821 | self.layout.update_output_size(&output); | 828 | self.layout.update_output_size(&output); |
| 822 | 829 | ||
| 823 | - let is_locked = self.is_locked(); | ||
| 824 | if let Some(state) = self.output_state.get_mut(&output) { | 830 | if let Some(state) = self.output_state.get_mut(&output) { |
| 825 | - state.lock_color_buffer.resize(output_size(&output)); | 831 | + state.background_buffer.resize(output_size); |
| 832 | + | ||
| 833 | + state.lock_color_buffer.resize(output_size); | ||
| 826 | if is_locked { | 834 | if is_locked { |
| 827 | if let Some(lock_surface) = &state.lock_surface { | 835 | if let Some(lock_surface) = &state.lock_surface { |
| 828 | configure_lock_surface(lock_surface, &output); | 836 | configure_lock_surface(lock_surface, &output); |
| @@ -1309,6 +1317,19 @@ impl Niri { | |||
| 1309 | extend_from_layer(&mut elements, Layer::Bottom); | 1317 | extend_from_layer(&mut elements, Layer::Bottom); |
| 1310 | extend_from_layer(&mut elements, Layer::Background); | 1318 | extend_from_layer(&mut elements, Layer::Background); |
| 1311 | 1319 | ||
| 1320 | + // Then the background. | ||
| 1321 | + let state = self.output_state.get(output).unwrap(); | ||
| 1322 | + elements.push( | ||
| 1323 | + SolidColorRenderElement::from_buffer( | ||
| 1324 | + &state.background_buffer, | ||
| 1325 | + (0, 0), | ||
| 1326 | + output_scale, | ||
| 1327 | + 1., | ||
| 1328 | + Kind::Unspecified, | ||
| 1329 | + ) | ||
| 1330 | + .into(), | ||
| 1331 | + ); | ||
| 1332 | + | ||
| 1312 | elements | 1333 | elements |
| 1313 | } | 1334 | } |
| 1314 | 1335 | ||
| @@ -2079,10 +2100,6 @@ fn render_to_dmabuf( | |||
| 2079 | .render(size, Transform::Normal) | 2100 | .render(size, Transform::Normal) |
| 2080 | .context("error starting frame")?; | 2101 | .context("error starting frame")?; |
| 2081 | 2102 | ||
| 2082 | - frame | ||
| 2083 | - .clear(CLEAR_COLOR, &[output_rect]) | ||
| 2084 | - .context("error clearing")?; | ||
| 2085 | - | ||
| 2086 | for element in elements.iter().rev() { | 2103 | for element in elements.iter().rev() { |
| 2087 | let src = element.src(); | 2104 | let src = element.src(); |
| 2088 | let dst = element.geometry(scale); | 2105 | let dst = element.geometry(scale); |