mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-03 17:52:15 +00:00
Replaced some OnceLocks with tokio's OnceCell.
This commit is contained in:
parent
7485c2ee6a
commit
7a2835f6d1
@ -6,12 +6,8 @@ use {
|
||||
::image::DynamicImage,
|
||||
app_error::Context,
|
||||
image::imageops,
|
||||
std::{
|
||||
self,
|
||||
mem,
|
||||
path::Path,
|
||||
sync::{Arc, OnceLock},
|
||||
},
|
||||
std::{self, mem, path::Path, sync::Arc},
|
||||
tokio::sync::OnceCell,
|
||||
zsw_util::{AppError, Loadable, loadable::Loader},
|
||||
zsw_wgpu::Wgpu,
|
||||
zutil_cloned::cloned,
|
||||
@ -30,10 +26,10 @@ pub struct PanelFadeImages {
|
||||
pub next: Option<PanelFadeImage>,
|
||||
|
||||
/// Texture sampler
|
||||
pub image_sampler: OnceLock<wgpu::Sampler>,
|
||||
pub image_sampler: OnceCell<wgpu::Sampler>,
|
||||
|
||||
/// Texture bind group
|
||||
pub image_bind_group: OnceLock<wgpu::BindGroup>,
|
||||
pub image_bind_group: OnceCell<wgpu::BindGroup>,
|
||||
|
||||
/// Next image
|
||||
pub next_image: Loadable<ImageLoadRes, NextImageLoader>,
|
||||
@ -68,8 +64,8 @@ impl PanelFadeImages {
|
||||
prev: None,
|
||||
cur: None,
|
||||
next: None,
|
||||
image_sampler: OnceLock::new(),
|
||||
image_bind_group: OnceLock::new(),
|
||||
image_sampler: OnceCell::new(),
|
||||
image_bind_group: OnceCell::new(),
|
||||
next_image: Loadable::new(NextImageLoader),
|
||||
}
|
||||
}
|
||||
@ -84,7 +80,7 @@ impl PanelFadeImages {
|
||||
mem::swap(&mut self.cur, &mut self.next);
|
||||
mem::swap(&mut self.prev, &mut self.cur);
|
||||
self.prev = None;
|
||||
self.image_bind_group = OnceLock::new();
|
||||
self.image_bind_group = OnceCell::new();
|
||||
self.load_missing(playlist_player, wgpu);
|
||||
|
||||
Ok(())
|
||||
@ -104,7 +100,7 @@ impl PanelFadeImages {
|
||||
mem::swap(&mut self.prev, &mut self.cur);
|
||||
mem::swap(&mut self.cur, &mut self.next);
|
||||
self.next = None;
|
||||
self.image_bind_group = OnceLock::new();
|
||||
self.image_bind_group = OnceCell::new();
|
||||
self.load_missing(playlist_player, wgpu);
|
||||
|
||||
Ok(())
|
||||
@ -175,7 +171,7 @@ impl PanelFadeImages {
|
||||
Slot::Cur => self.cur = Some(image),
|
||||
Slot::Next => self.next = Some(image),
|
||||
}
|
||||
self.image_bind_group = OnceLock::new();
|
||||
self.image_bind_group = OnceCell::new();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,9 +18,9 @@ use {
|
||||
std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, hash_map},
|
||||
sync::{Arc, OnceLock},
|
||||
sync::Arc,
|
||||
},
|
||||
tokio::sync::Mutex,
|
||||
tokio::sync::{Mutex, OnceCell},
|
||||
wgpu::util::DeviceExt,
|
||||
winit::{dpi::PhysicalSize, window::Window},
|
||||
zsw_util::{AppError, Rect},
|
||||
@ -44,7 +44,7 @@ pub struct PanelsRendererShared {
|
||||
uniforms_bind_group_layout: wgpu::BindGroupLayout,
|
||||
|
||||
/// Fade image bind group layout
|
||||
fade_image_bind_group_layout: OnceLock<wgpu::BindGroupLayout>,
|
||||
fade_image_bind_group_layout: OnceCell<wgpu::BindGroupLayout>,
|
||||
}
|
||||
|
||||
impl PanelsRendererShared {
|
||||
@ -61,7 +61,7 @@ impl PanelsRendererShared {
|
||||
vertices,
|
||||
indices,
|
||||
uniforms_bind_group_layout,
|
||||
fade_image_bind_group_layout: OnceLock::new(),
|
||||
fade_image_bind_group_layout: OnceCell::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,7 +190,8 @@ impl PanelsRenderer {
|
||||
PanelState::Fade(_) => {
|
||||
let fade_image_bind_group_layout = shared
|
||||
.fade_image_bind_group_layout
|
||||
.get_or_init(|| self::create_fade_image_bind_group_layout(wgpu));
|
||||
.get_or_init(async || self::create_fade_image_bind_group_layout(wgpu))
|
||||
.await;
|
||||
&[&shared.uniforms_bind_group_layout, fade_image_bind_group_layout]
|
||||
},
|
||||
PanelState::Slide(_) => &[&shared.uniforms_bind_group_layout],
|
||||
@ -219,24 +220,29 @@ impl PanelsRenderer {
|
||||
let panel_images = panel_state.images_mut();
|
||||
let image_sampler = panel_images
|
||||
.image_sampler
|
||||
.get_or_init(|| self::create_image_sampler(wgpu));
|
||||
.get_or_init(async || self::create_image_sampler(wgpu))
|
||||
.await;
|
||||
|
||||
let [prev, cur, next] = [&panel_images.prev, &panel_images.cur, &panel_images.next]
|
||||
.map(|img| img.as_ref().map_or(&wgpu.empty_texture_view, |img| &img.texture_view));
|
||||
|
||||
let image_bind_group = panel_images.image_bind_group.get_or_init(|| {
|
||||
let fade_image_bind_group_layout = shared
|
||||
.fade_image_bind_group_layout
|
||||
.get_or_init(|| self::create_fade_image_bind_group_layout(wgpu));
|
||||
self::create_image_bind_group(
|
||||
wgpu,
|
||||
fade_image_bind_group_layout,
|
||||
prev,
|
||||
cur,
|
||||
next,
|
||||
image_sampler,
|
||||
)
|
||||
});
|
||||
let image_bind_group = panel_images
|
||||
.image_bind_group
|
||||
.get_or_init(async || {
|
||||
let fade_image_bind_group_layout = shared
|
||||
.fade_image_bind_group_layout
|
||||
.get_or_init(async || self::create_fade_image_bind_group_layout(wgpu))
|
||||
.await;
|
||||
self::create_image_bind_group(
|
||||
wgpu,
|
||||
fade_image_bind_group_layout,
|
||||
prev,
|
||||
cur,
|
||||
next,
|
||||
image_sampler,
|
||||
)
|
||||
})
|
||||
.await;
|
||||
render_pass.set_bind_group(1, image_bind_group, &[]);
|
||||
},
|
||||
PanelState::Slide(_panel_state) => (),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user