Skip to content

Commit

Permalink
Add the CoreVideo framework
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Dec 10, 2024
1 parent 04f7841 commit 71be5dc
Show file tree
Hide file tree
Showing 20 changed files with 377 additions and 82 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion crates/header-translator/src/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ impl Ty {
// Ignored for now; these are usually also emitted on the method/property,
// which is where they will be useful in any case.
}
Some(UnexposedAttr::ReturnsRetained) => {
lifetime = Lifetime::Strong;
}
Some(UnexposedAttr::ReturnsNotRetained) => {
lifetime = Lifetime::Autoreleasing;
}
Some(attr) => error!(?attr, "unknown attribute on type"),
None => {}
}
Expand Down Expand Up @@ -1804,7 +1810,23 @@ impl Ty {
ty
}

pub(crate) fn parse_function_argument(ty: Type<'_>, context: &Context<'_>) -> Self {
pub(crate) fn parse_function_argument(
ty: Type<'_>,
attr: Option<UnexposedAttr>,
context: &Context<'_>,
) -> Self {
match attr {
Some(UnexposedAttr::NoEscape) => {
// TODO: Use this if mapping `fn + context ptr` to closure.
}
Some(UnexposedAttr::ReturnsRetained) => {
// TODO: Massage this into a lifetime
}
Some(attr) => {
error!(?attr, "unknown attribute in function argument");
}
None => {}
}
Self::parse_method_argument(ty, None, None, false, context)
}

Expand Down
26 changes: 15 additions & 11 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,16 @@ pub enum Stmt {
},
}

