Introduce a WindowProxy for accessing a subset of functionality

from other threads. This currently provides a way for other threads
to wakeup a blocked event loop on X11. Other platforms have stub
functions that need to be implemented. This is similar to
the functionality of glfwPostEmptyEvent.
This commit is contained in:
Glenn Watson 2014-12-17 14:49:11 +10:00
parent 19d120b8b1
commit 9dc5689eef
8 changed files with 171 additions and 52 deletions

View file

@ -473,6 +473,15 @@ impl Window {
pub fn get_api(&self) -> Api {
self.window.get_api()
}
/// Create a window proxy for this window, that can be freely
/// passed to different threads.
#[inline]
pub fn create_window_proxy(&self) -> WindowProxy {
WindowProxy {
proxy: self.window.create_window_proxy()
}
}
}
#[cfg(feature = "window")]
@ -482,6 +491,28 @@ impl gl_common::GlFunctionsSource for Window {
}
}
/// Represents a thread safe subset of operations that can be called
/// on a window. This structure can be safely cloned and sent between
/// threads.
///
#[cfg(feature = "window")]
#[deriving(Clone)]
pub struct WindowProxy {
proxy: winimpl::WindowProxy,
}
#[cfg(feature = "window")]
impl WindowProxy {
/// Triggers a blocked event loop to wake up. This is
/// typically called when another thread wants to wake
/// up the blocked rendering thread to cause a refresh.
#[inline]
pub fn wakeup_event_loop(&self) {
self.proxy.wakeup_event_loop();
}
}
/// Represents a headless OpenGL context.
#[cfg(feature = "headless")]
pub struct HeadlessContext {