Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added MetalLayer methods #185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,15 +1426,19 @@ impl DeviceRef {
}

#[cfg(feature = "private")]
pub unsafe fn vendor(&self) -> &str {
let name = msg_send![self, vendorName];
crate::nsstring_as_str(name)
pub fn vendor(&self) -> &str {
unsafe {
let name = msg_send![self, vendorName];
crate::nsstring_as_str(name)
}
}

#[cfg(feature = "private")]
pub unsafe fn family_name(&self) -> &str {
let name = msg_send![self, familyName];
crate::nsstring_as_str(name)
pub fn family_name(&self) -> &str {
unsafe {
let name = msg_send![self, familyName];
crate::nsstring_as_str(name)
}
}

pub fn registry_id(&self) -> u64 {
Expand Down
30 changes: 24 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ where
type CType = NSArray<T>;
type Ref = ArrayRef<T>;

unsafe fn from_ptr(p: *mut NSArray<T>) -> Self {
Array(p)
fn from_ptr(p: *mut NSArray<T>) -> Self {
unsafe { Array(p) }
}

fn as_ptr(&self) -> *mut NSArray<T> {
Expand Down Expand Up @@ -316,6 +316,10 @@ impl MetalLayerRef {
unsafe { msg_send![self, setDevice: device] }
}

pub fn preferred_device(&self) -> &DeviceRef {
unsafe { msg_send![self, preferredDevice] }
}

pub fn pixel_format(&self) -> MTLPixelFormat {
unsafe { msg_send![self, pixelFormat] }
}
Expand Down Expand Up @@ -346,6 +350,20 @@ impl MetalLayerRef {
unsafe { msg_send![self, setPresentsWithTransaction: transaction] }
}

pub fn display_sync_enabled(&self) -> bool {
unsafe {
match msg_send![self, displaySyncEnabled] {
YES => true,
NO => false,
_ => unreachable!(),
}
}
}

pub fn set_display_sync_enabled(&self, sync_enabled: bool) {
unsafe { msg_send![self, setDisplaySyncEnabled: sync_enabled] }
}

pub fn set_edge_antialiasing_mask(&self, mask: u64) {
unsafe { msg_send![self, setEdgeAntialiasingMask: mask] }
}
Expand Down Expand Up @@ -451,13 +469,13 @@ pub use {
pub use mps::*;

#[inline]
unsafe fn obj_drop<T>(p: *mut T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should probably be left unsafe

msg_send![(p as *mut Object), release]
fn obj_drop<T>(p: *mut T) {
unsafe { msg_send![(p as *mut Object), release] }
}

#[inline]
unsafe fn obj_clone<T: 'static>(p: *mut T) -> *mut T {
msg_send![(p as *mut Object), retain]
fn obj_clone<T: 'static>(p: *mut T) -> *mut T {
unsafe { msg_send![(p as *mut Object), retain] }
}

#[allow(non_camel_case_types)]
Expand Down
12 changes: 6 additions & 6 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ impl FunctionConstantValues {
}

impl FunctionConstantValuesRef {
pub unsafe fn set_constant_value_at_index(
pub fn set_constant_value_at_index(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't be safe, since we are passing a raw pointer in

&self,
index: NSUInteger,
ty: MTLDataType,
value: *const std::os::raw::c_void,
) {
msg_send![self, setConstantValue:value type:ty atIndex:index]
unsafe { msg_send![self, setConstantValue:value type:ty atIndex:index] }
}
}

Expand All @@ -149,12 +149,12 @@ impl CompileOptions {
}

impl CompileOptionsRef {
pub unsafe fn preprocessor_defines(&self) -> *mut Object {
msg_send![self, preprocessorMacros]
pub fn preprocessor_defines(&self) -> *mut Object {
unsafe { msg_send![self, preprocessorMacros] }
}

pub unsafe fn set_preprocessor_defines(&self, defines: *mut Object) {
msg_send![self, setPreprocessorMacros: defines]
pub fn set_preprocessor_defines(&self, defines: *mut Object) {
unsafe { msg_send![self, setPreprocessorMacros: defines] }
}

pub fn is_fast_math_enabled(&self) -> bool {
Expand Down
32 changes: 18 additions & 14 deletions src/pipeline/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,28 @@ foreign_obj_type! {

impl RenderPipelineReflection {
#[cfg(feature = "private")]
pub unsafe fn new(
pub fn new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, can't be safe

vertex_data: *mut std::ffi::c_void,
fragment_data: *mut std::ffi::c_void,
vertex_desc: *mut std::ffi::c_void,
device: &DeviceRef,
options: u64,
flags: u64,
) -> Self {
let class = class!(MTLRenderPipelineReflection);
let this: RenderPipelineReflection = msg_send![class, alloc];
let this_alias: *mut Object = msg_send![this.as_ref(), initWithVertexData:vertex_data
unsafe {
let class = class!(MTLRenderPipelineReflection);
let this: RenderPipelineReflection = msg_send![class, alloc];
let this_alias: *mut Object = msg_send![this.as_ref(), initWithVertexData:vertex_data
fragmentData:fragment_data
serializedVertexDescriptor:vertex_desc
device:device
options:options
flags:flags];
if this_alias.is_null() {
panic!("[MTLRenderPipelineReflection init] failed");
if this_alias.is_null() {
panic!("[MTLRenderPipelineReflection init] failed");
}
this
}
this
}
}

Expand Down Expand Up @@ -339,17 +341,19 @@ impl RenderPipelineDescriptorRef {
}

#[cfg(feature = "private")]
pub unsafe fn serialize_vertex_data(&self) -> *mut std::ffi::c_void {
use std::ptr;
let flags = 0;
let err: *mut Object = ptr::null_mut();
msg_send![self, newSerializedVertexDataWithFlags:flags
pub fn serialize_vertex_data(&self) -> *mut std::ffi::c_void {
unsafe {
use std::ptr;
let flags = 0;
let err: *mut Object = ptr::null_mut();
msg_send![self, newSerializedVertexDataWithFlags:flags
error:err]
}
}

#[cfg(feature = "private")]
pub unsafe fn serialize_fragment_data(&self) -> *mut std::ffi::c_void {
msg_send![self, serializeFragmentData]
pub fn serialize_fragment_data(&self) -> *mut std::ffi::c_void {
unsafe { msg_send![self, serializeFragmentData] }
}

pub fn support_indirect_command_buffers(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl SamplerDescriptorRef {
}

#[cfg(feature = "private")]
pub unsafe fn set_lod_bias(&self, bias: f32) {
msg_send![self, setLodBias: bias]
pub fn set_lod_bias(&self, bias: f32) {
unsafe { msg_send![self, setLodBias: bias] }
}

pub fn set_lod_min_clamp(&self, clamp: f32) {
Expand Down
14 changes: 8 additions & 6 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ foreign_obj_type! {
}

impl SharedEventListener {
pub unsafe fn from_queue_handle(queue: dispatch_queue_t) -> Self {
let listener: SharedEventListener = msg_send![class!(MTLSharedEventListener), alloc];
let ptr: *mut Object = msg_send![listener.as_ref(), initWithDispatchQueue: queue];
if ptr.is_null() {
panic!("[MTLSharedEventListener alloc] initWithDispatchQueue failed");
pub fn from_queue_handle(queue: dispatch_queue_t) -> Self {
unsafe {
let listener: SharedEventListener = msg_send![class!(MTLSharedEventListener), alloc];
let ptr: *mut Object = msg_send![listener.as_ref(), initWithDispatchQueue: queue];
if ptr.is_null() {
panic!("[MTLSharedEventListener alloc] initWithDispatchQueue failed");
}
listener
}
listener
}

#[cfg(feature = "dispatch-queue")]
Expand Down
4 changes: 2 additions & 2 deletions src/vertexdescriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ impl VertexDescriptorRef {
}

#[cfg(feature = "private")]
pub unsafe fn serialize_descriptor(&self) -> *mut std::ffi::c_void {
msg_send![self, newSerializedDescriptor]
pub fn serialize_descriptor(&self) -> *mut std::ffi::c_void {
unsafe { msg_send![self, newSerializedDescriptor] }
}

pub fn reset(&self) {
Expand Down