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

Add CoreAnimation framework #325

Merged
merged 4 commits into from
Jan 8, 2023
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
2 changes: 2 additions & 0 deletions crates/header-translator/framework-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <Foundation/Foundation.h>

#import <QuartzCore/CoreAnimation.h>

#import <CoreData/CoreData.h>

#if TARGET_OS_OSX
Expand Down
20 changes: 19 additions & 1 deletion crates/header-translator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,26 @@ pub struct MethodData {
pub mutating: bool,
}

#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct FnData {
#[serde(default)]
pub skipped: bool,
#[serde(rename = "unsafe")]
#[serde(default = "unsafe_default")]
pub unsafe_: bool,
}

impl Default for FnData {
fn default() -> Self {
Self {
skipped: skipped_default(),
unsafe_: unsafe_default(),
}
}
}

// TODO
pub type FnData = StructData;
pub type StaticData = StructData;
pub type TypedefData = StructData;

Expand Down
233 changes: 233 additions & 0 deletions crates/header-translator/src/data/CoreAnimation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
// We probably technically had the choice of making these classes mutating
// methods require `&mut`, but as with so many things in Cocoa, that would
// make it difficult to use in a larger context (e.g. even after assigning a
// layer to a view you'd often still want to modify the layer).

data! {
class CALayer {
unsafe +layer;
unsafe -init;

// -initWithLayer must be called in a specific context

// -presentationLayer's return value may not be safe to modify
// -modelLayer must be called in a specific context

unsafe -bounds;
unsafe -setBounds;
unsafe -position;
unsafe -setPosition;
unsafe -zPosition;
unsafe -setZPosition;
unsafe -anchorPoint;
unsafe -setAnchorPoint;
unsafe -anchorPointZ;
unsafe -setAnchorPointZ;
unsafe -transform;
unsafe -setTransform;
unsafe -affineTransform;
unsafe -setAffineTransform;
unsafe -frame;
unsafe -setFrame;
unsafe -isHidden;
unsafe -setHidden;
unsafe -isDoubleSided;
unsafe -setDoubleSided;
unsafe -isGeometryFlipped;
unsafe -setGeometryFlipped;

unsafe -contentsAreFlipped;

unsafe -superlayer;
unsafe -removeFromSuperlayer;

// -sublayers is not safe, since the returned array is not guaranteed
// to retain its elements.

// -setSublayers not safe since it requires all layers to have a
// `nil` superlayer.

// If the layer already has a superlayer, it will be changed
// appropriately by these methods (effectively, removeFromSuperlayer
// is called on the given layer inside these).
unsafe -addSublayer;
unsafe -insertSublayer_atIndex;
unsafe -insertSublayer_below;
unsafe -insertSublayer_above;

// -replaceSublayer is not safe since it requires `oldlayer` to exist
// in the current layer.

unsafe -sublayerTransform;
unsafe -setSublayerTransform;
unsafe -mask;
// -setMask's argument must have a `nil` superlayer
unsafe -masksToBounds;
unsafe -setMasksToBounds;

unsafe -convertPoint_fromLayer;
unsafe -convertPoint_toLayer;
unsafe -convertRect_fromLayer;
unsafe -convertRect_toLayer;
unsafe -convertTime_fromLayer;
unsafe -convertTime_toLayer;
unsafe -hitTest;
unsafe -containsPoint;

// No type set:
// -contents;
// -setContents;
unsafe -contentsRect;
unsafe -setContentsRect;
unsafe -contentsGravity;
unsafe -setContentsGravity;
unsafe -contentsScale;
unsafe -setContentsScale;
unsafe -contentsCenter;
unsafe -setContentsCenter;
unsafe -contentsFormat;
unsafe -setContentsFormat;
unsafe -minificationFilter;
unsafe -setMinificationFilter;
unsafe -magnificationFilter;
unsafe -setMagnificationFilter;
unsafe -minificationFilterBias;
unsafe -setMinificationFilterBias;
unsafe -isOpaque;
unsafe -setOpaque;

unsafe -display;
unsafe -setNeedsDisplay;
unsafe -setNeedsDisplayInRect;
unsafe -needsDisplay;
unsafe -displayIfNeeded;
unsafe -needsDisplayOnBoundsChange;
unsafe -setNeedsDisplayOnBoundsChange;

unsafe -drawsAsynchronously;
unsafe -setDrawsAsynchronously;
unsafe -edgeAntialiasingMask;
unsafe -setEdgeAntialiasingMask;
unsafe -allowsEdgeAntialiasing;
unsafe -setAllowsEdgeAntialiasing;
unsafe -cornerRadius;
unsafe -setCornerRadius;
unsafe -maskedCorners;
unsafe -setMaskedCorners;
unsafe -cornerCurve;
unsafe -setCornerCurve;
unsafe -cornerCurveExpansionFactor;
unsafe -borderWidth;
unsafe -setBorderWidth;
unsafe -opacity;
// Gives "undefined results" outside [0; 1], but by this the authors
// very likely didn't mean "triggers language-level UB".
unsafe -setOpacity;
unsafe -allowsGroupOpacity;
unsafe -setAllowsGroupOpacity;
// No type set:
// -compositingFilter;
// -setCompositingFilter;
// -filters;
// -setFilters;
// -backgroundFilters;
// -setBackgroundFilters;
unsafe -shouldRasterize;
unsafe -setShouldRasterize;
unsafe -rasterizationScale;
unsafe -setRasterizationScale;
unsafe -shadowOpacity;
// Gives "undefined results" outside [0; 1], but by this the authors
// very likely didn't mean "triggers language-level UB".
unsafe -setShadowOpacity;
unsafe -shadowOffset;
unsafe -setShadowOffset;
unsafe -shadowRadius;
unsafe -setShadowRadius;
unsafe -autoresizingMask;
unsafe -setAutoresizingMask;
unsafe -layoutManager;
unsafe -setLayoutManager;

unsafe -preferredFrameSize;
unsafe -setNeedsLayout;
unsafe -needsLayout;
unsafe -layoutIfNeeded;
unsafe -layoutSublayers;
unsafe -resizeSublayersWithOldSize;
unsafe -resizeWithOldSuperlayerSize;

unsafe -defaultActionForKey;
unsafe -actionForKey;
unsafe -actions;
unsafe -setActions;

// Copies the animation
unsafe -addAnimation_forKey;

unsafe -removeAllAnimations;
unsafe -removeAnimationForKey;
unsafe -animationKeys;

// Not safe since modifying the returned animation is UB.
// -animationForKey;

unsafe -name;
unsafe -setName;
unsafe -delegate;
unsafe -setDelegate;
// No type set:
// -style;
// -setStyle;
}

class CARenderer {
unsafe -layer;
unsafe -setLayer;
unsafe -bounds;
unsafe -setBounds;
unsafe -updateBounds;
unsafe -addUpdateRect;
unsafe -render;
unsafe -nextFrameTime;
unsafe -endFrame;
}

// SAFETY: CATransaction is basically just a way to call methods that
// access thread-local state.
class CATransaction {
unsafe +begin;
unsafe +commit;
unsafe +flush;

unsafe +animationDuration;
unsafe +setAnimationDuration;

unsafe +animationTimingFunction;
unsafe +setAnimationTimingFunction;

unsafe +disableActions;
unsafe +setDisableActions;

// TODO:
// unsafe +completionBlock;
// unsafe +setCompletionBlock;
}

unsafe fn CACurrentMediaTime;

// SAFETY: Basic mathematical functions
unsafe fn CATransform3DIsIdentity;
unsafe fn CATransform3DEqualToTransform;
unsafe fn CATransform3DMakeTranslation;
unsafe fn CATransform3DMakeScale;
unsafe fn CATransform3DMakeRotation;
unsafe fn CATransform3DTranslate;
unsafe fn CATransform3DScale;
unsafe fn CATransform3DRotate;
unsafe fn CATransform3DConcat;
unsafe fn CATransform3DInvert;
unsafe fn CATransform3DMakeAffineTransform;
unsafe fn CATransform3DIsAffine;
unsafe fn CATransform3DGetAffineTransform;
}
3 changes: 3 additions & 0 deletions crates/header-translator/src/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ data! {
// The method `mutateUnchecked` takes &mut self, but is not safe.
mut -mutateUnchecked;
}

// Declare the function "foo" as safe
unsafe fn foo;
}
```

Expand Down
17 changes: 17 additions & 0 deletions crates/header-translator/src/data/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ macro_rules! __data_inner {
$($rest)*
}
};
// Function
(
@($config:expr)

unsafe fn $function:ident;

$($rest:tt)*
) => {
let mut data = $config.fns.entry(stringify!($function).to_string()).or_default();

data.unsafe_ = false;

__data_inner! {
@($config)
$($rest)*
}
}
}

macro_rules! __data_methods {
Expand Down
1 change: 1 addition & 0 deletions crates/header-translator/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod macros;
data! {
mod AppKit;
mod AuthenticationServices;
mod CoreAnimation;
mod CoreData;
mod Foundation;
}
1 change: 1 addition & 0 deletions crates/header-translator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "run")]
#![recursion_limit = "256"]
use std::collections::BTreeMap;
use std::fmt;
use std::path::Path;
Expand Down
Loading