forge
Explore
Log in

Don't you dare go Hollow

tile: Use OffscreenBuffer for resize anims

Browse files at this commit

3b8ce12316c7f5d1e4dbee1f040243837a80e882Ivan MolodetskikhParent: 880386e
OffscreenBuffer knows how to avoid recreating the texture every frame.
src/layout/tile.rsmodified+20 -16
@@ -2,10 +2,9 @@ use core::f64;
2 use std::rc::Rc;2 use std::rc::Rc;
3 3
4 use niri_config::{Color, CornerRadius, GradientInterpolation};4 use niri_config::{Color, CornerRadius, GradientInterpolation};
5-use smithay::backend::allocator::Fourcc;
6 use smithay::backend::renderer::element::{Element, Kind};5 use smithay::backend::renderer::element::{Element, Kind};
7 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
8-use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};7+use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
9 8
10 use super::focus_ring::{FocusRing, FocusRingRenderElement};9 use super::focus_ring::{FocusRing, FocusRingRenderElement};
11 use super::opening_window::{OpenAnimation, OpeningWindowRenderElement};10 use super::opening_window::{OpenAnimation, OpeningWindowRenderElement};
@@ -24,7 +23,7 @@ use crate::render_helpers::resize::ResizeRenderElement;
24 use crate::render_helpers::shadow::ShadowRenderElement;23 use crate::render_helpers::shadow::ShadowRenderElement;
25 use crate::render_helpers::snapshot::RenderSnapshot;24 use crate::render_helpers::snapshot::RenderSnapshot;
26 use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};25 use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
27-use crate::render_helpers::{render_to_encompassing_texture, RenderTarget};26+use crate::render_helpers::RenderTarget;
28 use crate::utils::round_logical_in_physical;27 use crate::utils::round_logical_in_physical;
29 use crate::utils::transaction::Transaction;28 use crate::utils::transaction::Transaction;
30 29
@@ -135,6 +134,7 @@ struct ResizeAnimation {
135 anim: Animation,134 anim: Animation,
136 size_from: Size<f64, Logical>,135 size_from: Size<f64, Logical>,
137 snapshot: LayoutElementRenderSnapshot,136 snapshot: LayoutElementRenderSnapshot,
137+ offscreen: OffscreenBuffer,
138 }138 }
139 139
140 #[derive(Debug)]140 #[derive(Debug)]
@@ -228,7 +228,7 @@ impl<W: LayoutElement> Tile<W> {
228 self.is_fullscreen = self.window.is_fullscreen();228 self.is_fullscreen = self.window.is_fullscreen();
229 229
230 if let Some(animate_from) = self.window.take_animation_snapshot() {230 if let Some(animate_from) = self.window.take_animation_snapshot() {
231- let size_from = if let Some(resize) = self.resize_animation.take() {231+ let (size_from, offscreen) = if let Some(resize) = self.resize_animation.take() {
232 // Compute like in animated_window_size(), but using the snapshot geometry (since232 // Compute like in animated_window_size(), but using the snapshot geometry (since
233 // the current one is already overwritten).233 // the current one is already overwritten).
234 let mut size = animate_from.size;234 let mut size = animate_from.size;
@@ -239,9 +239,10 @@ impl<W: LayoutElement> Tile<W> {
239 size.w = size_from.w + (size.w - size_from.w) * val;239 size.w = size_from.w + (size.w - size_from.w) * val;
240 size.h = size_from.h + (size.h - size_from.h) * val;240 size.h = size_from.h + (size.h - size_from.h) * val;
241 241
242- size242+ // Also try to reuse the existing offscreen buffer if we have one.
243+ (size, resize.offscreen)
243 } else {244 } else {
244- animate_from.size245+ (animate_from.size, OffscreenBuffer::default())
245 };246 };
246 247
247 let change = self.window.size().to_f64().to_point() - size_from.to_point();248 let change = self.window.size().to_f64().to_point() - size_from.to_point();
@@ -258,6 +259,7 @@ impl<W: LayoutElement> Tile<W> {
258 anim,259 anim,
259 size_from,260 size_from,
260 snapshot: animate_from,261 snapshot: animate_from,
262+ offscreen,
261 });263 });
262 } else {264 } else {
263 self.resize_animation = None;265 self.resize_animation = None;
@@ -848,15 +850,11 @@ impl<W: LayoutElement> Tile<W> {
848 target,850 target,
849 );851 );
850 852
851- let current = render_to_encompassing_texture(853+ let current = resize
852- gles_renderer,854+ .offscreen
853- scale,855+ .render(gles_renderer, scale, &window_elements)
854- Transform::Normal,856+ .map_err(|err| warn!("error rendering window to texture: {err:?}"))
855- Fourcc::Abgr8888,857+ .ok();
856- &window_elements,
857- )
858- .map_err(|err| warn!("error rendering window to texture: {err:?}"))
859- .ok();
860 858
861 // Clip blocked-out resizes unconditionally because they use solid color render859 // Clip blocked-out resizes unconditionally because they use solid color render
862 // elements.860 // elements.
@@ -869,7 +867,13 @@ impl<W: LayoutElement> Tile<W> {
869 clip_to_geometry867 clip_to_geometry
870 };868 };
871 869
872- if let Some((texture_current, _sync_point, texture_current_geo)) = current {870+ if let Some((elem_current, _sync_point)) = current {
871+ let texture_current = elem_current.texture().clone();
872+ // The offset and size are computed in physical pixels and converted to
873+ // logical with the same `scale`, so converting them back with rounding
874+ // inside the geometry() call gives us the same physical result back.
875+ let texture_current_geo = elem_current.geometry(scale);
876+
873 let elem = ResizeRenderElement::new(877 let elem = ResizeRenderElement::new(
874 area,878 area,
875 scale,879 scale,