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 missing macOS 10.6+ IOSurface functions #459

Merged
merged 1 commit into from
Oct 27, 2021
Merged
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
1 change: 1 addition & 0 deletions io-surface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ default-target = "x86_64-apple-darwin"
[dependencies]
libc = "0.2"
core-foundation = { path = "../core-foundation", version = "0.9" }
core-foundation-sys = { path = "../core-foundation-sys", version = "0.8" }
cgl = "0.3"
leaky-cow = "0.1.1"
67 changes: 52 additions & 15 deletions io-surface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

extern crate libc;
extern crate core_foundation;
extern crate core_foundation_sys;
extern crate cgl;
extern crate leaky_cow;

Expand All @@ -20,6 +21,7 @@ extern crate leaky_cow;
use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, CFType, TCFType};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use core_foundation::string::{CFString, CFStringRef};
use core_foundation_sys::base::mach_port_t;
use cgl::{kCGLNoError, CGLGetCurrentContext, CGLTexImageIOSurface2D, CGLErrorString, GLenum};
use libc::{c_int, size_t};
use std::os::raw::c_void;
Expand All @@ -33,8 +35,12 @@ const RGB: GLenum = 0x1907;
const TEXTURE_RECTANGLE_ARB: GLenum = 0x84F5;
const UNSIGNED_INT_8_8_8_8_REV: GLenum = 0x8367;

//static kIOSurfaceLockReadOnly: u32 = 0x1;
//static kIOSurfaceLockAvoidSync: u32 = 0x2;
#[allow(non_snake_case)]
pub mod IOSurfaceLockOptions {
#![allow(non_upper_case_globals)]
pub const kIOSurfaceLockReadOnly: u32 = 0x00000001;
pub const kIOSurfaceLockAvoidSync: u32 = 0x00000002;
}

type IOReturn = c_int;

Expand Down Expand Up @@ -143,7 +149,7 @@ impl IOSurface {
let error_msg = error_msg.to_string_lossy();
// This will only actually leak memory if error_msg is a `Cow::Owned`, which
// will only happen if the platform gives us invalid unicode.
panic!(error_msg.leak());
panic!("{}", error_msg.leak());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not relevant to the PR itself, but fixes a warning at compile time.

}
}
}
Expand Down Expand Up @@ -195,16 +201,47 @@ extern {
pub static kIOSurfaceIsGlobal: CFStringRef;
pub static kIOSurfacePixelFormat: CFStringRef;

fn IOSurfaceCreate(properties: CFDictionaryRef) -> IOSurfaceRef;
fn IOSurfaceLookup(csid: IOSurfaceID) -> IOSurfaceRef;
fn IOSurfaceGetID(buffer: IOSurfaceRef) -> IOSurfaceID;

fn IOSurfaceGetTypeID() -> CFTypeID;

fn IOSurfaceLock(buffer: IOSurfaceRef, options: u32, seed: *mut u32) -> IOReturn;
fn IOSurfaceUnlock(buffer: IOSurfaceRef, options: u32, seed: *mut u32) -> IOReturn;

fn IOSurfaceGetHeight(buffer: IOSurfaceRef) -> size_t;
fn IOSurfaceGetBytesPerRow(buffer: IOSurfaceRef) -> size_t;
fn IOSurfaceGetBaseAddress(buffer: IOSurfaceRef) -> *mut c_void;
pub fn IOSurfaceCreate(properties: CFDictionaryRef) -> IOSurfaceRef;
pub fn IOSurfaceLookup(csid: IOSurfaceID) -> IOSurfaceRef;
pub fn IOSurfaceGetID(buffer: IOSurfaceRef) -> IOSurfaceID;

pub fn IOSurfaceGetTypeID() -> CFTypeID;

pub fn IOSurfaceLock(buffer: IOSurfaceRef, options: u32, seed: *mut u32) -> IOReturn;
pub fn IOSurfaceUnlock(buffer: IOSurfaceRef, options: u32, seed: *mut u32) -> IOReturn;
pub fn IOSurfaceGetSeed(buffer: IOSurfaceRef) -> u32;

pub fn IOSurfaceGetHeight(buffer: IOSurfaceRef) -> size_t;
pub fn IOSurfaceGetWidth(buffer: IOSurfaceRef) -> usize;
pub fn IOSurfaceGetBytesPerRow(buffer: IOSurfaceRef) -> size_t;
pub fn IOSurfaceGetBaseAddress(buffer: IOSurfaceRef) -> *mut c_void;
pub fn IOSurfaceGetElementHeight(buffer: IOSurfaceRef) -> usize;
pub fn IOSurfaceGetElementWidth(buffer: IOSurfaceRef) -> usize;
pub fn IOSurfaceGetBytesPerElement(buffer: IOSurfaceRef) -> usize;
pub fn IOSurfaceGetAllocSize(buffer: IOSurfaceRef) -> usize;

pub fn IOSurfaceGetPixelFormat(buffer: IOSurfaceRef) -> i32;

pub fn IOSurfaceGetUseCount(buffer: IOSurfaceRef) -> i32;
pub fn IOSurfaceIncrementUseCount(buffer: IOSurfaceRef);
pub fn IOSurfaceDecrementUseCount(buffer: IOSurfaceRef);
pub fn IOSurfaceIsInUse(buffer: IOSurfaceRef) -> bool;

pub fn IOSurfaceCreateMachPort(buffer: IOSurfaceRef) -> mach_port_t;
pub fn IOSurfaceLookupFromMachPort(port: mach_port_t) -> IOSurfaceRef;

pub fn IOSurfaceGetPropertyAlignment(property: CFStringRef) -> usize;
pub fn IOSurfaceGetPropertyMaximum(property: CFStringRef) -> usize;

pub fn IOSurfaceCopyValue(buffer: IOSurfaceRef, key: CFStringRef) -> CFTypeRef;
pub fn IOSurfaceRemoveValue(buffer: IOSurfaceRef, key: CFStringRef);
pub fn IOSurfaceSetValue(buffer: IOSurfaceRef, key: CFStringRef, value: CFTypeRef);

pub fn IOSurfaceGetBaseAddressOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> *mut c_void;
pub fn IOSurfaceGetBytesPerElementOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> usize;
pub fn IOSurfaceGetBytesPerRowOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> usize;
pub fn IOSurfaceGetElementHeightOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> usize;
pub fn IOSurfaceGetElementWidthOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> usize;
pub fn IOSurfaceGetHeightOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> usize;
pub fn IOSurfaceGetWidthOfPlane(buffer: IOSurfaceRef, plane_index: usize) -> usize;
}