Set up main thread dispatcher required for WGL GLContext sharing in Windows, r=emilio

This commit is contained in:
Imanol Fernandez 2016-10-20 23:56:23 +02:00
parent 77dd618e7a
commit b1b074e988
2 changed files with 31 additions and 0 deletions

View file

@ -354,6 +354,17 @@ impl webrender_traits::RenderNotifier for RenderNotifier {
}
}
// Used to dispatch functions from webrender to the main thread's event loop.
struct CompositorThreadDispatcher {
compositor_proxy: Box<CompositorProxy>
}
impl webrender_traits::RenderDispatcher for CompositorThreadDispatcher {
fn dispatch(&self, f: Box<Fn() + Send>) {
self.compositor_proxy.send(Msg::Dispatch(f));
}
}
impl<Window: WindowMethods> IOCompositor<Window> {
fn new(window: Rc<Window>, state: InitialCompositorState)
-> IOCompositor<Window> {
@ -426,6 +437,15 @@ impl<Window: WindowMethods> IOCompositor<Window> {
compositor.constellation_chan.clone());
compositor.webrender.set_render_notifier(Box::new(render_notifier));
if cfg!(target_os = "windows") {
// Used to dispatch functions from webrender to the main thread's event loop.
// Required to allow WGL GLContext sharing in Windows.
let dispatcher = Box::new(CompositorThreadDispatcher {
compositor_proxy: compositor.channel_to_self.clone_compositor_proxy()
});
compositor.webrender.set_main_thread_dispatcher(dispatcher);
}
// Set the size of the root layer.
compositor.update_zoom_transform();
@ -642,6 +662,12 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
(Msg::Dispatch(func), ShutdownState::NotShuttingDown) => {
// The functions sent here right now are really dumb, so they can't panic.
// But if we start running more complex code here, we should really catch panic here.
func();
}
// When we are shutting_down, we need to avoid performing operations
// such as Paint that may crash because we have begun tearing down
// the rest of our resources.