Skip to content

Commit

Permalink
new ca::Layer api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 9, 2024
1 parent 40a29d9 commit 26e7f45
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 9 deletions.
1 change: 1 addition & 0 deletions cidre/src/ca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use layer::CornerCurve as LayerCornerCurve;
pub use layer::CornerMask;
pub use layer::EdgeAntialiasingMask;
pub use layer::Layer;
pub use layer::ToneMapMode;

#[cfg(feature = "mtl")]
mod metal_layer;
Expand Down
152 changes: 143 additions & 9 deletions cidre/src/ca/layer.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,73 @@
use crate::{
arc, ca, cf, cg, define_obj_type, define_opts,
ns::{self, Id},
objc,
};

define_obj_type!(pub ContentsGravity(ns::String));
define_obj_type!(pub ContentsFormat(ns::String));
use crate::{api, arc, ca, cf, cg, define_obj_type, define_opts, ns, objc};

define_obj_type!(
#[doc(alias = "CALayerContentsGravity")]
pub ContentsGravity(ns::String)
);

define_obj_type!(
#[doc(alias = "CALayerContentsFormat")]
pub ContentsFormat(ns::String)
);

define_obj_type!(
#[doc(alias = "CALayerContentsFilter")]
pub ContentsFilter(ns::String)
);

define_obj_type!(
#[doc(alias = "CALayerCornerCurve")]
pub CornerCurve(ns::String)
);

define_obj_type!(
/// Options that control when to tone map ca::Layer contents and
/// ca::MetalLayer drawables. Defaults to
#[doc(alias = "CALayer.ToneMapMode")]
#[doc(alias = "CAToneMapMode")]
pub ToneMapMode(ns::String)
);

impl ToneMapMode {
/// Let the OS decide whether to tone map.
#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
pub fn automatic() -> &'static Self {
unsafe { CAToneMapModeAutomatic }
}

/// Never tone map contents.
#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
pub fn never() -> &'static Self {
unsafe { CAToneMapModeNever }
}

/// Tone map whenever supported by the OS. This includes
/// PQ, HLG and extended-range contents for ca::Layer
/// and ca::MetalLayers.
#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
pub fn if_supported() -> &'static Self {
unsafe { CAToneMapModeIfSupported }
}
}

define_opts!(
#[doc(alias = "CAAutoresizingMask")]
pub AutoresizingMask(u32)
Expand Down Expand Up @@ -144,14 +197,64 @@ impl Layer {
pub fn animation_keys(&self) -> Option<arc::R<ns::Array<ns::String>>>;

#[objc::msg_send(contents)]
pub fn contents(&self) -> Option<arc::R<Id>>;
pub fn contents(&self) -> Option<arc::R<ns::Id>>;

#[objc::msg_send(setContents:)]
pub fn set_ns_contents(&mut self, contents: Option<&ns::Id>);

#[objc::msg_send(setContents:)]
pub fn set_cf_contents(&mut self, contents: Option<&cf::Type>);

#[objc::msg_send(contentsRect)]
pub fn contents_rect(&self) -> cg::Rect;

#[objc::msg_send(setContentsRect:)]
pub fn set_contents_rect(&mut self, val: cg::Rect);

#[objc::msg_send(contentsGravity)]
pub fn contents_gravity(&self) -> arc::R<ContentsGravity>;

#[objc::msg_send(setContentsGravity:)]
pub fn set_contents_gravity(&mut self, val: &ContentsGravity);

#[objc::msg_send(contentsScale)]
pub fn contents_scale(&self) -> cg::Float;

#[objc::msg_send(setContentsScale:)]
pub fn set_contents_scale(&mut self, val: cg::Float);

#[objc::msg_send(contentsCenter)]
pub fn contents_center(&self) -> cg::Rect;

#[objc::msg_send(setContentsCenter:)]
pub fn set_contents_center(&mut self, val: cg::Rect);

#[objc::msg_send(contentsFormat)]
pub fn contents_format(&self) -> arc::R<ContentsFormat>;

#[objc::msg_send(setContentsFormat:)]
pub fn set_contents_format(&mut self, val: &ContentsFormat);

#[objc::msg_send(toneMapMode)]
#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
pub fn tone_map_mode(&self) -> arc::R<ToneMapMode>;

#[objc::msg_send(setToneMapMode:)]
#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
pub fn set_tone_map_mode(&mut self, val: &ToneMapMode);

#[objc::msg_send(wantsExtendedDynamicRangeContent)]
pub fn wants_extended_dynamic_range_content(&self) -> bool;

Expand All @@ -163,3 +266,34 @@ impl Layer {
extern "C" {
static CA_LAYER: &'static objc::Class<Layer>;
}

#[link(name = "QuartzCore", kind = "framework")]
#[api::weak]
extern "C" {
#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
static CAToneMapModeAutomatic: &'static ToneMapMode;

#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
static CAToneMapModeNever: &'static ToneMapMode;

#[api::available(
macos = 15.0,
maccatalyst = 18.0,
ios = 18.0,
tvos = 18.0,
visionos = 2.0
)]
static CAToneMapModeIfSupported: &'static ToneMapMode;
}

0 comments on commit 26e7f45

Please sign in to comment.