fn parse_fn_param_children(entity: &Entity<'_>, context: &Context<'_>) {
immediate_children(entity, |entity, _span| match entity.get_kind() {
fn parse_fn_param_children(parent: &Entity<'_>, context: &Context<'_>) -> Option<UnexposedAttr> {
let mut ret = None;

immediate_children(parent, |entity, _span| match entity.get_kind() {
EntityKind::UnexposedAttr => {
if let Some(attr) = UnexposedAttr::parse(&entity, context) {
match attr {
UnexposedAttr::NoEscape => {
// TODO: Use this if mapping `fn + context ptr` to closure.
}
_ => error!(?attr, "unknown attribute on fn param"),
if ret.is_some() {
error!("found multiple attributes {ret:?} and {attr:?} on fn param");
}
ret = Some(attr);
}
}
EntityKind::ObjCClassRef
Expand All @@ -554,8 +554,10 @@ fn parse_fn_param_children(entity: &Entity<'_>, context: &Context<'_>) {
EntityKind::NSConsumed => {
error!("found NSConsumed, which requires manual handling");
}
kind => error!(?kind, "unknown"),
kind => error!(?parent, ?kind, "unknown"),
});

ret
}

pub(crate) fn new_enum_id(
Expand Down Expand Up @@ -1025,6 +1027,7 @@ impl Stmt {
match attr {
// TODO
UnexposedAttr::Sendable => warn!("sendable typedef"),
UnexposedAttr::NonSendable => warn!("non-sendable typedef"),
UnexposedAttr::UIActor => warn!("main-thread-only typedef"),
_ => kind = Some(attr),
}
Expand Down Expand Up @@ -1363,7 +1366,8 @@ impl Stmt {
UnexposedAttr::UIActor => {
warn!("unhandled UIActor on function declaration")
}
UnexposedAttr::ReturnsRetained => {
UnexposedAttr::ReturnsRetained
| UnexposedAttr::ReturnsNotRetained => {
// TODO: Ignore for now, but at some point handle in a similar way to in methods
}
_ => error!(?attr, "unknown attribute on function"),
Expand All @@ -1374,11 +1378,11 @@ impl Stmt {
| EntityKind::TypeRef
| EntityKind::ObjCProtocolRef => {}
EntityKind::ParmDecl => {
parse_fn_param_children(&entity, context);
let attr = parse_fn_param_children(&entity, context);
// Could also be retrieved via `get_arguments`
let name = entity.get_name().unwrap_or_else(|| "_".into());
let ty = entity.get_type().expect("function argument type");
let ty = Ty::parse_function_argument(ty, context);
let ty = Ty::parse_function_argument(ty, attr, context);
arguments.push((name, ty))
}
EntityKind::VisibilityAttr => {
Expand Down
20 changes: 16 additions & 4 deletions crates/header-translator/src/unexposed_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ impl UnexposedAttr {
"NS_SWIFT_BRIDGED_TYPEDEF" | "CF_SWIFT_BRIDGED_TYPEDEF" => Some(Self::BridgedTypedef),
"CF_BRIDGED_TYPE" => Some(Self::Bridged),
"CF_BRIDGED_MUTABLE_TYPE" => Some(Self::BridgedMutable),
"NS_RETURNS_RETAINED" | "CF_RETURNS_RETAINED" => Some(Self::ReturnsRetained),
"NS_RETURNS_RETAINED"
| "CF_RETURNS_RETAINED"
| "CV_RETURNS_RETAINED"
| "CV_RETURNS_RETAINED_PARAMETER" => Some(Self::ReturnsRetained),
"NS_RETURNS_NOT_RETAINED" | "CF_RETURNS_NOT_RETAINED" => Some(Self::ReturnsNotRetained),
"NS_RETURNS_INNER_POINTER" => None,
// This has two arguments: `sendability` and `nullability`.
Expand All @@ -76,8 +79,8 @@ impl UnexposedAttr {
let _ = get_arguments();
None
}
"NS_SWIFT_SENDABLE" | "AS_SWIFT_SENDABLE" => Some(Self::Sendable),
"NS_SWIFT_NONSENDABLE" => Some(Self::NonSendable),
"NS_SWIFT_SENDABLE" | "AS_SWIFT_SENDABLE" | "CV_SWIFT_SENDABLE" => Some(Self::Sendable),
"NS_SWIFT_NONSENDABLE" | "CV_SWIFT_NONSENDABLE" => Some(Self::NonSendable),
"NS_SWIFT_UI_ACTOR" | "WK_SWIFT_UI_ACTOR" => Some(Self::UIActor),
"NS_SWIFT_NONISOLATED" | "UIKIT_SWIFT_ACTOR_INDEPENDENT" => Some(Self::NonIsolated),
// TODO
Expand Down Expand Up @@ -106,6 +109,7 @@ impl UnexposedAttr {
| "__IOS_AVAILABLE"
| "__IOS_DEPRECATED"
| "__OSX_AVAILABLE"
| "__OSX_AVAILABLE_BUT_DEPRECATED"
| "__OSX_AVAILABLE_STARTING"
| "__OSX_DEPRECATED"
| "__TVOS_AVAILABLE"
Expand All @@ -132,6 +136,7 @@ impl UnexposedAttr {
| "CIKL_DEPRECATED"
| "CK_UNAVAILABLE"
| "CK_NEWLY_UNAVAILABLE"
| "COREVIDEO_GL_DEPRECATED"
| "FPUI_AVAILABLE"
| "MLCOMPUTE_AVAILABLE_STARTING"
| "MLCOMPUTE_AVAILABLE_STARTING_BUT_DEPRECATED_MACOS14"
Expand Down Expand Up @@ -190,7 +195,6 @@ impl UnexposedAttr {
"AS_API_AVAILABLE" | "AS_HEADER_AUDIT_BEGIN" => None,
"__IOS_PROHIBITED"
| "__IOS_UNAVAILABLE"
| "__OSX_AVAILABLE_BUT_DEPRECATED"
| "__OSX_UNAVAILABLE"
| "__TVOS_PROHIBITED"
| "__TVOS_UNAVAILABLE"
Expand Down Expand Up @@ -231,6 +235,14 @@ impl UnexposedAttr {
| "NS_REFINED_FOR_SWIFT"
| "NS_SWIFT_DISABLE_ASYNC"
| "NS_SWIFT_NOTHROW" => None,
"CF_CONSUMED"
| "CF_RELEASES_ARGUMENT"
| "NS_RELEASES_ARGUMENT"
| "CM_RELEASES_ARGUMENT"
| "CV_RELEASES_ARGUMENT" => {
error!(?s, "attribute that requires manual handling. Mark it as skipped in translation-config.toml");
None
}
_ => return Err(()),
})
}
Expand Down
8 changes: 0 additions & 8 deletions crates/header-translator/system-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ class.NSObject.methods.release.skipped = true
fn.IOServiceGetMatchingService.skipped = true
fn.IOServiceGetMatchingServices.skipped = true
fn.IOServiceAddMatchingNotification.skipped = true
fn.CVOpenGLBufferRelease.skipped = true
fn.CVDisplayLinkRelease.skipped = true
fn.CVOpenGLBufferPoolRelease.skipped = true
fn.CVOpenGLTextureRelease.skipped = true
fn.CVPixelBufferPoolRelease.skipped = true
fn.CVPixelBufferRelease.skipped = true
fn.CVOpenGLTextureCacheRelease.skipped = true
fn.CVBufferRelease.skipped = true
# + a few methods from DriverKit.framework and Kernel.framework, but those
# are written in C++, so we're not going to ever handle them anyhow.

Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/topics/about_generated/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Added new framework crates:
- `CoreAudioTypes` / `objc2-core-audio-types`.
- `CoreFoundation` / `objc2-core-foundation`.
- `CoreVideo` / `objc2-core-video`.
- `ScreenSaver` / `objc2-screen-saver`.

### Changed
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/topics/about_generated/list_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
| `CoreLocation` | [![`objc2-core-location`](https://badgen.net/crates/v/objc2-core-location)](https://crates.io/crates/objc2-core-location) | [![docs.rs](https://docs.rs/objc2-core-location/badge.svg)](https://docs.rs/objc2-core-location/) |
| `CoreML` | [![`objc2-core-ml`](https://badgen.net/crates/v/objc2-core-ml)](https://crates.io/crates/objc2-core-ml) | [![docs.rs](https://docs.rs/objc2-core-ml/badge.svg)](https://docs.rs/objc2-core-ml/) |
| `CoreMotion` | [![`objc2-core-motion`](https://badgen.net/crates/v/objc2-core-motion)](https://crates.io/crates/objc2-core-motion) | [![docs.rs](https://docs.rs/objc2-core-motion/badge.svg)](https://docs.rs/objc2-core-motion/) |
| `CoreVideo` | [![`objc2-core-video`](https://badgen.net/crates/v/objc2-core-video)](https://crates.io/crates/objc2-core-video) | [![docs.rs](https://docs.rs/objc2-core-video/badge.svg)](https://docs.rs/objc2-core-video/) |
| `CoreWLAN` | [![`objc2-core-wlan`](https://badgen.net/crates/v/objc2-core-wlan)](https://crates.io/crates/objc2-core-wlan) | [![docs.rs](https://docs.rs/objc2-core-wlan/badge.svg)](https://docs.rs/objc2-core-wlan/) |
| `DataDetection` | [![`objc2-data-detection`](https://badgen.net/crates/v/objc2-data-detection)](https://crates.io/crates/objc2-data-detection) | [![docs.rs](https://docs.rs/objc2-data-detection/badge.svg)](https://docs.rs/objc2-data-detection/) |
| `DeviceCheck` | [![`objc2-device-check`](https://badgen.net/crates/v/objc2-device-check)](https://crates.io/crates/objc2-device-check) | [![docs.rs](https://docs.rs/objc2-device-check/badge.svg)](https://docs.rs/objc2-device-check/) |
Expand Down
31 changes: 26 additions & 5 deletions framework-crates/objc2-core-image/Cargo.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions framework-crates/objc2-core-image/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,3 @@ class.CIRenderDestination.methods."setColorSpace:".skipped = true
class.CIVector.methods."vectorWithCGAffineTransform:".skipped = true
class.CIVector.methods."initWithCGAffineTransform:".skipped = true
class.CIVector.methods.CGAffineTransformValue.skipped = true

# Needs CoreVideo
class.CIContext.methods."render:toCVPixelBuffer:".skipped = true
class.CIImage.methods."imageWithCVImageBuffer:".skipped = true
class.CIImage.methods."imageWithCVImageBuffer:options:".skipped = true
class.CIImage.methods."imageWithCVPixelBuffer:".skipped = true
class.CIImage.methods."imageWithCVPixelBuffer:options:".skipped = true
class.CIImage.methods."initWithCVImageBuffer:".skipped = true
class.CIImage.methods."initWithCVImageBuffer:options:".skipped = true
class.CIImage.methods."initWithCVPixelBuffer:".skipped = true
class.CIImage.methods."initWithCVPixelBuffer:options:".skipped = true
class.CIImage.methods.pixelBuffer.skipped = true
protocol.CIImageProcessorInput.methods.pixelBuffer.skipped = true
protocol.CIImageProcessorOutput.methods.pixelBuffer.skipped = true
class.CIFilter.methods."filterWithCVPixelBuffer:properties:options:".skipped = true
class.CIRAWFilter.methods."filterWithCVPixelBuffer:properties:".skipped = true
class.CIRenderDestination.methods."initWithPixelBuffer:".skipped = true
Loading

0 comments on commit 71be5dc

Please sign in to comment.