Conversation
| // 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(); | ||
| } |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
When I run the animation example, it seems to sometimes work, but sometimes get stuck in this loop after the three buffers have been allocated.
e02da58 to
f1882c5
Compare
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
|
Hm. When I try this on an M1 Mac Mini running Tahoe 26.2, I'm not seeing it work correctly. Examples create windows with white contents, except it becomes partly visible if I drag another window over it. But that doesn't show up in a screenshot, which just shows the window white. |
|
It requires #321 (the alpha mode is diff --git a/src/pixel.rs b/src/pixel.rs
index bcc223d..eb08f30 100644
--- a/src/pixel.rs
+++ b/src/pixel.rs
@@ -101,7 +101,7 @@ impl Pixel {
/// ```
pub const fn new_rgb(r: u8, g: u8, b: u8) -> Self {
// FIXME(madsmtm): Change alpha to `0xff` once we support transparency.
- Self { r, g, b, a: 0x00 }
+ Self { r, g, b, a: 0xff }
}
/// Create a new pixel from a blue, a green and a red component. |
|
Idk., I just preferred to wait for #321 (and I won't merge this one before that) |
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.