Start fixing up gpui2
This commit is contained in:
parent
86facbbe4a
commit
7d420edb84
3 changed files with 97 additions and 98 deletions
|
@ -1896,7 +1896,6 @@ impl Into<Corners<Pixels>> for Pixels {
|
||||||
Div,
|
Div,
|
||||||
DivAssign,
|
DivAssign,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
PartialOrd,
|
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
)]
|
)]
|
||||||
|
@ -2039,9 +2038,15 @@ impl Mul<Pixels> for Pixels {
|
||||||
|
|
||||||
impl Eq 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 {
|
impl Ord for Pixels {
|
||||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||||
self.0.partial_cmp(&other.0).unwrap()
|
self.partial_cmp(other).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ impl MetalRenderer {
|
||||||
unit_vertices,
|
unit_vertices,
|
||||||
instances,
|
instances,
|
||||||
sprite_atlas,
|
sprite_atlas,
|
||||||
core_video_texture_cache: CVMetalTextureCache::new(device.as_ptr()).unwrap(),
|
core_video_texture_cache: unsafe { CVMetalTextureCache::new(device.as_ptr()).unwrap() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -849,28 +849,30 @@ impl MetalRenderer {
|
||||||
media::core_video::kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
|
media::core_video::kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
|
||||||
);
|
);
|
||||||
|
|
||||||
let y_texture = self
|
let y_texture = unsafe {
|
||||||
.core_video_texture_cache
|
self.core_video_texture_cache
|
||||||
.create_texture_from_image(
|
.create_texture_from_image(
|
||||||
surface.image_buffer.as_concrete_TypeRef(),
|
surface.image_buffer.as_concrete_TypeRef(),
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
MTLPixelFormat::R8Unorm,
|
MTLPixelFormat::R8Unorm,
|
||||||
surface.image_buffer.plane_width(0),
|
surface.image_buffer.plane_width(0),
|
||||||
surface.image_buffer.plane_height(0),
|
surface.image_buffer.plane_height(0),
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap()
|
||||||
let cb_cr_texture = self
|
};
|
||||||
.core_video_texture_cache
|
let cb_cr_texture = unsafe {
|
||||||
.create_texture_from_image(
|
self.core_video_texture_cache
|
||||||
surface.image_buffer.as_concrete_TypeRef(),
|
.create_texture_from_image(
|
||||||
ptr::null(),
|
surface.image_buffer.as_concrete_TypeRef(),
|
||||||
MTLPixelFormat::RG8Unorm,
|
ptr::null(),
|
||||||
surface.image_buffer.plane_width(1),
|
MTLPixelFormat::RG8Unorm,
|
||||||
surface.image_buffer.plane_height(1),
|
surface.image_buffer.plane_width(1),
|
||||||
1,
|
surface.image_buffer.plane_height(1),
|
||||||
)
|
1,
|
||||||
.unwrap();
|
)
|
||||||
|
.unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
align_offset(offset);
|
align_offset(offset);
|
||||||
let next_offset = *offset + mem::size_of::<Surface>();
|
let next_offset = *offset + mem::size_of::<Surface>();
|
||||||
|
|
|
@ -108,25 +108,23 @@ pub mod core_video {
|
||||||
impl_CFTypeDescription!(CVMetalTextureCache);
|
impl_CFTypeDescription!(CVMetalTextureCache);
|
||||||
|
|
||||||
impl CVMetalTextureCache {
|
impl CVMetalTextureCache {
|
||||||
pub fn new(metal_device: *mut MTLDevice) -> Result<Self> {
|
pub unsafe fn new(metal_device: *mut MTLDevice) -> Result<Self> {
|
||||||
unsafe {
|
let mut this = ptr::null();
|
||||||
let mut this = ptr::null();
|
let result = CVMetalTextureCacheCreate(
|
||||||
let result = CVMetalTextureCacheCreate(
|
kCFAllocatorDefault,
|
||||||
kCFAllocatorDefault,
|
ptr::null(),
|
||||||
ptr::null(),
|
metal_device,
|
||||||
metal_device,
|
ptr::null(),
|
||||||
ptr::null(),
|
&mut this,
|
||||||
&mut this,
|
);
|
||||||
);
|
if result == kCVReturnSuccess {
|
||||||
if result == kCVReturnSuccess {
|
Ok(CVMetalTextureCache::wrap_under_create_rule(this))
|
||||||
Ok(CVMetalTextureCache::wrap_under_create_rule(this))
|
} else {
|
||||||
} else {
|
Err(anyhow!("could not create texture cache, code: {}", result))
|
||||||
Err(anyhow!("could not create texture cache, code: {}", result))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_texture_from_image(
|
pub unsafe fn create_texture_from_image(
|
||||||
&self,
|
&self,
|
||||||
source: CVImageBufferRef,
|
source: CVImageBufferRef,
|
||||||
texture_attributes: CFDictionaryRef,
|
texture_attributes: CFDictionaryRef,
|
||||||
|
@ -135,24 +133,22 @@ pub mod core_video {
|
||||||
height: usize,
|
height: usize,
|
||||||
plane_index: usize,
|
plane_index: usize,
|
||||||
) -> Result<CVMetalTexture> {
|
) -> Result<CVMetalTexture> {
|
||||||
unsafe {
|
let mut this = ptr::null();
|
||||||
let mut this = ptr::null();
|
let result = CVMetalTextureCacheCreateTextureFromImage(
|
||||||
let result = CVMetalTextureCacheCreateTextureFromImage(
|
kCFAllocatorDefault,
|
||||||
kCFAllocatorDefault,
|
self.as_concrete_TypeRef(),
|
||||||
self.as_concrete_TypeRef(),
|
source,
|
||||||
source,
|
texture_attributes,
|
||||||
texture_attributes,
|
pixel_format,
|
||||||
pixel_format,
|
width,
|
||||||
width,
|
height,
|
||||||
height,
|
plane_index,
|
||||||
plane_index,
|
&mut this,
|
||||||
&mut this,
|
);
|
||||||
);
|
if result == kCVReturnSuccess {
|
||||||
if result == kCVReturnSuccess {
|
Ok(CVMetalTexture::wrap_under_create_rule(this))
|
||||||
Ok(CVMetalTexture::wrap_under_create_rule(this))
|
} else {
|
||||||
} else {
|
Err(anyhow!("could not create texture, code: {}", result))
|
||||||
Err(anyhow!("could not create texture, code: {}", result))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,60 +434,56 @@ pub mod video_toolbox {
|
||||||
impl_CFTypeDescription!(VTCompressionSession);
|
impl_CFTypeDescription!(VTCompressionSession);
|
||||||
|
|
||||||
impl VTCompressionSession {
|
impl VTCompressionSession {
|
||||||
pub fn new(
|
pub unsafe fn new(
|
||||||
width: usize,
|
width: usize,
|
||||||
height: usize,
|
height: usize,
|
||||||
codec: CMVideoCodecType,
|
codec: CMVideoCodecType,
|
||||||
callback: VTCompressionOutputCallback,
|
callback: VTCompressionOutputCallback,
|
||||||
callback_data: *const c_void,
|
callback_data: *const c_void,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
unsafe {
|
let mut this = ptr::null();
|
||||||
let mut this = ptr::null();
|
let result = VTCompressionSessionCreate(
|
||||||
let result = VTCompressionSessionCreate(
|
ptr::null(),
|
||||||
ptr::null(),
|
width as i32,
|
||||||
width as i32,
|
height as i32,
|
||||||
height as i32,
|
codec,
|
||||||
codec,
|
ptr::null(),
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
ptr::null(),
|
callback,
|
||||||
callback,
|
callback_data,
|
||||||
callback_data,
|
&mut this,
|
||||||
&mut this,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
Ok(Self::wrap_under_create_rule(this))
|
Ok(Self::wrap_under_create_rule(this))
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!(
|
Err(anyhow!(
|
||||||
"error creating compression session, code {}",
|
"error creating compression session, code {}",
|
||||||
result
|
result
|
||||||
))
|
))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_frame(
|
pub unsafe fn encode_frame(
|
||||||
&self,
|
&self,
|
||||||
buffer: CVImageBufferRef,
|
buffer: CVImageBufferRef,
|
||||||
presentation_timestamp: CMTime,
|
presentation_timestamp: CMTime,
|
||||||
duration: CMTime,
|
duration: CMTime,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
unsafe {
|
let result = VTCompressionSessionEncodeFrame(
|
||||||
let result = VTCompressionSessionEncodeFrame(
|
self.as_concrete_TypeRef(),
|
||||||
self.as_concrete_TypeRef(),
|
buffer,
|
||||||
buffer,
|
presentation_timestamp,
|
||||||
presentation_timestamp,
|
duration,
|
||||||
duration,
|
ptr::null(),
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
ptr::null(),
|
ptr::null_mut(),
|
||||||
ptr::null_mut(),
|
);
|
||||||
);
|
if result == 0 {
|
||||||
if result == 0 {
|
Ok(())
|
||||||
Ok(())
|
} else {
|
||||||
} else {
|
Err(anyhow!("error encoding frame, code {}", result))
|
||||||
Err(anyhow!("error encoding frame, code {}", result))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue