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