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

missing CALayer.contents -> Any? #120

Open
aiden-leong opened this issue Jun 16, 2024 · 3 comments
Open

missing CALayer.contents -> Any? #120

aiden-leong opened this issue Jun 16, 2024 · 3 comments

Comments

@aiden-leong
Copy link

Apple Docs: https://developer.apple.com/documentation/quartzcore/calayer/1410773-contents

var contents: Any? { get set }

Further, one possible type it accepts is IOSurface which is NOT included in this repo.

Ref: https://developer.apple.com/documentation/iosurface

Maybe we can create another binding repo for IOSurface.framework?

@aiden-leong
Copy link
Author

BTW: Do you have Discord/Telegram channels for discussion?

@ryanmcgrath
Copy link
Owner

Do you have more info on what you're trying to accomplish? e.g is this for a bare CALayer you own or a CALayer backing an NSView?

Since the objc property of CALayer is exposed publicly, you can message it directly with objc calls (e.g let _: () = msg_send![my_view.layer.id, surface];). You of course need to handle the lifetimes and safety yourself, but this is one of those territories where it's the preferred way of doing it at the moment.

If you wind up finding a more comfortable API and/or you want to buff the CALayer wrapper to be more comprehensive, a pull request is always welcome. I wouldn't pull IOSurface into this framework necessarily, similar to how Metal isn't really in here either (though other crates exist for it). In general I just try to make it possible for crates to interop via the objc layer if possible.

I considered making a channel on Matrix at one point, but the level of activity here isn't so significant that it's needed.

@aiden-leong
Copy link
Author

Do you have more info on what you're trying to accomplish? e.g is this for a bare CALayer you own or a CALayer backing an NSView?

Yes. I'm trying to rewrite a demo from Apple. (You'll need to download the .zip file.)
https://developer.apple.com/documentation/screencapturekit/capturing_screen_content_in_macos

contentLayer.contents = frame.surface is the final step that put a CapturedFrame on an NSView so we can see it on the screen. (It's an OBS-like app.)

Since the objc property of CALayer is exposed publicly, you can message it directly with objc calls (e.g let _: () = msg_send![my_view.layer.id, surface];). You of course need to handle the lifetimes and safety yourself, but this is one of those territories where it's the preferred way of doing it at the moment.

Great. I didn't find the correct way to call msg_send, now I do. I'll have a try if I can handle the lifetimes.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants