Skip to content

Commit

Permalink
ca::Renderer property keys
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed May 2, 2023
1 parent c6f73f4 commit 25a473b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
14 changes: 9 additions & 5 deletions cidre/pomace/sc/sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ static void mtl_initializer(void)
{
static int initialized = 0;
if (!initialized) {
SC_STREAM_CONFIGURATION = [SCStreamConfiguration class];
SC_CONTENT_FILTER = [SCContentFilter class];
SC_STREAM = [SCStream class];
SC_SHAREABLE_CONTENT = [SCShareableContent class];

if (@available(macOS 12.3, *)) {
SC_STREAM_CONFIGURATION = [SCStreamConfiguration class];
SC_CONTENT_FILTER = [SCContentFilter class];
SC_STREAM = [SCStream class];
SC_SHAREABLE_CONTENT = [SCShareableContent class];
} else {
// Fallback on earlier versions
}

initialized = 1;
}
}
Expand Down
4 changes: 4 additions & 0 deletions cidre/src/ca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ pub use layer::Layer;
mod metal_layer;
pub use metal_layer::MetalDrawable;
pub use metal_layer::MetalLayer;

mod renderer;
pub use renderer::OptionKey as RendererOptionKey;
pub use renderer::Renderer;
24 changes: 21 additions & 3 deletions cidre/src/ca/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
use crate::{arc, cf, cv, define_cls, define_obj_type, ns, objc};

define_obj_type!(Renderer(ns::Id));
define_obj_type!(OptionKey(ns::String));

impl OptionKey {
#[inline]
pub fn color_space() -> &'static Self {
unsafe { kCARendererColorSpace }
}

#[inline]
pub fn metal_cmd_queue() -> &'static Self {
unsafe { kCARendererMetalCommandQueue }
}
}

define_obj_type!(Renderer(ns::Id));
impl Renderer {
define_cls!(CA_RENDERER);

#[objc::cls_msg_send(rendererWithMTLTexture:options:)]
pub fn with_mtl_texture_ar(
texture: &mtl::Texture,
options: Option<&ns::Dictionary<ns::String, ns::Id>>,
options: Option<&ns::Dictionary<OptionKey, ns::Id>>,
) -> &'ar Self;

#[objc::rar_retain]
pub fn with_mtl_texture(
texture: &mtl::Texture,
options: Option<&ns::Dictionary<ns::String, ns::Id>>,
options: Option<&ns::Dictionary<OptionKey, ns::Id>>,
) -> arc::R<Self>;

#[objc::msg_send(layer)]
Expand Down Expand Up @@ -56,3 +69,8 @@ impl Renderer {
extern "C" {
static CA_RENDERER: &'static objc::Class<Renderer>;
}

extern "C" {
static kCARendererColorSpace: &'static OptionKey;
static kCARendererMetalCommandQueue: &'static OptionKey;
}

0 comments on commit 25a473b

Please sign in to comment.