Skip to content

Commit bbdf4b6

Browse files
committed
Enable off-main-thread rendering on macOS
In servo/webrender#1640 we discussed how Firefox (and probably also other browsers) have a compositor thread, which is not the main thread, that does all their OpenGL calls. In glutin this kind of architecture doesn't seem to be possible right now since it's not possible to split the `GlWindow` into the window and the context, and the `Context` doesn't implement `Send` on macOS. The following two changes allow such architectures: - Implement `Send` for `Context` on macOS. The Apple docs suggest that this is correct. - Add a `split` method to `GlWindow` that allows obtaining an owned `Window` and `Context`.
1 parent c477436 commit bbdf4b6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ impl GlWindow {
335335
pub fn context(&self) -> &Context {
336336
&self.context
337337
}
338+
339+
pub fn split(self) -> (Window, Context) {
340+
(self.window, self.context)
341+
}
338342
}
339343

340344
impl GlContext for Context {

src/platform/macos/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ pub struct Context {
3737
pixel_format: PixelFormat,
3838
}
3939

40+
/// according to https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html
41+
/// it is safe to use an `NSOpenGLContext` from multiple threads provided only one thread does so at a time.
42+
unsafe impl Send for Context {}
43+
4044
impl Context {
4145

4246
pub fn new(

0 commit comments

Comments
 (0)