Draw background with a solid color buffer

This commit is contained in:
Ivan Molodetskikh
2023-10-27 08:34:00 +04:00
parent 27e2648bd4
commit e73f33d6a3
3 changed files with 30 additions and 16 deletions
+3 -6
View File
@@ -38,7 +38,7 @@ use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner};
use smithay_drm_extras::edid::EdidInfo; use smithay_drm_extras::edid::EdidInfo;
use crate::config::Config; use crate::config::Config;
use crate::niri::{OutputRenderElements, State, RedrawState, CLEAR_COLOR}; use crate::niri::{OutputRenderElements, State, RedrawState};
use crate::utils::get_monotonic_time; use crate::utils::get_monotonic_time;
use crate::Niri; use crate::Niri;
@@ -859,11 +859,8 @@ impl Tty {
span.emit_text(&surface.name); span.emit_text(&surface.name);
let drm_compositor = &mut surface.compositor; let drm_compositor = &mut surface.compositor;
match drm_compositor.render_frame::<_, _, GlesTexture>( match drm_compositor.render_frame::<_, _, GlesTexture>(&mut device.gles, elements, [0.; 4])
&mut device.gles, {
elements,
CLEAR_COLOR,
) {
Ok(res) => { Ok(res) => {
if self if self
.config .config
+2 -2
View File
@@ -18,7 +18,7 @@ use smithay::utils::Transform;
use super::RenderResult; use super::RenderResult;
use crate::config::Config; use crate::config::Config;
use crate::niri::{OutputRenderElements, RedrawState, State, CLEAR_COLOR}; use crate::niri::{OutputRenderElements, RedrawState, State};
use crate::utils::get_monotonic_time; use crate::utils::get_monotonic_time;
use crate::Niri; use crate::Niri;
@@ -148,7 +148,7 @@ impl Winit {
let age = self.backend.buffer_age().unwrap(); let age = self.backend.buffer_age().unwrap();
let res = self let res = self
.damage_tracker .damage_tracker
.render_output(self.backend.renderer(), age, elements, CLEAR_COLOR) .render_output(self.backend.renderer(), age, elements, [0.; 4])
.unwrap(); .unwrap();
niri.update_primary_scanout_output(output, &res.states); niri.update_primary_scanout_output(output, &res.states);
+25 -8
View File
@@ -86,8 +86,8 @@ use crate::layout::{output_size, Layout, MonitorRenderElement};
use crate::pw_utils::{Cast, PipeWire}; use crate::pw_utils::{Cast, PipeWire};
use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8}; use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8};
pub const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.]; const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
pub const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.]; const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.];
pub struct Niri { pub struct Niri {
pub config: Rc<RefCell<Config>>, pub config: Rc<RefCell<Config>>,
@@ -169,6 +169,9 @@ pub struct OutputState {
/// If there are no commits, then we won't have a timer running, so the estimated sequence will /// If there are no commits, then we won't have a timer running, so the estimated sequence will
/// not increase. /// not increase.
pub current_estimated_sequence: Option<u32>, pub current_estimated_sequence: Option<u32>,
/// Solid color buffer for the background that we use instead of clearing to avoid damage
/// tracking issues and make screenshots easier.
pub background_buffer: SolidColorBuffer,
pub lock_render_state: LockRenderState, pub lock_render_state: LockRenderState,
pub lock_surface: Option<LockSurface>, pub lock_surface: Option<LockSurface>,
pub lock_color_buffer: SolidColorBuffer, pub lock_color_buffer: SolidColorBuffer,
@@ -750,6 +753,7 @@ impl Niri {
unfinished_animations_remain: false, unfinished_animations_remain: false,
frame_clock: FrameClock::new(refresh_interval), frame_clock: FrameClock::new(refresh_interval),
current_estimated_sequence: None, current_estimated_sequence: None,
background_buffer: SolidColorBuffer::new(size, CLEAR_COLOR),
lock_render_state, lock_render_state,
lock_surface: None, lock_surface: None,
lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED), lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED),
@@ -817,12 +821,16 @@ impl Niri {
} }
pub fn output_resized(&mut self, output: Output) { pub fn output_resized(&mut self, output: Output) {
let output_size = output_size(&output);
let is_locked = self.is_locked();
layer_map_for_output(&output).arrange(); layer_map_for_output(&output).arrange();
self.layout.update_output_size(&output); self.layout.update_output_size(&output);
let is_locked = self.is_locked();
if let Some(state) = self.output_state.get_mut(&output) { if let Some(state) = self.output_state.get_mut(&output) {
state.lock_color_buffer.resize(output_size(&output)); state.background_buffer.resize(output_size);
state.lock_color_buffer.resize(output_size);
if is_locked { if is_locked {
if let Some(lock_surface) = &state.lock_surface { if let Some(lock_surface) = &state.lock_surface {
configure_lock_surface(lock_surface, &output); configure_lock_surface(lock_surface, &output);
@@ -1309,6 +1317,19 @@ impl Niri {
extend_from_layer(&mut elements, Layer::Bottom); extend_from_layer(&mut elements, Layer::Bottom);
extend_from_layer(&mut elements, Layer::Background); extend_from_layer(&mut elements, Layer::Background);
// Then the background.
let state = self.output_state.get(output).unwrap();
elements.push(
SolidColorRenderElement::from_buffer(
&state.background_buffer,
(0, 0),
output_scale,
1.,
Kind::Unspecified,
)
.into(),
);
elements elements
} }
@@ -2079,10 +2100,6 @@ fn render_to_dmabuf(
.render(size, Transform::Normal) .render(size, Transform::Normal)
.context("error starting frame")?; .context("error starting frame")?;
frame
.clear(CLEAR_COLOR, &[output_rect])
.context("error clearing")?;
for element in elements.iter().rev() { for element in elements.iter().rev() {
let src = element.src(); let src = element.src();
let dst = element.geometry(scale); let dst = element.geometry(scale);