Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit ff7bafc

Browse files
committed
servo: Merge #13840 - WebGL support on Windows (from MortimerGoro:webrender_dispatcher); r=emilio
<!-- Please describe your changes on the following line: --> This is the final step to provide WebGL support on Windows ;) Some Related PRs already merged in webrender and offscreen-gl-context: servo/surfman#64 servo/webrender#432 --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ Source-Repo: https://github.com/servo/servo Source-Revision: 4216224f9cc7f3430db2b59f4d77061824ba7a1e
1 parent 98b2f1c commit ff7bafc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

servo/components/compositing/compositor.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ impl webrender_traits::RenderNotifier for RenderNotifier {
354354
}
355355
}
356356

357+
// Used to dispatch functions from webrender to the main thread's event loop.
358+
struct CompositorThreadDispatcher {
359+
compositor_proxy: Box<CompositorProxy>
360+
}
361+
362+
impl webrender_traits::RenderDispatcher for CompositorThreadDispatcher {
363+
fn dispatch(&self, f: Box<Fn() + Send>) {
364+
self.compositor_proxy.send(Msg::Dispatch(f));
365+
}
366+
}
367+
357368
impl<Window: WindowMethods> IOCompositor<Window> {
358369
fn new(window: Rc<Window>, state: InitialCompositorState)
359370
-> IOCompositor<Window> {
@@ -426,6 +437,15 @@ impl<Window: WindowMethods> IOCompositor<Window> {
426437
compositor.constellation_chan.clone());
427438
compositor.webrender.set_render_notifier(Box::new(render_notifier));
428439

440+
if cfg!(target_os = "windows") {
441+
// Used to dispatch functions from webrender to the main thread's event loop.
442+
// Required to allow WGL GLContext sharing in Windows.
443+
let dispatcher = Box::new(CompositorThreadDispatcher {
444+
compositor_proxy: compositor.channel_to_self.clone_compositor_proxy()
445+
});
446+
compositor.webrender.set_main_thread_dispatcher(dispatcher);
447+
}
448+
429449
// Set the size of the root layer.
430450
compositor.update_zoom_transform();
431451

@@ -642,6 +662,12 @@ impl<Window: WindowMethods> IOCompositor<Window> {
642662
}
643663
}
644664

665+
(Msg::Dispatch(func), ShutdownState::NotShuttingDown) => {
666+
// The functions sent here right now are really dumb, so they can't panic.
667+
// But if we start running more complex code here, we should really catch panic here.
668+
func();
669+
}
670+
645671
// When we are shutting_down, we need to avoid performing operations
646672
// such as Paint that may crash because we have begun tearing down
647673
// the rest of our resources.

servo/components/compositing/compositor_thread.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ pub enum Msg {
126126
// sends a reply on the IpcSender, the constellation knows it's safe to
127127
// tear down the other threads associated with this pipeline.
128128
PipelineExited(PipelineId, IpcSender<()>),
129+
/// Runs a closure in the compositor thread.
130+
/// It's used to dispatch functions from webrender to the main thread's event loop.
131+
/// Required to allow WGL GLContext sharing in Windows.
132+
Dispatch(Box<Fn() + Send>)
129133
}
130134

131135
impl Debug for Msg {
@@ -158,6 +162,7 @@ impl Debug for Msg {
158162
Msg::PipelineVisibilityChanged(..) => write!(f, "PipelineVisibilityChanged"),
159163
Msg::PipelineExited(..) => write!(f, "PipelineExited"),
160164
Msg::NewScrollFrameReady(..) => write!(f, "NewScrollFrameReady"),
165+
Msg::Dispatch(..) => write!(f, "Dispatch"),
161166
}
162167
}
163168
}

0 commit comments

Comments
 (0)