closing_window: Store textures directly
Browse files at this commit464441f9ebd288bc74910cd50840093d1ca5310cParent: bc292562 changed files +44 -32
- src/layout/closing_window.rs +43 -31
- src/layout/workspace.rs +1 -1
src/layout/closing_window.rsmodified+43 -31
| @@ -3,12 +3,13 @@ use std::time::Duration; | |||
| 3 | use anyhow::Context as _; | 3 | use anyhow::Context as _; |
| 4 | use niri_config::BlockOutFrom; | 4 | use niri_config::BlockOutFrom; |
| 5 | use smithay::backend::allocator::Fourcc; | 5 | use smithay::backend::allocator::Fourcc; |
| 6 | -use smithay::backend::renderer::element::texture::{TextureBuffer, TextureRenderElement}; | 6 | +use smithay::backend::renderer::element::texture::TextureRenderElement; |
| 7 | use smithay::backend::renderer::element::utils::{ | 7 | use smithay::backend::renderer::element::utils::{ |
| 8 | Relocate, RelocateRenderElement, RescaleRenderElement, | 8 | Relocate, RelocateRenderElement, RescaleRenderElement, |
| 9 | }; | 9 | }; |
| 10 | -use smithay::backend::renderer::element::{Kind, RenderElement}; | 10 | +use smithay::backend::renderer::element::{Id, Kind, RenderElement}; |
| 11 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; | 11 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; |
| 12 | +use smithay::backend::renderer::Renderer as _; | ||
| 12 | use smithay::utils::{Logical, Point, Scale, Transform}; | 13 | use smithay::utils::{Logical, Point, Scale, Transform}; |
| 13 | 14 | ||
| 14 | use crate::animation::Animation; | 15 | use crate::animation::Animation; |
| @@ -20,10 +21,16 @@ use crate::render_helpers::{render_to_encompassing_texture, RenderTarget}; | |||
| 20 | #[derive(Debug)] | 21 | #[derive(Debug)] |
| 21 | pub struct ClosingWindow { | 22 | pub struct ClosingWindow { |
| 22 | /// Contents of the window. | 23 | /// Contents of the window. |
| 23 | - buffer: TextureBuffer<GlesTexture>, | 24 | + texture: GlesTexture, |
| 24 | 25 | ||
| 25 | /// Blocked-out contents of the window. | 26 | /// Blocked-out contents of the window. |
| 26 | - blocked_out_buffer: TextureBuffer<GlesTexture>, | 27 | + blocked_out_texture: GlesTexture, |
| 28 | + | ||
| 29 | + /// Scale that the textures was rendered with. | ||
| 30 | + texture_scale: Scale<f64>, | ||
| 31 | + | ||
| 32 | + /// ID of the textures' renderer. | ||
| 33 | + texture_renderer_id: usize, | ||
| 27 | 34 | ||
| 28 | /// Where the window should be blocked out from. | 35 | /// Where the window should be blocked out from. |
| 29 | block_out_from: Option<BlockOutFrom>, | 36 | block_out_from: Option<BlockOutFrom>, |
| @@ -34,11 +41,11 @@ pub struct ClosingWindow { | |||
| 34 | /// Position in the workspace. | 41 | /// Position in the workspace. |
| 35 | pos: Point<i32, Logical>, | 42 | pos: Point<i32, Logical>, |
| 36 | 43 | ||
| 37 | - /// How much the buffer should be offset. | 44 | + /// How much the texture should be offset. |
| 38 | - buffer_offset: Point<i32, Logical>, | 45 | + texture_offset: Point<f64, Logical>, |
| 39 | 46 | ||
| 40 | - /// How much the blocked-out buffer should be offset. | 47 | + /// How much the blocked-out texture should be offset. |
| 41 | - blocked_out_buffer_offset: Point<i32, Logical>, | 48 | + blocked_out_texture_offset: Point<f64, Logical>, |
| 42 | 49 | ||
| 43 | /// The closing animation. | 50 | /// The closing animation. |
| 44 | anim: Animation, | 51 | anim: Animation, |
| @@ -61,7 +68,7 @@ impl ClosingWindow { | |||
| 61 | pub fn new<E: RenderElement<GlesRenderer>>( | 68 | pub fn new<E: RenderElement<GlesRenderer>>( |
| 62 | renderer: &mut GlesRenderer, | 69 | renderer: &mut GlesRenderer, |
| 63 | snapshot: RenderSnapshot<E, E>, | 70 | snapshot: RenderSnapshot<E, E>, |
| 64 | - scale: i32, | 71 | + scale: Scale<f64>, |
| 65 | center: Point<i32, Logical>, | 72 | center: Point<i32, Logical>, |
| 66 | pos: Point<i32, Logical>, | 73 | pos: Point<i32, Logical>, |
| 67 | anim: Animation, | 74 | anim: Animation, |
| @@ -70,37 +77,37 @@ impl ClosingWindow { | |||
| 70 | ) -> anyhow::Result<Self> { | 77 | ) -> anyhow::Result<Self> { |
| 71 | let _span = tracy_client::span!("ClosingWindow::new"); | 78 | let _span = tracy_client::span!("ClosingWindow::new"); |
| 72 | 79 | ||
| 73 | - let mut render_to_buffer = |elements: Vec<E>| -> anyhow::Result<_> { | 80 | + let mut render_to_texture = |elements: Vec<E>| -> anyhow::Result<_> { |
| 74 | let (texture, _sync_point, geo) = render_to_encompassing_texture( | 81 | let (texture, _sync_point, geo) = render_to_encompassing_texture( |
| 75 | renderer, | 82 | renderer, |
| 76 | - Scale::from(scale as f64), | 83 | + scale, |
| 77 | Transform::Normal, | 84 | Transform::Normal, |
| 78 | Fourcc::Abgr8888, | 85 | Fourcc::Abgr8888, |
| 79 | &elements, | 86 | &elements, |
| 80 | ) | 87 | ) |
| 81 | .context("error rendering to texture")?; | 88 | .context("error rendering to texture")?; |
| 82 | 89 | ||
| 83 | - let buffer = | 90 | + let offset = geo.loc.to_f64().to_logical(scale); |
| 84 | - TextureBuffer::from_texture(renderer, texture, scale, Transform::Normal, None); | ||
| 85 | - let offset = geo.loc.to_logical(scale); | ||
| 86 | 91 | ||
| 87 | - Ok((buffer, offset)) | 92 | + Ok((texture, offset)) |
| 88 | }; | 93 | }; |
| 89 | 94 | ||
| 90 | - let (buffer, buffer_offset) = | 95 | + let (texture, texture_offset) = |
| 91 | - render_to_buffer(snapshot.contents).context("error rendering contents")?; | 96 | + render_to_texture(snapshot.contents).context("error rendering contents")?; |
| 92 | - let (blocked_out_buffer, blocked_out_buffer_offset) = | 97 | + let (blocked_out_texture, blocked_out_texture_offset) = |
| 93 | - render_to_buffer(snapshot.blocked_out_contents) | 98 | + render_to_texture(snapshot.blocked_out_contents) |
| 94 | .context("error rendering blocked-out contents")?; | 99 | .context("error rendering blocked-out contents")?; |
| 95 | 100 | ||
| 96 | Ok(Self { | 101 | Ok(Self { |
| 97 | - buffer, | 102 | + texture, |
| 98 | - blocked_out_buffer, | 103 | + blocked_out_texture, |
| 104 | + texture_scale: scale, | ||
| 105 | + texture_renderer_id: renderer.id(), | ||
| 99 | block_out_from: snapshot.block_out_from, | 106 | block_out_from: snapshot.block_out_from, |
| 100 | center, | 107 | center, |
| 101 | pos, | 108 | pos, |
| 102 | - buffer_offset, | 109 | + texture_offset, |
| 103 | - blocked_out_buffer_offset, | 110 | + blocked_out_texture_offset, |
| 104 | anim, | 111 | anim, |
| 105 | starting_alpha, | 112 | starting_alpha, |
| 106 | starting_scale, | 113 | starting_scale, |
| @@ -123,18 +130,23 @@ impl ClosingWindow { | |||
| 123 | ) -> ClosingWindowRenderElement { | 130 | ) -> ClosingWindowRenderElement { |
| 124 | let val = self.anim.clamped_value(); | 131 | let val = self.anim.clamped_value(); |
| 125 | 132 | ||
| 126 | - let (buffer, offset) = if target.should_block_out(self.block_out_from) { | 133 | + let (texture, offset) = if target.should_block_out(self.block_out_from) { |
| 127 | - (&self.blocked_out_buffer, self.blocked_out_buffer_offset) | 134 | + (&self.blocked_out_texture, self.blocked_out_texture_offset) |
| 128 | } else { | 135 | } else { |
| 129 | - (&self.buffer, self.buffer_offset) | 136 | + (&self.texture, self.texture_offset) |
| 130 | }; | 137 | }; |
| 131 | 138 | ||
| 132 | - let elem = TextureRenderElement::from_texture_buffer( | 139 | + let elem = TextureRenderElement::from_static_texture( |
| 140 | + Id::new(), | ||
| 141 | + self.texture_renderer_id, | ||
| 133 | Point::from((0., 0.)), | 142 | Point::from((0., 0.)), |
| 134 | - buffer, | 143 | + texture.clone(), |
| 144 | + self.texture_scale.x as i32, | ||
| 145 | + Transform::Normal, | ||
| 135 | Some(val.clamp(0., 1.) as f32 * self.starting_alpha), | 146 | Some(val.clamp(0., 1.) as f32 * self.starting_alpha), |
| 136 | None, | 147 | None, |
| 137 | None, | 148 | None, |
| 149 | + None, | ||
| 138 | Kind::Unspecified, | 150 | Kind::Unspecified, |
| 139 | ); | 151 | ); |
| 140 | 152 | ||
| @@ -142,12 +154,12 @@ impl ClosingWindow { | |||
| 142 | 154 | ||
| 143 | let elem = RescaleRenderElement::from_element( | 155 | let elem = RescaleRenderElement::from_element( |
| 144 | elem, | 156 | elem, |
| 145 | - (self.center - offset).to_physical_precise_round(scale), | 157 | + (self.center.to_f64() - offset).to_physical_precise_round(scale), |
| 146 | ((val / 5. + 0.8) * self.starting_scale).max(0.), | 158 | ((val / 5. + 0.8) * self.starting_scale).max(0.), |
| 147 | ); | 159 | ); |
| 148 | 160 | ||
| 149 | - let mut location = self.pos + offset; | 161 | + let mut location = self.pos.to_f64() + offset; |
| 150 | - location.x -= view_pos; | 162 | + location.x -= view_pos as f64; |
| 151 | let elem = RelocateRenderElement::from_element( | 163 | let elem = RelocateRenderElement::from_element( |
| 152 | elem, | 164 | elem, |
| 153 | location.to_physical_precise_round(scale), | 165 | location.to_physical_precise_round(scale), |
src/layout/workspace.rsmodified+1 -1
| @@ -1363,7 +1363,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1363 | let res = ClosingWindow::new( | 1363 | let res = ClosingWindow::new( |
| 1364 | renderer, | 1364 | renderer, |
| 1365 | snapshot, | 1365 | snapshot, |
| 1366 | - output_scale.x as i32, | 1366 | + output_scale, |
| 1367 | center, | 1367 | center, |
| 1368 | tile_pos, | 1368 | tile_pos, |
| 1369 | anim, | 1369 | anim, |