From 9dc5689eef87cace5e6ac6b5438928a1c99688c4 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 17 Dec 2014 14:49:11 +1000 Subject: 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. --- src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 9ba3e13..029b576 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { -- cgit v1.2.3