Merge pull request #736 from mahkoh/jorth/replace-utils
Replace some utils
This commit is contained in:
commit
6fb5526d64
29 changed files with 101 additions and 180 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -682,6 +682,7 @@ dependencies = [
|
|||
"rand 0.10.0",
|
||||
"regex",
|
||||
"repc",
|
||||
"run-on-drop",
|
||||
"rustc-demangle",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ cfg-if = "1.0.0"
|
|||
opera = "1.0.1"
|
||||
with_builtin_macros = "0.1.0"
|
||||
blake3 = "1.8.2"
|
||||
run-on-drop = "1.0.0"
|
||||
|
||||
[build-dependencies]
|
||||
repc = "0.1.1"
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ use {
|
|||
asyncevent::AsyncEvent, binary_search_map::BinarySearchMap, bitflags::BitflagsExt,
|
||||
cell_ext::CellExt, clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt,
|
||||
geometric_decay::GeometricDecay, numcell::NumCell, on_change::OnChange,
|
||||
on_drop::OnDrop2, opaque_cell::OpaqueCell, ordered_float::F64, oserror::OsError,
|
||||
opaque_cell::OpaqueCell, ordered_float::F64, oserror::OsError,
|
||||
},
|
||||
video::{
|
||||
INVALID_MODIFIER, Modifier,
|
||||
|
|
@ -62,6 +62,7 @@ use {
|
|||
indexmap::{IndexMap, IndexSet, indexset},
|
||||
isnt::std_1::collections::IsntHashMapExt,
|
||||
jay_config::video::GfxApi,
|
||||
run_on_drop::on_drop,
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
collections::hash_map::Entry,
|
||||
|
|
@ -2735,7 +2736,7 @@ impl MetalBackend {
|
|||
let Some(dev_gfx_format) = dev_gfx_formats.get(&format.drm) else {
|
||||
return Err(ScanoutBufferErrorKind::SodUnsupportedFormat);
|
||||
};
|
||||
let send_dev_gfx_write_modifiers = OnDrop2::new(|| {
|
||||
let send_dev_gfx_write_modifiers = on_drop(|| {
|
||||
*dbg_dev_gfx_write_modifiers =
|
||||
Some(dev_gfx_format.write_modifiers.keys().copied().collect())
|
||||
});
|
||||
|
|
@ -2745,7 +2746,7 @@ impl MetalBackend {
|
|||
.filter(|(m, _)| plane_modifiers.contains(*m))
|
||||
.map(|(m, v)| (*m, v))
|
||||
.collect();
|
||||
let send_dev_modifiers_possible = OnDrop2::new(|| {
|
||||
let send_dev_modifiers_possible = on_drop(|| {
|
||||
*dbg_dev_modifiers_possible = Some(possible_modifiers.keys().copied().collect())
|
||||
});
|
||||
if possible_modifiers.is_empty() {
|
||||
|
|
@ -2804,7 +2805,7 @@ impl MetalBackend {
|
|||
};
|
||||
(None, render_tex, None, None)
|
||||
} else {
|
||||
send_render_dev_name = Some(OnDrop2::new(|| {
|
||||
send_render_dev_name = Some(on_drop(|| {
|
||||
*dbg_render_name = Some(render_ctx.devnode.as_bytes().as_bstr().to_string());
|
||||
}));
|
||||
// Create a _bridge_ BO in the render device
|
||||
|
|
@ -2813,11 +2814,11 @@ impl MetalBackend {
|
|||
None => return Err(ScanoutBufferErrorKind::RenderUnsupportedFormat),
|
||||
Some(f) => f,
|
||||
};
|
||||
send_render_gfx_write_modifiers = Some(OnDrop2::new(|| {
|
||||
send_render_gfx_write_modifiers = Some(on_drop(|| {
|
||||
*dbg_render_gfx_write_modifiers =
|
||||
Some(render_gfx_format.write_modifiers.keys().copied().collect())
|
||||
}));
|
||||
send_dev_gfx_read_modifiers = Some(OnDrop2::new(|| {
|
||||
send_dev_gfx_read_modifiers = Some(on_drop(|| {
|
||||
*dbg_dev_gfx_read_modifiers = Some(dev_gfx_format.read_modifiers.clone());
|
||||
}));
|
||||
render_possible_modifiers = render_gfx_format
|
||||
|
|
@ -2826,7 +2827,7 @@ impl MetalBackend {
|
|||
.filter(|(m, _)| dev_gfx_format.read_modifiers.contains(*m))
|
||||
.map(|(m, v)| (*m, v))
|
||||
.collect();
|
||||
send_render_possible_modifiers = Some(OnDrop2::new(|| {
|
||||
send_render_possible_modifiers = Some(on_drop(|| {
|
||||
*dbg_render_modifiers_possible =
|
||||
Some(render_possible_modifiers.keys().copied().collect())
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ use {
|
|||
crate::{
|
||||
cli::{GlobalArgs, IdleArgs, duration::parse_duration},
|
||||
tools::tool_client::{Handle, ToolClient, with_tool_client},
|
||||
utils::{debug_fn::debug_fn, stack::Stack},
|
||||
utils::stack::Stack,
|
||||
wire::{JayIdleId, WlSurfaceId, jay_compositor, jay_idle},
|
||||
},
|
||||
clap::{Args, Subcommand},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
std::{cell::Cell, fmt, rc::Rc},
|
||||
};
|
||||
|
||||
#[derive(Subcommand, Debug, Default)]
|
||||
|
|
@ -105,7 +105,7 @@ impl Idle {
|
|||
});
|
||||
tc.round_trip().await;
|
||||
let interval = |iv: u64| {
|
||||
debug_fn(move |f| {
|
||||
fmt::from_fn(move |f| {
|
||||
let minutes = iv / 60;
|
||||
let seconds = iv % 60;
|
||||
if minutes == 0 && seconds == 0 {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ use {
|
|||
ifs::wl_output::BlendSpace,
|
||||
scale::Scale,
|
||||
tools::tool_client::{Handle, ToolClient, with_tool_client},
|
||||
utils::{
|
||||
debug_fn::debug_fn, errorfmt::ErrorFmt, ordered_float::F64, transform_ext::TransformExt,
|
||||
},
|
||||
utils::{errorfmt::ErrorFmt, ordered_float::F64, transform_ext::TransformExt},
|
||||
wire::{JayRandrId, jay_compositor, jay_randr},
|
||||
},
|
||||
clap::{
|
||||
|
|
@ -21,7 +19,7 @@ use {
|
|||
linearize::LinearizeExt,
|
||||
std::{
|
||||
cell::RefCell,
|
||||
fmt::{Display, Formatter},
|
||||
fmt::{self, Display, Formatter},
|
||||
rc::Rc,
|
||||
str::FromStr,
|
||||
time::Duration,
|
||||
|
|
@ -1067,7 +1065,7 @@ impl Randr {
|
|||
if let Some(p) = &o.native_gamut {
|
||||
println!(
|
||||
" native gamut:{}",
|
||||
debug_fn(|f| {
|
||||
fmt::from_fn(|f| {
|
||||
if o.use_native_gamut {
|
||||
f.write_str(" (used for default color space)")?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ use {
|
|||
crate::{
|
||||
cmm::{cmm_eotf::Eotf, cmm_primaries::Primaries},
|
||||
theme::Color,
|
||||
utils::{debug_fn::debug_fn, ordered_float::F64},
|
||||
utils::ordered_float::F64,
|
||||
},
|
||||
std::{
|
||||
fmt,
|
||||
fmt::{Debug, Formatter},
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
|
|
@ -52,7 +53,7 @@ impl<T, U> Debug for ColorMatrix<T, U> {
|
|||
}
|
||||
|
||||
fn format_matrix<'a>(m: &'a [[F64; 4]; 3]) -> impl Debug + use<'a> {
|
||||
debug_fn(move |f| {
|
||||
fmt::from_fn(move |f| {
|
||||
let iter = m
|
||||
.iter()
|
||||
.copied()
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ use {
|
|||
utils::{
|
||||
asyncevent::AsyncEvent,
|
||||
copyhashmap::CopyHashMap,
|
||||
debug_fn::debug_fn,
|
||||
errorfmt::ErrorFmt,
|
||||
numcell::NumCell,
|
||||
oserror::OsError,
|
||||
|
|
@ -83,6 +82,7 @@ use {
|
|||
regex::Regex,
|
||||
std::{
|
||||
cell::Cell,
|
||||
fmt,
|
||||
hash::Hash,
|
||||
ops::Deref,
|
||||
rc::{Rc, Weak},
|
||||
|
|
@ -273,7 +273,7 @@ impl ConfigProxyHandler {
|
|||
LogLevel::Debug => Level::Debug,
|
||||
LogLevel::Trace => Level::Trace,
|
||||
};
|
||||
let debug = debug_fn(|fmt| {
|
||||
let debug = fmt::from_fn(|fmt| {
|
||||
if let Some(file) = file {
|
||||
write!(fmt, "{}", file)?;
|
||||
if let Some(line) = line {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use {
|
|||
asyncevent::AsyncEvent,
|
||||
buffd::{EiMsgFormatter, EiMsgParser, EiMsgParserError, OutBufferSwapchain},
|
||||
clonecell::CloneCell,
|
||||
debug_fn::debug_fn,
|
||||
errorfmt::ErrorFmt,
|
||||
numcell::NumCell,
|
||||
pid_info::{PidInfo, get_pid_info, get_socket_creds},
|
||||
|
|
@ -27,7 +26,7 @@ use {
|
|||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
error::Error,
|
||||
fmt::Debug,
|
||||
fmt::{self, Debug},
|
||||
mem,
|
||||
ops::DerefMut,
|
||||
rc::Rc,
|
||||
|
|
@ -128,7 +127,7 @@ impl EiClients {
|
|||
log::info!(
|
||||
"Client {} connected{:?}",
|
||||
data.id,
|
||||
debug_fn(|fmt| {
|
||||
fmt::from_fn(|fmt| {
|
||||
if let Some(p) = &data.pid_info {
|
||||
write!(fmt, ", pid: {}, uid: {}, comm: {:?}", p.pid, p.uid, p.comm)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,15 @@ use {
|
|||
SPA_VIDEO_FORMAT_UNKNOWN, SPA_VIDEO_FORMAT_xBGR_210LE, SPA_VIDEO_FORMAT_xRGB_210LE,
|
||||
SpaVideoFormat,
|
||||
},
|
||||
utils::debug_fn::debug_fn,
|
||||
},
|
||||
ahash::AHashMap,
|
||||
ash::vk,
|
||||
jay_config::video::Format as ConfigFormat,
|
||||
once_cell::sync::Lazy,
|
||||
std::fmt::{Debug, Write},
|
||||
std::{
|
||||
fmt,
|
||||
fmt::{Debug, Write},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
|
@ -134,7 +136,7 @@ const fn fourcc_code(a: char, b: char, c: char, d: char) -> u32 {
|
|||
|
||||
#[expect(dead_code)]
|
||||
pub fn debug(fourcc: u32) -> impl Debug {
|
||||
debug_fn(move |fmt| {
|
||||
fmt::from_fn(move |fmt| {
|
||||
fmt.write_char(fourcc as u8 as char)?;
|
||||
fmt.write_char((fourcc >> 8) as u8 as char)?;
|
||||
fmt.write_char((fourcc >> 16) as u8 as char)?;
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ use {
|
|||
image::{QueueFamily, QueueState, VulkanImage, VulkanImageMemory},
|
||||
renderer::VulkanRenderer,
|
||||
},
|
||||
utils::on_drop::OnDrop,
|
||||
},
|
||||
ash::vk::{
|
||||
Extent3D, ImageAspectFlags, ImageCreateInfo, ImageLayout, ImageSubresourceRange,
|
||||
ImageTiling, ImageType, ImageViewCreateInfo, ImageViewType, SampleCountFlags, SharingMode,
|
||||
},
|
||||
gpu_alloc::UsageFlags,
|
||||
run_on_drop::on_drop,
|
||||
std::{cell::Cell, collections::hash_map::Entry, rc::Rc},
|
||||
};
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ impl VulkanRenderer {
|
|||
.usage(usage);
|
||||
let image = unsafe { self.device.device.create_image(&create_info, None) };
|
||||
let image = image.map_err(VulkanError::CreateImage)?;
|
||||
let destroy_image = OnDrop(|| unsafe { self.device.device.destroy_image(image, None) });
|
||||
let destroy_image = on_drop(|| unsafe { self.device.device.destroy_image(image, None) });
|
||||
let memory_requirements =
|
||||
unsafe { self.device.device.get_image_memory_requirements(image) };
|
||||
let allocation =
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use {
|
|||
device::VulkanDevice, format::VulkanFormat, renderer::image_barrier,
|
||||
staging::VulkanStagingBuffer,
|
||||
},
|
||||
utils::{errorfmt::ErrorFmt, on_drop::OnDrop},
|
||||
utils::errorfmt::ErrorFmt,
|
||||
video::{
|
||||
Modifier,
|
||||
dmabuf::{DmaBuf, DmaBufIds, DmaBufPlane, PlaneVec},
|
||||
|
|
@ -33,6 +33,7 @@ use {
|
|||
PipelineStageFlags2, QUEUE_FAMILY_FOREIGN_EXT, SampleCountFlags, SharingMode, SubmitInfo2,
|
||||
SubresourceLayout,
|
||||
},
|
||||
run_on_drop::on_drop,
|
||||
std::{rc::Rc, slice},
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
|
|
@ -140,7 +141,7 @@ impl VulkanBoAllocator {
|
|||
let res = unsafe { data.device.device.create_image(&create_info, None) };
|
||||
res.map_err(VulkanError::CreateImage)?
|
||||
};
|
||||
let destroy_image = OnDrop(|| unsafe { data.device.device.destroy_image(image, None) });
|
||||
let destroy_image = on_drop(|| unsafe { data.device.device.destroy_image(image, None) });
|
||||
let modifier = {
|
||||
let mut props = ImageDrmFormatModifierPropertiesEXT::default();
|
||||
unsafe {
|
||||
|
|
@ -187,7 +188,7 @@ impl VulkanBoAllocator {
|
|||
};
|
||||
memory.map_err(VulkanError::AllocateMemory)?
|
||||
};
|
||||
let destroy_memory = OnDrop(|| unsafe { data.device.device.free_memory(memory, None) });
|
||||
let destroy_memory = on_drop(|| unsafe { data.device.device.free_memory(memory, None) });
|
||||
unsafe {
|
||||
data.device
|
||||
.device
|
||||
|
|
@ -326,7 +327,7 @@ impl VulkanBoAllocator {
|
|||
let res = unsafe { data.device.device.create_image(&create_info, None) };
|
||||
res.map_err(VulkanError::CreateImage)?
|
||||
};
|
||||
let destroy_image = OnDrop(|| unsafe { data.device.device.destroy_image(image, None) });
|
||||
let destroy_image = on_drop(|| unsafe { data.device.device.destroy_image(image, None) });
|
||||
let num_device_memories = match disjoint {
|
||||
true => dmabuf.planes.len(),
|
||||
false => 1,
|
||||
|
|
@ -397,7 +398,7 @@ impl VulkanBoAllocator {
|
|||
let device_memory = device_memory.map_err(VulkanError::AllocateMemory)?;
|
||||
fd.unwrap();
|
||||
device_memories.push(device_memory);
|
||||
free_device_memories.push(OnDrop(move || unsafe {
|
||||
free_device_memories.push(on_drop(move || unsafe {
|
||||
data.device.device.free_memory(device_memory, None)
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
use {
|
||||
crate::{
|
||||
gfx_apis::vulkan::{
|
||||
VulkanError,
|
||||
allocator::{VulkanAllocation, VulkanAllocator},
|
||||
device::VulkanDevice,
|
||||
},
|
||||
utils::on_drop::OnDrop,
|
||||
crate::gfx_apis::vulkan::{
|
||||
VulkanError,
|
||||
allocator::{VulkanAllocation, VulkanAllocator},
|
||||
device::VulkanDevice,
|
||||
},
|
||||
ash::vk::{
|
||||
Buffer, BufferCreateInfo, BufferDeviceAddressInfo, BufferUsageFlags, DeviceAddress,
|
||||
DeviceSize,
|
||||
},
|
||||
gpu_alloc::UsageFlags,
|
||||
run_on_drop::on_drop,
|
||||
std::{cell::RefCell, mem::ManuallyDrop, ops::Deref, rc::Rc},
|
||||
uapi::Packed,
|
||||
};
|
||||
|
|
@ -119,7 +117,7 @@ impl VulkanBufferCache {
|
|||
.map_err(VulkanError::CreateBuffer)?
|
||||
}
|
||||
};
|
||||
let destroy_buffer = OnDrop(|| unsafe { self.device.device.destroy_buffer(buffer, None) });
|
||||
let destroy_buffer = on_drop(|| unsafe { self.device.device.destroy_buffer(buffer, None) });
|
||||
let mut memory_requirements =
|
||||
unsafe { self.device.device.get_buffer_memory_requirements(buffer) };
|
||||
memory_requirements.alignment = memory_requirements.alignment.max(self.min_alignment);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use {
|
|||
map_extension_properties,
|
||||
},
|
||||
},
|
||||
utils::{bitflags::BitflagsExt, on_drop::OnDrop},
|
||||
utils::bitflags::BitflagsExt,
|
||||
video::{
|
||||
dmabuf::DmaBufIds,
|
||||
drm::{Drm, sync_obj::SyncObjCtx},
|
||||
|
|
@ -45,6 +45,7 @@ use {
|
|||
},
|
||||
},
|
||||
isnt::std_1::collections::IsntHashMapExt,
|
||||
run_on_drop::on_drop,
|
||||
std::{
|
||||
cell::Cell,
|
||||
ffi::{CStr, CString},
|
||||
|
|
@ -447,7 +448,7 @@ impl VulkanInstance {
|
|||
Ok(d) => d,
|
||||
Err(e) => return Err(VulkanError::CreateDevice(e)),
|
||||
};
|
||||
let destroy_device = OnDrop(|| unsafe { device.destroy_device(None) });
|
||||
let destroy_device = on_drop(|| unsafe { device.destroy_device(None) });
|
||||
let blend_limits = self.load_blend_format_limits(phy_dev)?;
|
||||
let formats = self.load_formats(phy_dev)?;
|
||||
let supports_xrgb8888 = formats
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use {
|
|||
format::Format,
|
||||
gfx_api::GfxBuffer,
|
||||
gfx_apis::vulkan::{VulkanError, device::VulkanDevice},
|
||||
utils::on_drop::OnDrop,
|
||||
},
|
||||
ash::{
|
||||
Device,
|
||||
|
|
@ -13,6 +12,7 @@ use {
|
|||
MemoryDedicatedAllocateInfo, MemoryFdPropertiesKHR, MemoryPropertyFlags,
|
||||
},
|
||||
},
|
||||
run_on_drop::on_drop,
|
||||
std::{any::Any, rc::Rc},
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
|
|
@ -61,7 +61,7 @@ impl VulkanDevice {
|
|||
.map_err(VulkanError::CreateBuffer)?
|
||||
}
|
||||
};
|
||||
let destroy_buffer = OnDrop(|| unsafe { self.device.destroy_buffer(buffer, None) });
|
||||
let destroy_buffer = on_drop(|| unsafe { self.device.destroy_buffer(buffer, None) });
|
||||
let requirements = unsafe { self.device.get_buffer_memory_requirements(buffer) };
|
||||
let memory_type = self.find_memory_type(
|
||||
MemoryPropertyFlags::HOST_VISIBLE,
|
||||
|
|
@ -89,7 +89,7 @@ impl VulkanDevice {
|
|||
}
|
||||
};
|
||||
fd.unwrap();
|
||||
let free_memory = OnDrop(|| unsafe { self.device.free_memory(memory, None) });
|
||||
let free_memory = on_drop(|| unsafe { self.device.free_memory(memory, None) });
|
||||
unsafe {
|
||||
self.device
|
||||
.bind_buffer_memory(buffer, memory, 0)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use {
|
|||
},
|
||||
rect::Region,
|
||||
theme::Color,
|
||||
utils::on_drop::OnDrop,
|
||||
video::dmabuf::{DmaBuf, PlaneVec},
|
||||
},
|
||||
ash::vk::{
|
||||
|
|
@ -31,6 +30,7 @@ use {
|
|||
SubresourceLayout,
|
||||
},
|
||||
gpu_alloc::UsageFlags,
|
||||
run_on_drop::on_drop,
|
||||
std::{
|
||||
cell::Cell,
|
||||
fmt::{Debug, Formatter},
|
||||
|
|
@ -349,7 +349,7 @@ impl VulkanDmaBufImageTemplate {
|
|||
let image = unsafe { device.device.create_image(&create_info, None) };
|
||||
image.map_err(VulkanError::CreateImage)?
|
||||
};
|
||||
let destroy_image = OnDrop(|| unsafe { device.device.destroy_image(image, None) });
|
||||
let destroy_image = on_drop(|| unsafe { device.device.destroy_image(image, None) });
|
||||
let num_device_memories = match self.disjoint {
|
||||
true => self.dmabuf.planes.len(),
|
||||
false => 1,
|
||||
|
|
@ -419,7 +419,7 @@ impl VulkanDmaBufImageTemplate {
|
|||
let device_memory = device_memory.map_err(VulkanError::AllocateMemory)?;
|
||||
fd.unwrap();
|
||||
device_memories.push(device_memory);
|
||||
free_device_memories.push(OnDrop(move || unsafe {
|
||||
free_device_memories.push(on_drop(move || unsafe {
|
||||
device.device.free_memory(device_memory, None)
|
||||
}));
|
||||
}
|
||||
|
|
@ -440,7 +440,7 @@ impl VulkanDmaBufImageTemplate {
|
|||
if for_rendering && self.render_needs_bridge {
|
||||
let (bridge_image, allocation) = self.create_bridge()?;
|
||||
primary_image = bridge_image;
|
||||
destroy_bridge_image = Some(OnDrop(|| unsafe {
|
||||
destroy_bridge_image = Some(on_drop(|| unsafe {
|
||||
device.device.destroy_image(primary_image, None)
|
||||
}));
|
||||
bridge = Some(VulkanFramebufferBridge {
|
||||
|
|
@ -496,7 +496,7 @@ impl VulkanDmaBufImageTemplate {
|
|||
let image = unsafe { self.renderer.device.device.create_image(&create_info, None) };
|
||||
let image = image.map_err(VulkanError::CreateImage)?;
|
||||
let destroy_image =
|
||||
OnDrop(|| unsafe { self.renderer.device.device.destroy_image(image, None) });
|
||||
on_drop(|| unsafe { self.renderer.device.device.destroy_image(image, None) });
|
||||
let memory_requirements = unsafe {
|
||||
self.renderer
|
||||
.device
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
use {
|
||||
crate::{
|
||||
gfx_apis::vulkan::{VULKAN_VALIDATION, VulkanError},
|
||||
utils::on_drop::OnDrop,
|
||||
},
|
||||
crate::gfx_apis::vulkan::{VULKAN_VALIDATION, VulkanError},
|
||||
ahash::{AHashMap, AHashSet},
|
||||
ash::{
|
||||
Entry, Instance, LoadingError,
|
||||
|
|
@ -18,6 +15,7 @@ use {
|
|||
isnt::std_1::collections::IsntHashMapExt,
|
||||
log::Level,
|
||||
once_cell::sync::Lazy,
|
||||
run_on_drop::on_drop,
|
||||
std::{
|
||||
ffi::{CStr, CString, c_void},
|
||||
fmt::{Display, Formatter},
|
||||
|
|
@ -108,7 +106,7 @@ impl VulkanInstance {
|
|||
Ok(i) => i,
|
||||
Err(e) => return Err(VulkanError::CreateInstance(e)),
|
||||
};
|
||||
let destroy_instance = OnDrop(|| unsafe { instance.destroy_instance(None) });
|
||||
let destroy_instance = on_drop(|| unsafe { instance.destroy_instance(None) });
|
||||
let debug_utils = debug_utils::Instance::new(entry, &instance);
|
||||
let messenger = unsafe { debug_utils.create_debug_utils_messenger(&debug_info, None) };
|
||||
let messenger = match messenger {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
gfx_apis::vulkan::{
|
||||
VulkanError, descriptor::VulkanDescriptorSetLayout, device::VulkanDevice,
|
||||
shaders::VulkanShader,
|
||||
},
|
||||
utils::on_drop::OnDrop,
|
||||
crate::gfx_apis::vulkan::{
|
||||
VulkanError, descriptor::VulkanDescriptorSetLayout, device::VulkanDevice,
|
||||
shaders::VulkanShader,
|
||||
},
|
||||
arrayvec::ArrayVec,
|
||||
ash::{
|
||||
|
|
@ -21,6 +18,7 @@ use {
|
|||
SpecializationInfo, SpecializationMapEntry,
|
||||
},
|
||||
},
|
||||
run_on_drop::on_drop,
|
||||
std::{rc::Rc, slice},
|
||||
};
|
||||
|
||||
|
|
@ -77,7 +75,7 @@ impl VulkanDevice {
|
|||
layout.map_err(VulkanError::CreatePipelineLayout)?
|
||||
};
|
||||
let destroy_layout =
|
||||
OnDrop(|| unsafe { self.device.destroy_pipeline_layout(pipeline_layout, None) });
|
||||
on_drop(|| unsafe { self.device.destroy_pipeline_layout(pipeline_layout, None) });
|
||||
let mut frag_spec_data = ArrayVec::<_, { 5 * 4 }>::new();
|
||||
let mut frag_spec_entries = ArrayVec::<_, 5>::new();
|
||||
let mut frag_spec_entry = |data: &[u8]| {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use {
|
|||
transfer::{TransferType, VulkanShmImageAsyncData},
|
||||
},
|
||||
rect::Rect,
|
||||
utils::{errorfmt::ErrorFmt, on_drop::OnDrop},
|
||||
utils::errorfmt::ErrorFmt,
|
||||
},
|
||||
ash::vk::{
|
||||
AccessFlags2, Buffer, BufferImageCopy2, BufferMemoryBarrier2, CommandBufferBeginInfo,
|
||||
|
|
@ -26,6 +26,7 @@ use {
|
|||
},
|
||||
gpu_alloc::UsageFlags,
|
||||
isnt::std_1::primitive::IsntSliceExt,
|
||||
run_on_drop::on_drop,
|
||||
std::{cell::Cell, mem, ptr, rc::Rc, slice},
|
||||
};
|
||||
|
||||
|
|
@ -407,7 +408,7 @@ impl VulkanRenderer {
|
|||
.usage(usage);
|
||||
let image = unsafe { self.device.device.create_image(&create_info, None) };
|
||||
let image = image.map_err(VulkanError::CreateImage)?;
|
||||
let destroy_image = OnDrop(|| unsafe { self.device.device.destroy_image(image, None) });
|
||||
let destroy_image = on_drop(|| unsafe { self.device.device.destroy_image(image, None) });
|
||||
let memory_requirements =
|
||||
unsafe { self.device.device.get_image_memory_requirements(image) };
|
||||
let allocation =
|
||||
|
|
|
|||
|
|
@ -8,16 +8,14 @@ use {
|
|||
device::VulkanDevice,
|
||||
renderer::VulkanRenderer,
|
||||
},
|
||||
utils::{
|
||||
clonecell::CloneCell,
|
||||
on_drop::{OnDrop, OnDrop2},
|
||||
},
|
||||
utils::clonecell::CloneCell,
|
||||
},
|
||||
ash::{
|
||||
Device,
|
||||
vk::{Buffer, BufferCreateInfo, BufferUsageFlags},
|
||||
},
|
||||
gpu_alloc::UsageFlags,
|
||||
run_on_drop::on_drop,
|
||||
std::{any::Any, cell::Cell, rc::Rc},
|
||||
};
|
||||
|
||||
|
|
@ -55,7 +53,7 @@ impl VulkanDevice {
|
|||
) -> Result<VulkanStagingBuffer, VulkanError> {
|
||||
let (vk_usage, usage) = get_usage(upload, download, transient);
|
||||
let buffer = self.create_buffer(size, vk_usage)?;
|
||||
let destroy_buffer = OnDrop(|| unsafe { self.device.destroy_buffer(buffer, None) });
|
||||
let destroy_buffer = on_drop(|| unsafe { self.device.destroy_buffer(buffer, None) });
|
||||
let memory_requirements = unsafe { self.device.get_buffer_memory_requirements(buffer) };
|
||||
let allocation = allocator.alloc(&memory_requirements, usage, true)?;
|
||||
{
|
||||
|
|
@ -85,8 +83,7 @@ impl VulkanDevice {
|
|||
let buffer = self.create_buffer(shell.size, vk_usage)?;
|
||||
let memory_requirements = unsafe { self.device.get_buffer_memory_requirements(buffer) };
|
||||
let slf = self.clone();
|
||||
let destroy_buffer =
|
||||
OnDrop2::new(move || unsafe { slf.device.destroy_buffer(buffer, None) });
|
||||
let destroy_buffer = on_drop(move || unsafe { slf.device.destroy_buffer(buffer, None) });
|
||||
let slf = self.clone();
|
||||
let finish_allocation = move |res| {
|
||||
let allocation: VulkanAllocation = res?;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ use {
|
|||
event_listener::{EventListener, EventSource},
|
||||
linkedlist::{LinkedList, LinkedNode, NodeRef},
|
||||
numcell::NumCell,
|
||||
on_drop::OnDrop,
|
||||
rc_eq::{rc_eq, rc_weak_eq},
|
||||
smallmap::SmallMap,
|
||||
},
|
||||
|
|
@ -111,6 +110,7 @@ use {
|
|||
keyboard::syms::{KeySym, SYM_Escape},
|
||||
},
|
||||
kbvm::Keycode,
|
||||
run_on_drop::on_drop,
|
||||
smallvec::SmallVec,
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
|
|
@ -901,7 +901,7 @@ impl WlSeatGlobal {
|
|||
return;
|
||||
};
|
||||
self.focus_history_rotate.fetch_add(1);
|
||||
let _reset = OnDrop(|| {
|
||||
let _reset = on_drop(|| {
|
||||
self.focus_history_rotate.fetch_sub(1);
|
||||
});
|
||||
if !visible {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use {
|
|||
wl_surface::zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2,
|
||||
},
|
||||
keyboard::KeyboardState,
|
||||
utils::{clonecell::CloneCell, debug_fn::debug_fn, smallmap::SmallMap},
|
||||
utils::{clonecell::CloneCell, smallmap::SmallMap},
|
||||
wire::ZwpInputPopupSurfaceV2Id,
|
||||
},
|
||||
kbvm::{
|
||||
|
|
@ -24,7 +24,7 @@ use {
|
|||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
fmt::Write,
|
||||
fmt::{self, Write},
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
|
|
@ -154,7 +154,7 @@ impl UnicodeInput {
|
|||
let _ = write!(self.text, "U+{:x}", self.cp);
|
||||
self.cursor = self.text.len() as _;
|
||||
if let Some(char) = char::from_u32(self.cp) {
|
||||
let s = debug_fn(|f| {
|
||||
let s = fmt::from_fn(|f| {
|
||||
if char == '\n' {
|
||||
f.write_str("\\n")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ use {
|
|||
sys::{IORING_OP_READ, IORING_OP_WRITE, io_uring_sqe},
|
||||
},
|
||||
time::Time,
|
||||
utils::on_drop::OnDrop,
|
||||
},
|
||||
run_on_drop::on_drop,
|
||||
uapi::{Fd, c},
|
||||
};
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ impl IoUring {
|
|||
self.schedule_timeout_link(time);
|
||||
}
|
||||
}
|
||||
let panic = OnDrop(|| panic!("Operation cannot be cancelled from userspace"));
|
||||
let panic = on_drop(|| panic!("Operation cannot be cancelled from userspace"));
|
||||
cancel(id.id);
|
||||
let res = Ok(pr.await.map(|v| v as usize)).merge();
|
||||
panic.forget();
|
||||
|
|
|
|||
|
|
@ -31,9 +31,12 @@ use {
|
|||
SpaVideoTransferFunction,
|
||||
},
|
||||
},
|
||||
utils::{debug_fn::debug_fn, errorfmt::ErrorFmt},
|
||||
utils::errorfmt::ErrorFmt,
|
||||
},
|
||||
std::{
|
||||
fmt,
|
||||
fmt::{Debug, DebugList, Formatter, Write},
|
||||
},
|
||||
std::fmt::{Debug, DebugList, Formatter, Write},
|
||||
};
|
||||
|
||||
trait PwPodObjectDebugger: Sync {
|
||||
|
|
@ -62,7 +65,7 @@ where
|
|||
s.field("flags", &value.flags)
|
||||
.field(
|
||||
"pod",
|
||||
&debug_fn(|f| (self.debug_pod)(value.key, f, value.pod)),
|
||||
&fmt::from_fn(|f| (self.debug_pod)(value.key, f, value.pod)),
|
||||
)
|
||||
.finish()
|
||||
}
|
||||
|
|
@ -83,16 +86,16 @@ where
|
|||
.field("flags", &c.flags)
|
||||
.field(
|
||||
"elements",
|
||||
&debug_fn(|fmt| {
|
||||
&fmt::from_fn(|fmt| {
|
||||
array_body_debug(fmt, c.elements, |l, p| {
|
||||
match p.read_pod_body_packed(ty, c.elements.child_len) {
|
||||
Ok(p) => {
|
||||
l.entry(&debug_fn(|fmt| f(fmt, p)));
|
||||
l.entry(&fmt::from_fn(|fmt| f(fmt, p)));
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
let e = ErrorFmt(e);
|
||||
l.entry(&debug_fn(|fmt| {
|
||||
l.entry(&fmt::from_fn(|fmt| {
|
||||
write!(fmt, "Could not read choice element: {}", e)
|
||||
}));
|
||||
false
|
||||
|
|
@ -151,7 +154,7 @@ where
|
|||
}
|
||||
Err(e) => {
|
||||
let e = ErrorFmt(e);
|
||||
l.entry(&debug_fn(|f| write!(f, "Could not read id: {}", e)));
|
||||
l.entry(&fmt::from_fn(|f| write!(f, "Could not read id: {}", e)));
|
||||
false
|
||||
}
|
||||
})
|
||||
|
|
@ -334,18 +337,18 @@ impl<'a> Debug for PwPodObject<'a> {
|
|||
s.field("id", id);
|
||||
s.field(
|
||||
"props",
|
||||
&debug_fn(|f| {
|
||||
&fmt::from_fn(|f| {
|
||||
let mut l = f.debug_list();
|
||||
let mut parser = self.probs;
|
||||
while parser.len() > 0 {
|
||||
match parser.read_prop() {
|
||||
Ok(p) => match debugger {
|
||||
Some(d) => l.entry(&debug_fn(|fmt| d.debug_property(fmt, p))),
|
||||
Some(d) => l.entry(&fmt::from_fn(|fmt| d.debug_property(fmt, p))),
|
||||
_ => l.entry(&p),
|
||||
},
|
||||
Err(e) => {
|
||||
let e = ErrorFmt(e);
|
||||
l.entry(&debug_fn(|f| {
|
||||
l.entry(&fmt::from_fn(|f| {
|
||||
write!(f, "Could not read object property: {}", &e)
|
||||
}));
|
||||
break;
|
||||
|
|
@ -365,7 +368,7 @@ impl<'a> Debug for PwPodSequence<'a> {
|
|||
s.field("unit", &self.unit);
|
||||
s.field(
|
||||
"controls",
|
||||
&debug_fn(|f| {
|
||||
&fmt::from_fn(|f| {
|
||||
let mut l = f.debug_list();
|
||||
let mut parser = self.controls;
|
||||
while parser.len() > 0 {
|
||||
|
|
@ -373,7 +376,7 @@ impl<'a> Debug for PwPodSequence<'a> {
|
|||
Ok(c) => l.entry(&c),
|
||||
Err(e) => {
|
||||
let e = ErrorFmt(e);
|
||||
l.entry(&debug_fn(|f| {
|
||||
l.entry(&fmt::from_fn(|f| {
|
||||
write!(f, "Could not read control element: {}", &e)
|
||||
}));
|
||||
break;
|
||||
|
|
@ -404,7 +407,7 @@ impl<'a> Debug for PwPodStruct<'a> {
|
|||
let e = ErrorFmt(e);
|
||||
s.field(
|
||||
&field,
|
||||
&debug_fn(|f| write!(f, "Could not parse struct field: {}", &e)),
|
||||
&fmt::from_fn(|f| write!(f, "Could not parse struct field: {}", &e)),
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
|
@ -423,7 +426,7 @@ impl<'a> Debug for PwPodArray<'a> {
|
|||
Ok(e) => list.entry(&e),
|
||||
Err(e) => {
|
||||
let e = ErrorFmt(e);
|
||||
list.entry(&debug_fn(|f| {
|
||||
list.entry(&fmt::from_fn(|f| {
|
||||
write!(f, "Could not parse array element: {}", &e)
|
||||
}));
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@ use {
|
|||
state::{ConnectorData, OutputData, State},
|
||||
tree::{OutputNode, WsMoveConfig, move_ws_to_output},
|
||||
utils::{
|
||||
asyncevent::AsyncEvent, clonecell::CloneCell, debug_fn::debug_fn,
|
||||
hash_map_ext::HashMapExt, rc_eq::RcEq,
|
||||
asyncevent::AsyncEvent, clonecell::CloneCell, hash_map_ext::HashMapExt, rc_eq::RcEq,
|
||||
},
|
||||
},
|
||||
jay_config::video::Transform,
|
||||
std::{cell::Cell, collections::VecDeque, rc::Rc},
|
||||
std::{cell::Cell, collections::VecDeque, fmt, rc::Rc},
|
||||
};
|
||||
|
||||
pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
|
||||
|
|
@ -475,7 +474,7 @@ impl ConnectorHandler {
|
|||
}
|
||||
|
||||
fn create_description(info: &MonitorInfo) -> String {
|
||||
debug_fn(|f| {
|
||||
fmt::from_fn(|f| {
|
||||
let mut needs_space = false;
|
||||
let id = &info.output_id;
|
||||
for s in [&id.manufacturer, &id.model, &id.serial_number] {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ pub mod clone3;
|
|||
pub mod clonecell;
|
||||
pub mod compat;
|
||||
pub mod copyhashmap;
|
||||
pub mod debug_fn;
|
||||
pub mod double_buffered;
|
||||
pub mod double_click_state;
|
||||
pub mod errorfmt;
|
||||
|
|
@ -33,7 +32,6 @@ pub mod nonblock;
|
|||
pub mod num_cpus;
|
||||
pub mod numcell;
|
||||
pub mod on_change;
|
||||
pub mod on_drop;
|
||||
pub mod on_drop_event;
|
||||
pub mod once;
|
||||
pub mod opaque;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ use {
|
|||
crate::{
|
||||
forker::ForkerError,
|
||||
pr_caps::drop_all_pr_caps,
|
||||
utils::{errorfmt::ErrorFmt, on_drop::OnDrop, process_name::set_process_name},
|
||||
utils::{errorfmt::ErrorFmt, process_name::set_process_name},
|
||||
},
|
||||
run_on_drop::on_drop,
|
||||
std::{env, mem::MaybeUninit, process, slice, str::FromStr},
|
||||
uapi::{Msghdr, MsghdrMut, OwnedFd, c},
|
||||
};
|
||||
|
|
@ -47,7 +48,7 @@ pub fn double_fork() -> Result<Option<OwnedFd>, ForkerError> {
|
|||
match fork_with_pidfd(false)? {
|
||||
Forked::Parent { pid, .. } => {
|
||||
drop(c);
|
||||
let _wait = OnDrop(|| {
|
||||
let _wait = on_drop(|| {
|
||||
let _ = uapi::waitpid(pid, 0);
|
||||
});
|
||||
recv_pidfd(&p).map(Some)
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
pub fn debug_fn<F>(f: F) -> Printable<F>
|
||||
where
|
||||
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
|
||||
{
|
||||
Printable { f }
|
||||
}
|
||||
|
||||
pub struct Printable<F> {
|
||||
f: F,
|
||||
}
|
||||
|
||||
impl<F> Debug for Printable<F>
|
||||
where
|
||||
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
(self.f)(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Display for Printable<F>
|
||||
where
|
||||
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
(self.f)(f)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
use std::{mem, mem::ManuallyDrop};
|
||||
|
||||
pub struct OnDrop<F>(pub F)
|
||||
where
|
||||
F: FnMut() + Copy;
|
||||
|
||||
impl<F: FnMut() + Copy> OnDrop<F> {
|
||||
pub fn forget(self) {
|
||||
mem::forget(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FnMut() + Copy> Drop for OnDrop<F> {
|
||||
fn drop(&mut self) {
|
||||
(self.0)();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OnDrop2<F>
|
||||
where
|
||||
F: FnOnce(),
|
||||
{
|
||||
f: ManuallyDrop<F>,
|
||||
}
|
||||
|
||||
impl<F: FnOnce()> OnDrop2<F> {
|
||||
pub fn new(f: F) -> Self {
|
||||
Self {
|
||||
f: ManuallyDrop::new(f),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn forget(mut self) {
|
||||
unsafe {
|
||||
ManuallyDrop::drop(&mut self.f);
|
||||
}
|
||||
mem::forget(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FnOnce()> Drop for OnDrop2<F> {
|
||||
fn drop(&mut self) {
|
||||
let f = unsafe { ManuallyDrop::take(&mut self.f) };
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
|
@ -15,9 +15,7 @@ use {
|
|||
security_context_acceptor::AcceptorMetadata,
|
||||
state::State,
|
||||
user_session::import_environment,
|
||||
utils::{
|
||||
buf::Buf, errorfmt::ErrorFmt, line_logger::log_lines, on_drop::OnDrop, oserror::OsError,
|
||||
},
|
||||
utils::{buf::Buf, errorfmt::ErrorFmt, line_logger::log_lines, oserror::OsError},
|
||||
wire::WlSurfaceId,
|
||||
xcon::XconError,
|
||||
xwayland::{
|
||||
|
|
@ -26,6 +24,7 @@ use {
|
|||
},
|
||||
},
|
||||
bstr::ByteSlice,
|
||||
run_on_drop::on_drop,
|
||||
std::{num::ParseIntError, rc::Rc},
|
||||
thiserror::Error,
|
||||
uapi::{OwnedFd, c, pipe2},
|
||||
|
|
@ -190,7 +189,7 @@ async fn run(
|
|||
state.ring.readable(&Rc::new(dfdread)).await?;
|
||||
state.xwayland.queue.clear();
|
||||
state.xwayland.pidfd.set(Some(pidfd.clone()));
|
||||
let _remove_pidfd = OnDrop(|| {
|
||||
let _remove_pidfd = on_drop(|| {
|
||||
state.xwayland.pidfd.take();
|
||||
});
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue