From 4e1d5a2915de71af7d9ba45b3bf63cf9479ca865 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: 2025年10月16日 01:21:25 +0200 Subject: [PATCH 1/6] Wip --- desktop/src/cef/context/builder.rs | 2 +- desktop/src/cef/internal/display_handler.rs | 2 +- desktop/src/cef/texture_import/iosurface.rs | 33 +++++++++------------ 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/desktop/src/cef/context/builder.rs b/desktop/src/cef/context/builder.rs index a5bbc93c8a..e1a39f1203 100644 --- a/desktop/src/cef/context/builder.rs +++ b/desktop/src/cef/context/builder.rs @@ -27,7 +27,7 @@ impl CefContextBuilder { pub(crate) fn new() -> Self { #[cfg(target_os = "macos")] let _loader = { - let loader = library_loader::LibraryLoader::new(&std::env::current_exe().unwrap(), false); + let loader = cef::library_loader::LibraryLoader::new(&std::env::current_exe().unwrap(), false); assert!(loader.load()); loader }; diff --git a/desktop/src/cef/internal/display_handler.rs b/desktop/src/cef/internal/display_handler.rs index 4e075dc39a..2ffd712fca 100644 --- a/desktop/src/cef/internal/display_handler.rs +++ b/desktop/src/cef/internal/display_handler.rs @@ -20,7 +20,7 @@ impl DisplayHandlerImpl { } impl ImplDisplayHandler for DisplayHandlerImpl { - fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, _cursor: cef::CursorHandle, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::cursorinfo>) -> ::std::os::raw::c_int { + fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::cursorinfo>) -> ::std::os::raw::c_int { let cursor = match cursor_type.into() { CT_POINTER => CursorIcon::Default, CT_CROSS => CursorIcon::Crosshair, diff --git a/desktop/src/cef/texture_import/iosurface.rs b/desktop/src/cef/texture_import/iosurface.rs index 65b4fdcc2a..40b6ab1c12 100644 --- a/desktop/src/cef/texture_import/iosurface.rs +++ b/desktop/src/cef/texture_import/iosurface.rs @@ -19,7 +19,7 @@ pub struct IOSurfaceImporter { impl TextureImporter for IOSurfaceImporter { fn new(info: &AcceleratedPaintInfo) -> Self { Self { - handle: info.shared_texture_handle, + handle: info.shared_texture_io_surface, format: *info.format.as_ref(), width: info.extra.coded_size.width as u32, height: info.extra.coded_size.height as u32, @@ -73,22 +73,15 @@ impl IOSurfaceImporter { // Wrap Metal texture in wgpu-hal texture let hal_texture = ::Device::texture_from_raw( metal_texture, - &wgpu::hal::TextureDescriptor { - label: Some("CEF IOSurface Texture"), - size: wgpu::Extent3d { - width: self.width, - height: self.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: format::cef_to_wgpu(self.format)?, - usage: wgpu::hal::TextureUses::RESOURCE, - memory_flags: wgpu::hal::MemoryFlags::empty(), - view_formats: vec![], + format::cef_to_wgpu(self.format)?, + objc2_metal::MTLTextureType::Type2D, + self.width, + self.height, + wgpu::hal::CopyExtent { + width: self.width, + height: self.height, + depth: 1, }, - None, // drop_callback ); Ok(hal_texture) @@ -127,8 +120,8 @@ impl IOSurfaceImporter { // Convert handle to IOSurface let iosurface = unsafe { - let cf_type = CFType::wrap_under_get_rule(self.handle as IOSurfaceRef); - IOSurface::from(cf_type) + let iosurface_ref = std::mem::transmute::<*mut c_void, IOSurfaceRef>(self.handle); + IOSurface::from_ptr(iosurface_ref) }; // Get the Metal device from wgpu-hal @@ -149,7 +142,9 @@ impl IOSurfaceImporter { texture_descriptor.setUsage(MTLTextureUsage::ShaderRead); // Create Metal texture from IOSurface - let metal_texture = unsafe { metal_device.newTextureWithDescriptor_iosurface_plane(&texture_descriptor, &iosurface, 0) }; + let metal_texture = unsafe { + metal_device.lock().newTextureWithDescriptor_iosurface_plane(&texture_descriptor, &iosurface, 0) + }; let Some(metal_texture) = metal_texture else { return Err(TextureImportError::PlatformError { From 72d8219f31ee4ba37c42da2f612f37f6de245403 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: 2025年10月16日 01:25:30 +0200 Subject: [PATCH 2/6] More testing --- desktop/src/cef/internal/display_handler.rs | 2 +- desktop/src/cef/texture_import/iosurface.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/desktop/src/cef/internal/display_handler.rs b/desktop/src/cef/internal/display_handler.rs index 2ffd712fca..6a0dda96bd 100644 --- a/desktop/src/cef/internal/display_handler.rs +++ b/desktop/src/cef/internal/display_handler.rs @@ -20,7 +20,7 @@ impl DisplayHandlerImpl { } impl ImplDisplayHandler for DisplayHandlerImpl { - fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::cursorinfo>) -> ::std::os::raw::c_int { + fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, _cursor: *mut u8, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::cursorinfo>) -> ::std::os::raw::c_int { let cursor = match cursor_type.into() { CT_POINTER => CursorIcon::Default, CT_CROSS => CursorIcon::Crosshair, diff --git a/desktop/src/cef/texture_import/iosurface.rs b/desktop/src/cef/texture_import/iosurface.rs index 40b6ab1c12..a1faa489e6 100644 --- a/desktop/src/cef/texture_import/iosurface.rs +++ b/desktop/src/cef/texture_import/iosurface.rs @@ -72,9 +72,9 @@ impl IOSurfaceImporter { // Wrap Metal texture in wgpu-hal texture let hal_texture = ::Device::texture_from_raw( - metal_texture, + metal_texture.as_ptr() as *mut metal::MTLTexture, format::cef_to_wgpu(self.format)?, - objc2_metal::MTLTextureType::Type2D, + metal::MTLTextureType::D2, self.width, self.height, wgpu::hal::CopyExtent { @@ -121,7 +121,7 @@ impl IOSurfaceImporter { // Convert handle to IOSurface let iosurface = unsafe { let iosurface_ref = std::mem::transmute::<*mut c_void, IOSurfaceRef>(self.handle); - IOSurface::from_ptr(iosurface_ref) + IOSurface::from(iosurface_ref) }; // Get the Metal device from wgpu-hal @@ -143,7 +143,8 @@ impl IOSurfaceImporter { // Create Metal texture from IOSurface let metal_texture = unsafe { - metal_device.lock().newTextureWithDescriptor_iosurface_plane(&texture_descriptor, &iosurface, 0) + let device = metal_device.lock(); + device.newTextureWithDescriptor_iosurface_plane(&texture_descriptor, &iosurface, 0) }; let Some(metal_texture) = metal_texture else { From a39382bdcecc7e274ca21a8ddd2031515a88757c Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: 2025年10月16日 01:28:57 +0200 Subject: [PATCH 3/6] Remove unused imports --- desktop/src/cef/texture_import/iosurface.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/desktop/src/cef/texture_import/iosurface.rs b/desktop/src/cef/texture_import/iosurface.rs index a1faa489e6..53249b8546 100644 --- a/desktop/src/cef/texture_import/iosurface.rs +++ b/desktop/src/cef/texture_import/iosurface.rs @@ -3,9 +3,8 @@ use super::common::{format, texture}; use super::{TextureImportError, TextureImportResult, TextureImporter}; use cef::{AcceleratedPaintInfo, sys::cef_color_type_t}; -use core_foundation::base::{CFType, TCFType}; use objc2_io_surface::{IOSurface, IOSurfaceRef}; -use objc2_metal::{MTLDevice, MTLPixelFormat, MTLTexture, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage}; +use objc2_metal::{MTLPixelFormat, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage}; use std::os::raw::c_void; use wgpu::hal::api; @@ -58,7 +57,7 @@ impl TextureImporter for IOSurfaceImporter { impl IOSurfaceImporter { fn import_via_metal(&self, device: &wgpu::Device) -> TextureImportResult { // Get wgpu's Metal device - use wgpu::{hal::Api, wgc::api::Metal}; + use wgpu::wgc::api::Metal; let hal_texture = unsafe { device.as_hal::(|device| { let Some(device) = device else { @@ -72,9 +71,9 @@ impl IOSurfaceImporter { // Wrap Metal texture in wgpu-hal texture let hal_texture = ::Device::texture_from_raw( - metal_texture.as_ptr() as *mut metal::MTLTexture, + metal_texture, format::cef_to_wgpu(self.format)?, - metal::MTLTextureType::D2, + MTLTextureType(2), // MTLTextureType2D self.width, self.height, wgpu::hal::CopyExtent { @@ -120,8 +119,7 @@ impl IOSurfaceImporter { // Convert handle to IOSurface let iosurface = unsafe { - let iosurface_ref = std::mem::transmute::<*mut c_void, IOSurfaceRef>(self.handle); - IOSurface::from(iosurface_ref) + IOSurface::from_ptr(std::mem::transmute::<*mut c_void, *mut objc2::runtime::AnyObject>(self.handle)) }; // Get the Metal device from wgpu-hal @@ -144,7 +142,7 @@ impl IOSurfaceImporter { // Create Metal texture from IOSurface let metal_texture = unsafe { let device = metal_device.lock(); - device.newTextureWithDescriptor_iosurface_plane(&texture_descriptor, &iosurface, 0) + objc2_metal::MTLDevice::newTextureWithDescriptor_iosurface_plane(&*device, &texture_descriptor, &iosurface, 0) }; let Some(metal_texture) = metal_texture else { From 3eca203195f6e5759c563624ced4cabd28a023a5 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: 2025年10月16日 12:06:26 +0200 Subject: [PATCH 4/6] Change dependencies --- desktop/Cargo.toml | 8 +- desktop/src/cef/texture_import/iosurface.rs | 85 ++++++++++++--------- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index e8e860fb76..fb1213be51 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -18,7 +18,7 @@ gpu = ["graphite-desktop-wrapper/gpu"] accelerated_paint = ["accelerated_paint_dmabuf", "accelerated_paint_d3d11", "accelerated_paint_iosurface"] accelerated_paint_dmabuf = ["libc", "ash"] accelerated_paint_d3d11 = ["windows", "ash"] -accelerated_paint_iosurface = ["objc2-io-surface", "objc2-metal", "core-foundation"] +accelerated_paint_iosurface = ["metal", "objc", "core-foundation"] [dependencies] # Local dependencies @@ -63,7 +63,13 @@ windows = { version = "0.58.0", features = [ "Win32_UI_HiDpi", ], optional = true } + # macOS-specific dependencies +[target.'cfg(target_os = "macos")'.dependencies] +metal = { version = "0.32.0", optional = true } +objc = { version = "0.2", optional = true } +core-foundation = { version = "0.10", optional = true } + [target.'cfg(target_os = "macos")'.dependencies] objc2-io-surface = { version = "0.3", optional = true } objc2-metal = { version = "0.3", optional = true } diff --git a/desktop/src/cef/texture_import/iosurface.rs b/desktop/src/cef/texture_import/iosurface.rs index 53249b8546..90d8be7e23 100644 --- a/desktop/src/cef/texture_import/iosurface.rs +++ b/desktop/src/cef/texture_import/iosurface.rs @@ -3,11 +3,14 @@ use super::common::{format, texture}; use super::{TextureImportError, TextureImportResult, TextureImporter}; use cef::{AcceleratedPaintInfo, sys::cef_color_type_t}; -use objc2_io_surface::{IOSurface, IOSurfaceRef}; -use objc2_metal::{MTLPixelFormat, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage}; +use core_foundation::base::TCFType; +use metal::{Device, MTLPixelFormat, MTLResourceOptions, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage, Texture}; use std::os::raw::c_void; use wgpu::hal::api; +// IOSurface type from Core Foundation +type IOSurfaceRef = *mut c_void; + pub struct IOSurfaceImporter { pub handle: *mut c_void, pub format: cef_color_type_t, @@ -59,28 +62,28 @@ impl IOSurfaceImporter { // Get wgpu's Metal device use wgpu::wgc::api::Metal; let hal_texture = unsafe { - device.as_hal::(|device| { - let Some(device) = device else { + device.as_hal::(|hal_device| { + let Some(hal_device) = hal_device else { return Err(TextureImportError::HardwareUnavailable { reason: "Device is not using Metal backend".to_string(), }); }; // Import IOSurface handle into Metal texture - let metal_texture = self.import_iosurface_to_metal(device)?; + let metal_texture = self.import_iosurface_to_metal_texture(hal_device)?; // Wrap Metal texture in wgpu-hal texture let hal_texture = ::Device::texture_from_raw( metal_texture, format::cef_to_wgpu(self.format)?, - MTLTextureType(2), // MTLTextureType2D - self.width, - self.height, - wgpu::hal::CopyExtent { + wgpu::TextureDimension::D2, + wgpu::Extent3d { width: self.width, height: self.height, - depth: 1, + depth_or_array_layers: 1, }, + 1, // mip_level_count + 1, // sample_count ); Ok(hal_texture) @@ -111,17 +114,12 @@ impl IOSurfaceImporter { Ok(texture) } - fn import_iosurface_to_metal(&self, hal_device: &::Device) -> Result<::Texture, TextureImportError> { + fn import_iosurface_to_metal_texture(&self, hal_device: &::Device) -> Result { // Validate dimensions if self.width == 0 || self.height == 0 { return Err(TextureImportError::InvalidHandle("Invalid IOSurface texture dimensions".to_string())); } - // Convert handle to IOSurface - let iosurface = unsafe { - IOSurface::from_ptr(std::mem::transmute::<*mut c_void, *mut objc2::runtime::AnyObject>(self.handle)) - }; - // Get the Metal device from wgpu-hal let metal_device = hal_device.raw_device(); @@ -129,30 +127,41 @@ impl IOSurfaceImporter { let metal_format = self.cef_to_metal_format(self.format)?; // Create Metal texture descriptor - let texture_descriptor = MTLTextureDescriptor::new(); - texture_descriptor.setTextureType(MTLTextureType::Type2D); - texture_descriptor.setPixelFormat(metal_format); - texture_descriptor.setWidth(self.width as usize); - texture_descriptor.setHeight(self.height as usize); - texture_descriptor.setDepth(1); - texture_descriptor.setMipmapLevelCount(1); - texture_descriptor.setSampleCount(1); - texture_descriptor.setUsage(MTLTextureUsage::ShaderRead); - - // Create Metal texture from IOSurface - let metal_texture = unsafe { - let device = metal_device.lock(); - objc2_metal::MTLDevice::newTextureWithDescriptor_iosurface_plane(&*device, &texture_descriptor, &iosurface, 0) - }; + let descriptor = MTLTextureDescriptor::new(); + descriptor.set_texture_type(MTLTextureType::D2); + descriptor.set_pixel_format(metal_format); + descriptor.set_width(self.width as u64); + descriptor.set_height(self.height as u64); + descriptor.set_depth(1); + descriptor.set_mipmap_level_count(1); + descriptor.set_sample_count(1); + descriptor.set_array_length(1); + descriptor.set_resource_options(MTLResourceOptions::StorageModeShared); + descriptor.set_usage(MTLTextureUsage::ShaderRead); + + // Create Metal texture from IOSurface using Objective-C runtime + unsafe { + let iosurface = self.handle as IOSurfaceRef; - let Some(metal_texture) = metal_texture else { - return Err(TextureImportError::PlatformError { - message: "Failed to create Metal texture from IOSurface".to_string(), - }); - }; + // Call newTextureWithDescriptor:iosurface:plane: on the Metal device + // This uses objc runtime to call the Metal API + use objc::runtime::Object; + use objc::{msg_send, sel, sel_impl}; + + let device_ptr = metal_device.lock().as_ptr() as *mut Object; + let descriptor_ptr = descriptor.as_ptr() as *mut Object; + + let metal_texture: *mut Object = msg_send![device_ptr, newTextureWithDescriptor:descriptor_ptr iosurface:iosurface plane:0u64]; - tracing::trace!("Successfully created Metal texture from IOSurface"); - Ok(metal_texture) + if metal_texture.is_null() { + return Err(TextureImportError::PlatformError { + message: "Failed to create Metal texture from IOSurface".to_string(), + }); + } + + // Wrap in metal::Texture + Ok(Texture::from_ptr(metal_texture)) + } } fn cef_to_metal_format(&self, format: cef_color_type_t) -> Result { From 452a2e2b77724b0c8c6ce1341ba21c105f6501c1 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: 2025年10月16日 12:16:14 +0200 Subject: [PATCH 5/6] Test --- desktop/Cargo.toml | 6 +--- desktop/src/cef/texture_import/iosurface.rs | 35 ++++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index fb1213be51..e353cebb61 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -66,14 +66,10 @@ windows = { version = "0.58.0", features = [ # macOS-specific dependencies [target.'cfg(target_os = "macos")'.dependencies] -metal = { version = "0.32.0", optional = true } +metal = { version = "0.31.0", optional = true } objc = { version = "0.2", optional = true } core-foundation = { version = "0.10", optional = true } -[target.'cfg(target_os = "macos")'.dependencies] -objc2-io-surface = { version = "0.3", optional = true } -objc2-metal = { version = "0.3", optional = true } -core-foundation = { version = "0.9", optional = true } # Linux-specific dependencies [target.'cfg(target_os = "linux")'.dependencies] diff --git a/desktop/src/cef/texture_import/iosurface.rs b/desktop/src/cef/texture_import/iosurface.rs index 90d8be7e23..f987ab4129 100644 --- a/desktop/src/cef/texture_import/iosurface.rs +++ b/desktop/src/cef/texture_import/iosurface.rs @@ -3,8 +3,8 @@ use super::common::{format, texture}; use super::{TextureImportError, TextureImportResult, TextureImporter}; use cef::{AcceleratedPaintInfo, sys::cef_color_type_t}; -use core_foundation::base::TCFType; -use metal::{Device, MTLPixelFormat, MTLResourceOptions, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage, Texture}; +use metal::foreign_types::ForeignType; +use metal::{Device, MTLPixelFormat, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage, Texture}; use std::os::raw::c_void; use wgpu::hal::api; @@ -73,17 +73,18 @@ impl IOSurfaceImporter { let metal_texture = self.import_iosurface_to_metal_texture(hal_device)?; // Wrap Metal texture in wgpu-hal texture + // texture_from_raw signature: (texture, format, texture_type, mip_levels, sample_count, copy_extent) let hal_texture = ::Device::texture_from_raw( metal_texture, format::cef_to_wgpu(self.format)?, - wgpu::TextureDimension::D2, - wgpu::Extent3d { + MTLTextureType::D2, + 1, // mip_level_count + 1, // sample_count + wgpu::hal::CopyExtent { width: self.width, height: self.height, - depth_or_array_layers: 1, + depth: 1, }, - 1, // mip_level_count - 1, // sample_count ); Ok(hal_texture) @@ -126,17 +127,13 @@ impl IOSurfaceImporter { // Convert CEF format to Metal pixel format let metal_format = self.cef_to_metal_format(self.format)?; - // Create Metal texture descriptor - let descriptor = MTLTextureDescriptor::new(); - descriptor.set_texture_type(MTLTextureType::D2); - descriptor.set_pixel_format(metal_format); - descriptor.set_width(self.width as u64); - descriptor.set_height(self.height as u64); - descriptor.set_depth(1); - descriptor.set_mipmap_level_count(1); - descriptor.set_sample_count(1); - descriptor.set_array_length(1); - descriptor.set_resource_options(MTLResourceOptions::StorageModeShared); + // Create Metal texture descriptor using texture2DDescriptorWithPixelFormat + let descriptor = MTLTextureDescriptor::texture_2d_descriptor( + metal_format, + self.width as u64, + self.height as u64, + false, // mipmapped + ); descriptor.set_usage(MTLTextureUsage::ShaderRead); // Create Metal texture from IOSurface using Objective-C runtime @@ -159,7 +156,7 @@ impl IOSurfaceImporter { }); } - // Wrap in metal::Texture + // Wrap in metal::Texture using ForeignType Ok(Texture::from_ptr(metal_texture)) } } From 4747df1fba0dd86bd7a16a6864a005ff91ee1d53 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: 2025年10月16日 12:22:32 +0200 Subject: [PATCH 6/6] Fix remaining compile errors --- desktop/src/cef/texture_import/iosurface.rs | 56 ++++++++++++--------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/desktop/src/cef/texture_import/iosurface.rs b/desktop/src/cef/texture_import/iosurface.rs index f987ab4129..4de9decf19 100644 --- a/desktop/src/cef/texture_import/iosurface.rs +++ b/desktop/src/cef/texture_import/iosurface.rs @@ -3,14 +3,12 @@ use super::common::{format, texture}; use super::{TextureImportError, TextureImportResult, TextureImporter}; use cef::{AcceleratedPaintInfo, sys::cef_color_type_t}; +use core_foundation::base::TCFType; use metal::foreign_types::ForeignType; -use metal::{Device, MTLPixelFormat, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage, Texture}; +use metal::{Device, MTLPixelFormat, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage, Texture, TextureRef}; use std::os::raw::c_void; use wgpu::hal::api; -// IOSurface type from Core Foundation -type IOSurfaceRef = *mut c_void; - pub struct IOSurfaceImporter { pub handle: *mut c_void, pub format: cef_color_type_t, @@ -127,28 +125,37 @@ impl IOSurfaceImporter { // Convert CEF format to Metal pixel format let metal_format = self.cef_to_metal_format(self.format)?; - // Create Metal texture descriptor using texture2DDescriptorWithPixelFormat - let descriptor = MTLTextureDescriptor::texture_2d_descriptor( - metal_format, - self.width as u64, - self.height as u64, - false, // mipmapped - ); - descriptor.set_usage(MTLTextureUsage::ShaderRead); - - // Create Metal texture from IOSurface using Objective-C runtime + // Create Metal texture from IOSurface using objc runtime + // We need to use raw objc because the metal crate doesn't expose IOSurface creation directly unsafe { - let iosurface = self.handle as IOSurfaceRef; - - // Call newTextureWithDescriptor:iosurface:plane: on the Metal device - // This uses objc runtime to call the Metal API use objc::runtime::Object; - use objc::{msg_send, sel, sel_impl}; + use objc::{class, msg_send, sel, sel_impl}; + + let iosurface = self.handle; + + // Create texture descriptor using NSObject/Objective-C + let descriptor_class = class!(MTLTextureDescriptor); + let descriptor: *mut Object = msg_send![descriptor_class, new]; + + // Set descriptor properties + let _: () = msg_send![descriptor, setTextureType: MTLTextureType::D2]; + let _: () = msg_send![descriptor, setPixelFormat: metal_format]; + let _: () = msg_send![descriptor, setWidth: self.width as u64]; + let _: () = msg_send![descriptor, setHeight: self.height as u64]; + let _: () = msg_send![descriptor, setDepth: 1u64]; + let _: () = msg_send![descriptor, setMipmapLevelCount: 1u64]; + let _: () = msg_send![descriptor, setSampleCount: 1u64]; + let _: () = msg_send![descriptor, setArrayLength: 1u64]; + let _: () = msg_send![descriptor, setUsage: MTLTextureUsage::ShaderRead.bits()]; + + // Get device pointer + let device_ptr = metal_device.lock().as_ptr(); - let device_ptr = metal_device.lock().as_ptr() as *mut Object; - let descriptor_ptr = descriptor.as_ptr() as *mut Object; + // Call newTextureWithDescriptor:iosurface:plane: + let metal_texture: *mut Object = msg_send![device_ptr, newTextureWithDescriptor:descriptor iosurface:iosurface plane:0u64]; - let metal_texture: *mut Object = msg_send![device_ptr, newTextureWithDescriptor:descriptor_ptr iosurface:iosurface plane:0u64]; + // Release the descriptor + let _: () = msg_send![descriptor, release]; if metal_texture.is_null() { return Err(TextureImportError::PlatformError { @@ -156,8 +163,9 @@ impl IOSurfaceImporter { }); } - // Wrap in metal::Texture using ForeignType - Ok(Texture::from_ptr(metal_texture)) + // Cast to correct type and wrap in metal::Texture + let mtl_texture = metal_texture as *mut metal::MTLTexture; + Ok(Texture::from_ptr(mtl_texture)) } }

AltStyle によって変換されたページ (->オリジナル) /