Start fixing up gpui2

This commit is contained in:
Piotr Osiewicz 2024-01-02 00:04:51 +01:00
parent 86facbbe4a
commit 7d420edb84
3 changed files with 97 additions and 98 deletions

View file

@ -1896,7 +1896,6 @@ impl Into<Corners<Pixels>> for Pixels {
Div,
DivAssign,
PartialEq,
PartialOrd,
Serialize,
Deserialize,
)]
@ -2039,9 +2038,15 @@ impl Mul<Pixels> for Pixels {
impl Eq for Pixels {}
impl PartialOrd for Pixels {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.0.partial_cmp(&other.0)
}
}
impl Ord for Pixels {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.0.partial_cmp(&other.0).unwrap()
self.partial_cmp(other).unwrap()
}
}

View file

@ -174,7 +174,7 @@ impl MetalRenderer {
unit_vertices,
instances,
sprite_atlas,
core_video_texture_cache: CVMetalTextureCache::new(device.as_ptr()).unwrap(),
core_video_texture_cache: unsafe { CVMetalTextureCache::new(device.as_ptr()).unwrap() },
}
}
@ -849,8 +849,8 @@ impl MetalRenderer {
media::core_video::kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
);
let y_texture = self
.core_video_texture_cache
let y_texture = unsafe {
self.core_video_texture_cache
.create_texture_from_image(
surface.image_buffer.as_concrete_TypeRef(),
ptr::null(),
@ -859,9 +859,10 @@ impl MetalRenderer {
surface.image_buffer.plane_height(0),
0,
)
.unwrap();
let cb_cr_texture = self
.core_video_texture_cache
.unwrap()
};
let cb_cr_texture = unsafe {
self.core_video_texture_cache
.create_texture_from_image(
surface.image_buffer.as_concrete_TypeRef(),
ptr::null(),
@ -870,7 +871,8 @@ impl MetalRenderer {
surface.image_buffer.plane_height(1),
1,
)
.unwrap();
.unwrap()
};
align_offset(offset);
let next_offset = *offset + mem::size_of::<Surface>();

View file

@ -108,8 +108,7 @@ pub mod core_video {
impl_CFTypeDescription!(CVMetalTextureCache);
impl CVMetalTextureCache {
pub fn new(metal_device: *mut MTLDevice) -> Result<Self> {
unsafe {
pub unsafe fn new(metal_device: *mut MTLDevice) -> Result<Self> {
let mut this = ptr::null();
let result = CVMetalTextureCacheCreate(
kCFAllocatorDefault,
@ -124,9 +123,8 @@ pub mod core_video {
Err(anyhow!("could not create texture cache, code: {}", result))
}
}
}
pub fn create_texture_from_image(
pub unsafe fn create_texture_from_image(
&self,
source: CVImageBufferRef,
texture_attributes: CFDictionaryRef,
@ -135,7 +133,6 @@ pub mod core_video {
height: usize,
plane_index: usize,
) -> Result<CVMetalTexture> {
unsafe {
let mut this = ptr::null();
let result = CVMetalTextureCacheCreateTextureFromImage(
kCFAllocatorDefault,
@ -155,7 +152,6 @@ pub mod core_video {
}
}
}
}
#[link(name = "CoreVideo", kind = "framework")]
extern "C" {
@ -438,14 +434,13 @@ pub mod video_toolbox {
impl_CFTypeDescription!(VTCompressionSession);
impl VTCompressionSession {
pub fn new(
pub unsafe fn new(
width: usize,
height: usize,
codec: CMVideoCodecType,
callback: VTCompressionOutputCallback,
callback_data: *const c_void,
) -> Result<Self> {
unsafe {
let mut this = ptr::null();
let result = VTCompressionSessionCreate(
ptr::null(),
@ -469,15 +464,13 @@ pub mod video_toolbox {
))
}
}
}
pub fn encode_frame(
pub unsafe fn encode_frame(
&self,
buffer: CVImageBufferRef,
presentation_timestamp: CMTime,
duration: CMTime,
) -> Result<()> {
unsafe {
let result = VTCompressionSessionEncodeFrame(
self.as_concrete_TypeRef(),
buffer,
@ -494,7 +487,6 @@ pub mod video_toolbox {
}
}
}
}
type VTCompressionOutputCallback = Option<
unsafe extern "C" fn(