-
Notifications
You must be signed in to change notification settings - Fork 69
Use IOSurface on macOS/iOS
#329
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
Open
madsmtm
wants to merge
1
commit into
master
Choose a base branch
from
madsmtm/iosurface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
madsmtm
commented
Jan 31, 2026
Comment on lines
+301
to
+317
| // Block until back buffer is no longer being used by the compositor. | ||
| // | ||
| // TODO: Allow configuring this: https://github.com/rust-windowing/softbuffer/issues/29 | ||
| // TODO: Is this actually the check we want to do? It seems like the compositor doesn't | ||
| // properly set the usage state when the application loses focus, even if you continue | ||
| // rendering there? | ||
| // | ||
| // Should we instead set up a `CVDisplayLink`, and only allow using the back buffer once a | ||
| // certain number of frames have passed since it was presented? Would be better though not | ||
| // perfect, `CVDisplayLink` isn't guaranteed to actually match the display's refresh rate: | ||
| // https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/CoreVideo/CVProg_Concepts/CVProg_Concepts.html#//apple_ref/doc/uid/TP40001536-CH202-DontLinkElementID_2 | ||
| // | ||
| // Another option would be to keep a boundless queue as described in: | ||
| // https://github.com/commercial-emacs/commercial-emacs/blob/68f5a28a316ea0c553d4274ce86e95fc4a5a701a/src/nsterm.m#L10552-L10571 | ||
| while self.back.surface.is_in_use() { | ||
| std::thread::yield_now(); | ||
| } |
Member
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way we wait for the compositor to stop using the buffer(s) here is kinda bad, but that can be resolved later, and shouldn't be a problem for applications that either:
- Only re-render when something changes.
- Do proper frame-pacing (Winit doesn't yet provide that though).
e02da58 to
f1882c5
Compare
This was referenced Jan 31, 2026
f1882c5 to
31f0a29
Compare
Write directly into a shared memory buffer that can be shared directly with the compositor and avoids copying bytes when presenting (QuartzCore was copying stuff before). This also implements double and triple buffering of the surface, to avoid creating a bunch of unnecessary buffers. The compositor seems to sometimes work on two buffers at the same time? A bit unsure why. The way we wait for the compositor to stop using the buffer(s) is kinda bad, but that can be resolved later, and shouldn't be a problem for applications that do proper frame-pacing (which Winit doesn't yet provide though).
31f0a29 to
45b790a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make
Buffer<'_>be backed by a shared memory buffer that can be shared directly with the compositor. This makes the CoreGraphics backend zero-copy (QuartzCore was copying from theCGImageProviderinternally before when committing the transaction).This also implements triple buffering of the surface, to avoid creating a bunch of unnecessary buffers. The compositor seems to want to work on two buffers at the same time? A bit unsure why, but I know that we do get tearing if we try to touch things while it's working on it.
Fixes #83.
This requires #321, because
IOSurfacedoes not support RGBX (so the alpha channel must be opaque to render correctly).Tested on:
Replaces #95 and #96.