ui/config_error_notification: Store TextureBuffers
Browse files at this commit02c2972e7446347d623c65bd52d45e5fa31209c8Parent: 4b830ee1 changed file +15 -10
src/ui/config_error_notification.rsmodified+15 -10
| @@ -9,12 +9,12 @@ use ordered_float::NotNan; | |||
| 9 | use pangocairo::cairo::{self, ImageSurface}; | 9 | use pangocairo::cairo::{self, ImageSurface}; |
| 10 | use pangocairo::pango::FontDescription; | 10 | use pangocairo::pango::FontDescription; |
| 11 | use smithay::backend::renderer::element::Kind; | 11 | use smithay::backend::renderer::element::Kind; |
| 12 | +use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; | ||
| 12 | use smithay::output::Output; | 13 | use smithay::output::Output; |
| 13 | use smithay::reexports::gbm::Format as Fourcc; | 14 | use smithay::reexports::gbm::Format as Fourcc; |
| 14 | use smithay::utils::{Point, Transform}; | 15 | use smithay::utils::{Point, Transform}; |
| 15 | 16 | ||
| 16 | use crate::animation::Animation; | 17 | use crate::animation::Animation; |
| 17 | -use crate::render_helpers::memory::MemoryBuffer; | ||
| 18 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; | 18 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; |
| 19 | use crate::render_helpers::renderer::NiriRenderer; | 19 | use crate::render_helpers::renderer::NiriRenderer; |
| 20 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; | 20 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; |
| @@ -29,7 +29,7 @@ const BORDER: i32 = 4; | |||
| 29 | 29 | ||
| 30 | pub struct ConfigErrorNotification { | 30 | pub struct ConfigErrorNotification { |
| 31 | state: State, | 31 | state: State, |
| 32 | - buffers: RefCell<HashMap<NotNan<f64>, Option<MemoryBuffer>>>, | 32 | + buffers: RefCell<HashMap<NotNan<f64>, Option<TextureBuffer<GlesTexture>>>>, |
| 33 | 33 | ||
| 34 | // If set, this is a "Created config at {path}" notification. If unset, this is a config error | 34 | // If set, this is a "Created config at {path}" notification. If unset, this is a config error |
| 35 | // notification. | 35 | // notification. |
| @@ -138,12 +138,10 @@ impl ConfigErrorNotification { | |||
| 138 | let mut buffers = self.buffers.borrow_mut(); | 138 | let mut buffers = self.buffers.borrow_mut(); |
| 139 | let buffer = buffers | 139 | let buffer = buffers |
| 140 | .entry(NotNan::new(scale).unwrap()) | 140 | .entry(NotNan::new(scale).unwrap()) |
| 141 | - .or_insert_with(move || render(scale, path).ok()); | 141 | + .or_insert_with(move || render(renderer.as_gles_renderer(), scale, path).ok()); |
| 142 | - let buffer = buffer.as_ref()?; | 142 | + let buffer = buffer.clone()?; |
| 143 | 143 | ||
| 144 | let size = buffer.logical_size(); | 144 | let size = buffer.logical_size(); |
| 145 | - let buffer = TextureBuffer::from_memory_buffer(renderer.as_gles_renderer(), buffer).ok()?; | ||
| 146 | - | ||
| 147 | let y_range = size.h + f64::from(PADDING) * 2.; | 145 | let y_range = size.h + f64::from(PADDING) * 2.; |
| 148 | 146 | ||
| 149 | let x = (f64::from(output_size.w) - size.w).max(0.) / 2.; | 147 | let x = (f64::from(output_size.w) - size.w).max(0.) / 2.; |
| @@ -168,7 +166,11 @@ impl ConfigErrorNotification { | |||
| 168 | } | 166 | } |
| 169 | } | 167 | } |
| 170 | 168 | ||
| 171 | -fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result<MemoryBuffer> { | 169 | +fn render( |
| 170 | + renderer: &mut GlesRenderer, | ||
| 171 | + scale: f64, | ||
| 172 | + created_path: Option<&Path>, | ||
| 173 | +) -> anyhow::Result<TextureBuffer<GlesTexture>> { | ||
| 172 | let _span = tracy_client::span!("config_error_notification::render"); | 174 | let _span = tracy_client::span!("config_error_notification::render"); |
| 173 | 175 | ||
| 174 | let padding = apply_scale(scale, PADDING); | 176 | let padding = apply_scale(scale, PADDING); |
| @@ -222,13 +224,16 @@ fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result<MemoryBuffe | |||
| 222 | drop(cr); | 224 | drop(cr); |
| 223 | 225 | ||
| 224 | let data = surface.take_data().unwrap(); | 226 | let data = surface.take_data().unwrap(); |
| 225 | - let buffer = MemoryBuffer::new( | 227 | + let buffer = TextureBuffer::from_memory( |
| 226 | - data.to_vec(), | 228 | + renderer, |
| 229 | + &data, | ||
| 227 | Fourcc::Argb8888, | 230 | Fourcc::Argb8888, |
| 228 | (width, height), | 231 | (width, height), |
| 232 | + false, | ||
| 229 | scale, | 233 | scale, |
| 230 | Transform::Normal, | 234 | Transform::Normal, |
| 231 | - ); | 235 | + Vec::new(), |
| 236 | + )?; | ||
| 232 | 237 | ||
| 233 | Ok(buffer) | 238 | Ok(buffer) |
| 234 | } | 239 | } |