Lift output clones from queue_redraw()

This commit is contained in:
Ivan Molodetskikh
2024-03-23 14:16:36 +04:00
parent 021a2a1af7
commit f3f02aca20
7 changed files with 57 additions and 55 deletions
+4 -4
View File
@@ -884,7 +884,7 @@ impl Tty {
// Power on all monitors if necessary and queue a redraw on the new one.
niri.event_loop.insert_idle(move |state| {
state.niri.activate_monitors(&mut state.backend);
state.niri.queue_redraw(output);
state.niri.queue_redraw(&output);
});
Ok(())
@@ -1067,7 +1067,7 @@ impl Tty {
.non_continuous_frame(surface.vblank_frame_name);
surface.vblank_frame = Some(vblank_frame);
niri.queue_redraw(output);
niri.queue_redraw(&output);
} else {
niri.send_frame_callbacks(&output);
}
@@ -1100,7 +1100,7 @@ impl Tty {
}
if output_state.unfinished_animations_remain {
niri.queue_redraw(output);
niri.queue_redraw(&output);
} else {
niri.send_frame_callbacks(&output);
}
@@ -1538,7 +1538,7 @@ impl Tty {
output.change_current_state(Some(wl_mode), None, None, None);
output.set_preferred(wl_mode);
output_state.frame_clock = FrameClock::new(Some(refresh_interval(mode)));
niri.output_resized(output);
niri.output_resized(&output);
}
for (connector, crtc) in device.drm_scanner.crtcs() {
+2 -4
View File
@@ -102,13 +102,11 @@ impl Winit {
mode.width = size.w.clamp(0, u16::MAX as i32) as u16;
mode.height = size.h.clamp(0, u16::MAX as i32) as u16;
state.niri.output_resized(winit.output.clone());
state.niri.output_resized(&winit.output);
}
WinitEvent::Input(event) => state.process_input_event(event),
WinitEvent::Focus(_) => (),
WinitEvent::Redraw => state
.niri
.queue_redraw(state.backend.winit().output.clone()),
WinitEvent::Redraw => state.niri.queue_redraw(&state.backend.winit().output),
WinitEvent::CloseRequested => state.niri.stop_signal.stop(),
})
.unwrap();
+6 -6
View File
@@ -168,7 +168,7 @@ impl CompositorHandler for State {
self.maybe_warp_cursor_to_focus();
}
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
}
return;
}
@@ -206,7 +206,7 @@ impl CompositorHandler for State {
let unmapped = Unmapped::new(window);
self.niri.unmapped_windows.insert(surface.clone(), unmapped);
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
return;
}
@@ -216,7 +216,7 @@ impl CompositorHandler for State {
// Popup placement depends on window size which might have changed.
self.update_reactive_popups(&window, &output);
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
return;
}
@@ -230,7 +230,7 @@ impl CompositorHandler for State {
let output = output.clone();
window.on_commit();
self.niri.layout.update_window(&window);
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
return;
}
@@ -238,7 +238,7 @@ impl CompositorHandler for State {
self.popups_handle_commit(surface);
if let Some(popup) = self.niri.popups.find_popup(surface) {
if let Some(output) = self.output_for_popup(&popup) {
self.niri.queue_redraw(output.clone());
self.niri.queue_redraw(&output.clone());
}
}
@@ -263,7 +263,7 @@ impl CompositorHandler for State {
for (output, state) in &self.niri.output_state {
if let Some(lock_surface) = &state.lock_surface {
if lock_surface.wl_surface() == surface {
self.niri.queue_redraw(output.clone());
self.niri.queue_redraw(&output.clone());
break;
}
}
+2 -2
View File
@@ -50,7 +50,7 @@ impl WlrLayerShellHandler for State {
None
};
if let Some(output) = output {
self.niri.output_resized(output);
self.niri.output_resized(&output);
}
}
@@ -107,6 +107,6 @@ impl State {
}
drop(map);
self.niri.output_resized(output);
self.niri.output_resized(&output);
}
}
+3 -3
View File
@@ -391,12 +391,12 @@ impl XdgShellHandler for State {
self.maybe_warp_cursor_to_focus();
}
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
}
fn popup_destroyed(&mut self, surface: PopupSurface) {
if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {
self.niri.queue_redraw(output.clone());
self.niri.queue_redraw(&output.clone());
}
}
@@ -756,7 +756,7 @@ impl State {
self.niri.layout.update_window(&window);
if let Some(output) = output {
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
}
}
}
+4 -4
View File
@@ -1449,7 +1449,7 @@ impl State {
.workspace_switch_gesture_update(delta_y, timestamp);
if let Some(output) = res {
if let Some(output) = output {
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
}
handled = true;
}
@@ -1460,7 +1460,7 @@ impl State {
.view_offset_gesture_update(delta_x, timestamp);
if let Some(output) = res {
if let Some(output) = output {
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
}
handled = true;
}
@@ -1494,13 +1494,13 @@ impl State {
.layout
.workspace_switch_gesture_end(event.cancelled());
if let Some(output) = res {
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
handled = true;
}
let res = self.niri.layout.view_offset_gesture_end(event.cancelled());
if let Some(output) = res {
self.niri.queue_redraw(output);
self.niri.queue_redraw(&output);
handled = true;
}
+36 -32
View File
@@ -338,6 +338,27 @@ pub enum CenterCoords {
#[derive(Default)]
pub struct WindowOffscreenId(pub RefCell<Option<Id>>);
impl RedrawState {
fn queue_redraw(self) -> Self {
match self {
RedrawState::Idle => RedrawState::Queued,
RedrawState::WaitingForEstimatedVBlank(token) => {
RedrawState::WaitingForEstimatedVBlankAndQueued(token)
}
// A redraw is already queued.
value @ (RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => {
value
}
// We're waiting for VBlank, request a redraw afterwards.
RedrawState::WaitingForVBlank { .. } => RedrawState::WaitingForVBlank {
redraw_needed: true,
},
}
}
}
impl Default for SurfaceFrameThrottlingState {
fn default() -> Self {
Self {
@@ -863,7 +884,7 @@ impl State {
}
}
for output in resized_outputs {
self.niri.output_resized(output);
self.niri.output_resized(&output);
}
self.backend.on_output_config_changed(&mut self.niri);
@@ -955,7 +976,7 @@ impl State {
}
}
ScreenCastToNiri::StopCast { session_id } => self.niri.stop_cast(session_id),
ScreenCastToNiri::Redraw(output) => self.niri.queue_redraw(output),
ScreenCastToNiri::Redraw(output) => self.niri.queue_redraw(&output),
}
}
@@ -1423,7 +1444,7 @@ impl Niri {
new_position.x, new_position.y
);
output.change_current_state(None, None, None, Some(new_position));
self.queue_redraw(output);
self.queue_redraw(&output);
}
}
}
@@ -1548,27 +1569,26 @@ impl Niri {
}
}
pub fn output_resized(&mut self, output: Output) {
let output_size = output_size(&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();
self.layout.update_output_size(&output);
layer_map_for_output(output).arrange();
self.layout.update_output_size(output);
if let Some(state) = self.output_state.get_mut(&output) {
if let Some(state) = self.output_state.get_mut(output) {
state.background_buffer.resize(output_size);
state.lock_color_buffer.resize(output_size);
if is_locked {
if let Some(lock_surface) = &state.lock_surface {
configure_lock_surface(lock_surface, &output);
configure_lock_surface(lock_surface, output);
}
}
}
// If the output size changed with an open screenshot UI, close the screenshot UI.
if let Some((old_size, old_scale, old_transform)) = self.screenshot_ui.output_size(&output)
{
if let Some((old_size, old_scale, old_transform)) = self.screenshot_ui.output_size(output) {
let transform = output.current_transform();
let output_mode = output.current_mode().unwrap();
let size = transform.transform_size(output_mode.size);
@@ -1879,31 +1899,15 @@ impl Niri {
/// Schedules an immediate redraw on all outputs if one is not already scheduled.
pub fn queue_redraw_all(&mut self) {
let outputs: Vec<_> = self.output_state.keys().cloned().collect();
for output in outputs {
self.queue_redraw(output);
for state in self.output_state.values_mut() {
state.redraw_state = mem::take(&mut state.redraw_state).queue_redraw();
}
}
/// Schedules an immediate redraw if one is not already scheduled.
pub fn queue_redraw(&mut self, output: Output) {
let state = self.output_state.get_mut(&output).unwrap();
state.redraw_state = match mem::take(&mut state.redraw_state) {
RedrawState::Idle => RedrawState::Queued,
RedrawState::WaitingForEstimatedVBlank(token) => {
RedrawState::WaitingForEstimatedVBlankAndQueued(token)
}
// A redraw is already queued.
value @ (RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => {
value
}
// We're waiting for VBlank, request a redraw afterwards.
RedrawState::WaitingForVBlank { .. } => RedrawState::WaitingForVBlank {
redraw_needed: true,
},
};
pub fn queue_redraw(&mut self, output: &Output) {
let state = self.output_state.get_mut(output).unwrap();
state.redraw_state = mem::take(&mut state.redraw_state).queue_redraw();
}
pub fn redraw_queued_outputs(&mut self, backend: &mut Backend) {