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 MacOS (Cgl) make_current_surfaceless() implementation #1710

Merged
merged 3 commits into from
Oct 28, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- Add `PossiblyCurrentContext::make_not_current_in_place(&self)` for when `Send` capability of `NotCurrentContext` is not required.
- Add `NotCurrentContext::make_current_surfaceless(self)` and `PossiblyCurrentContext::make_current_surfaceless(&self)` in the `Cgl` implementation to allow the use of surfaceless contexts on MacOS.

# Version 0.32.1

Expand Down
27 changes: 27 additions & 0 deletions glutin/src/api/cgl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ pub struct NotCurrentContext {
}

impl NotCurrentContext {
/// Make a [`Self::PossiblyCurrentContext`] indicating that the context
/// could be current on the thread.
pub fn make_current_surfaceless(self) -> Result<PossiblyCurrentContext> {
self.inner.make_current_surfaceless()?;
Ok(PossiblyCurrentContext { inner: self.inner, _nosendsync: PhantomData })
}

fn new(inner: ContextInner) -> Self {
Self { inner, _nosync: PhantomData }
}
Expand Down Expand Up @@ -143,6 +150,13 @@ pub struct PossiblyCurrentContext {
_nosendsync: PhantomData<*mut ()>,
}

impl PossiblyCurrentContext {
/// Make this context current on the calling thread.
pub fn make_current_surfaceless(&self) -> Result<()> {
self.inner.make_current_surfaceless()
}
}

impl PossiblyCurrentGlContext for PossiblyCurrentContext {
type NotCurrentContext = NotCurrentContext;
type Surface<T: SurfaceTypeTrait> = Surface<T>;
Expand Down Expand Up @@ -236,6 +250,19 @@ impl ContextInner {
})
}

fn make_current_surfaceless(&self) -> Result<()> {
autoreleasepool(|_| {
self.update();
self.raw.makeCurrentContext();
kchibisov marked this conversation as resolved.
Show resolved Hide resolved

run_on_main(|_mtm| unsafe {
self.raw.setView(None);
});

Ok(())
})
}

fn context_api(&self) -> ContextApi {
ContextApi::OpenGl(None)
}
Expand Down
Loading