diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-09 12:59:05 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-17 09:02:22 +0300 |
| commit | 02c2972e7446347d623c65bd52d45e5fa31209c8 (patch) | |
| tree | 9c1dd023fdbba1017b6b1fc7227be06250480ca6 /src/ui/config_error_notification.rs | |
| parent | 4b830ee7ff2a96fc7bf05176c9da0095f890e1ad (diff) | |
| download | niri-02c2972e7446347d623c65bd52d45e5fa31209c8.tar.gz niri-02c2972e7446347d623c65bd52d45e5fa31209c8.tar.bz2 niri-02c2972e7446347d623c65bd52d45e5fa31209c8.zip | |
ui/config_error_notification: Store TextureBuffers
Avoids re-importing every frame.
Diffstat (limited to 'src/ui/config_error_notification.rs')
| -rw-r--r-- | src/ui/config_error_notification.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/ui/config_error_notification.rs b/src/ui/config_error_notification.rs index ffa5e130..566941c5 100644 --- a/src/ui/config_error_notification.rs +++ b/src/ui/config_error_notification.rs @@ -9,12 +9,12 @@ use ordered_float::NotNan; use pangocairo::cairo::{self, ImageSurface}; use pangocairo::pango::FontDescription; use smithay::backend::renderer::element::Kind; +use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; use smithay::output::Output; use smithay::reexports::gbm::Format as Fourcc; use smithay::utils::{Point, Transform}; use crate::animation::Animation; -use crate::render_helpers::memory::MemoryBuffer; use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; use crate::render_helpers::renderer::NiriRenderer; use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; @@ -29,7 +29,7 @@ const BORDER: i32 = 4; pub struct ConfigErrorNotification { state: State, - buffers: RefCell<HashMap<NotNan<f64>, Option<MemoryBuffer>>>, + buffers: RefCell<HashMap<NotNan<f64>, Option<TextureBuffer<GlesTexture>>>>, // If set, this is a "Created config at {path}" notification. If unset, this is a config error // notification. @@ -138,12 +138,10 @@ impl ConfigErrorNotification { let mut buffers = self.buffers.borrow_mut(); let buffer = buffers .entry(NotNan::new(scale).unwrap()) - .or_insert_with(move || render(scale, path).ok()); - let buffer = buffer.as_ref()?; + .or_insert_with(move || render(renderer.as_gles_renderer(), scale, path).ok()); + let buffer = buffer.clone()?; let size = buffer.logical_size(); - let buffer = TextureBuffer::from_memory_buffer(renderer.as_gles_renderer(), buffer).ok()?; - let y_range = size.h + f64::from(PADDING) * 2.; let x = (f64::from(output_size.w) - size.w).max(0.) / 2.; @@ -168,7 +166,11 @@ impl ConfigErrorNotification { } } -fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result<MemoryBuffer> { +fn render( + renderer: &mut GlesRenderer, + scale: f64, + created_path: Option<&Path>, +) -> anyhow::Result<TextureBuffer<GlesTexture>> { let _span = tracy_client::span!("config_error_notification::render"); let padding = apply_scale(scale, PADDING); @@ -222,13 +224,16 @@ fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result<MemoryBuffe drop(cr); let data = surface.take_data().unwrap(); - let buffer = MemoryBuffer::new( - data.to_vec(), + let buffer = TextureBuffer::from_memory( + renderer, + &data, Fourcc::Argb8888, (width, height), + false, scale, Transform::Normal, - ); + Vec::new(), + )?; Ok(buffer) } |
