diff --git a/dev-helper/src/painter_backend_eq_image_test.rs b/dev-helper/src/painter_backend_eq_image_test.rs index b7181e5b1..a58b16972 100644 --- a/dev-helper/src/painter_backend_eq_image_test.rs +++ b/dev-helper/src/painter_backend_eq_image_test.rs @@ -110,13 +110,6 @@ pub fn assert_texture_eq_png(img: PixelImage, file_path: &std::path::Path) { } } -// todo: Fix me, it looks like a wgpu bug? Windows systems may hang threads when -// using multiple WgpuImpl in tests. -// it's a temporary solution: manually lock SINGLETON_WGPU_GUARD to prevent -// multiple WgpuImpl in your tests. -pub static SINGLETON_WGPU_GUARD: once_cell::sync::Lazy> = - once_cell::sync::Lazy::new(|| std::sync::Mutex::new(())); - /// Render painter by wgpu backend, and return the image. pub fn wgpu_render_commands( commands: Vec, viewport: ribir_geom::DeviceRect, @@ -127,7 +120,6 @@ pub fn wgpu_render_commands( use ribir_gpu::{GPUBackend, GPUBackendImpl, Texture}; use ribir_painter::{AntiAliasing, PainterBackend}; - let _guard = SINGLETON_WGPU_GUARD.lock().unwrap(); let mut gpu_impl = block_on(ribir_gpu::WgpuImpl::headless()); let rect = DeviceRect::from_size(DeviceSize::new(viewport.max_x() + 2, viewport.max_y() + 2)); diff --git a/gpu/src/gpu_backend.rs b/gpu/src/gpu_backend.rs index f315fdddd..22fe6a886 100644 --- a/gpu/src/gpu_backend.rs +++ b/gpu/src/gpu_backend.rs @@ -546,14 +546,6 @@ mod tests { use ribir_painter::{Brush, Painter, Path, Svg}; use super::*; - use crate::WgpuImpl; - - pub fn headless() -> (WgpuImpl, std::sync::MutexGuard<'static, ()>) { - use futures::executor::block_on; - let _guard = SINGLETON_WGPU_GUARD.lock().unwrap(); - let gpu_impl = block_on(WgpuImpl::headless()); - (gpu_impl, _guard) - } fn painter(bounds: Size) -> Painter { Painter::new(Rect::from_size(bounds)) } diff --git a/gpu/src/gpu_backend/atlas.rs b/gpu/src/gpu_backend/atlas.rs index ae2fe899b..2a54c94d4 100644 --- a/gpu/src/gpu_backend/atlas.rs +++ b/gpu/src/gpu_backend/atlas.rs @@ -198,10 +198,10 @@ mod tests { use futures::executor::block_on; use super::*; - use crate::{gpu_backend::tests::headless, WgpuTexture}; + use crate::{WgpuImpl, WgpuTexture}; #[test] fn atlas_grow_to_alloc() { - let (mut gpu_impl, _guard) = headless(); + let mut gpu_impl = block_on(WgpuImpl::headless()); let mut atlas = Atlas::::new("_", ColorFormat::Alpha8, AntiAliasing::None, &mut gpu_impl); let size = DeviceSize::new(ATLAS_MIN_SIZE.width + 1, 16); @@ -212,7 +212,7 @@ mod tests { #[test] fn resource_clear() { - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut atlas = Atlas::::new("_", ColorFormat::Rgba8, AntiAliasing::None, &mut wgpu); atlas.allocate(1, (), DeviceSize::new(32, 32), &mut wgpu); @@ -227,7 +227,7 @@ mod tests { #[test] fn fix_scale_path_cache_miss() { - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut atlas = Atlas::::new("_", ColorFormat::Rgba8, AntiAliasing::None, &mut wgpu); atlas.allocate(1, (), DeviceSize::new(32, 32), &mut wgpu); @@ -250,7 +250,7 @@ mod tests { #[test] fn fix_atlas_expand_overlap() { - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut atlas = Atlas::::new("_", ColorFormat::Alpha8, AntiAliasing::None, &mut wgpu); let icon = DeviceSize::new(32, 32); diff --git a/gpu/src/gpu_backend/textures_mgr.rs b/gpu/src/gpu_backend/textures_mgr.rs index c5a32deeb..e33f98c86 100644 --- a/gpu/src/gpu_backend/textures_mgr.rs +++ b/gpu/src/gpu_backend/textures_mgr.rs @@ -538,7 +538,7 @@ pub mod tests { use ribir_painter::Color; use super::*; - use crate::{gpu_backend::tests::headless, WgpuImpl, WgpuTexture}; + use crate::{WgpuImpl, WgpuTexture}; pub fn color_image(color: Color, width: u32, height: u32) -> ShareResource { let data = std::iter::repeat(color.into_components()) @@ -552,7 +552,7 @@ pub mod tests { #[test] fn smoke_store_image() { - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut mgr = TexturesMgr::new(&mut wgpu, AntiAliasing::None); let red_img = color_image(Color::RED, 32, 32); @@ -598,7 +598,7 @@ pub mod tests { #[test] fn transform_path_share_cache() { - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut mgr = TexturesMgr::::new(&mut wgpu, AntiAliasing::None); let path1 = Path::rect(&rect(0., 0., 300., 300.)); @@ -615,7 +615,7 @@ pub mod tests { #[test] fn store_clipped_path() { - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut mgr = TexturesMgr::::new(&mut wgpu, AntiAliasing::None); let path = PaintPath::new( @@ -637,7 +637,7 @@ pub mod tests { // because the next resource may allocate at same address of a deallocated // address. - let (mut wgpu, _guard) = headless(); + let mut wgpu = block_on(WgpuImpl::headless()); let mut mgr = TexturesMgr::::new(&mut wgpu, AntiAliasing::None); { let red_img = color_image(Color::RED, 32, 32);