aboutsummaryrefslogtreecommitdiffstats
path: root/components/compositing/compositor_task.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2015-07-10 18:08:03 -0700
committerPatrick Walton <pcwalton@mimiga.net>2015-07-14 12:12:19 -0700
commite84106535175211526729e532058a7514a0de372 (patch)
tree40605bb1daa46f8ebffd5200756077c969656a9c /components/compositing/compositor_task.rs
parent2947d78e4e0e7940b86e9fbdaa784ebbd28740f4 (diff)
downloadservo-e84106535175211526729e532058a7514a0de372.tar.gz
servo-e84106535175211526729e532058a7514a0de372.zip
compositing: Move messages that go over the `ScriptListener` to go over
an IPC channel instead. Because this used a boxed trait object to invoke messages across a process boundary, and boxed trait objects are not supported across IPC, we spawn a helper thread inside the compositor to perform the marshaling for us.
Diffstat (limited to 'components/compositing/compositor_task.rs')
-rw-r--r--components/compositing/compositor_task.rs44
1 files changed, 21 insertions, 23 deletions
diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs
index 15e5f59f513..d8ada04bbdf 100644
--- a/components/compositing/compositor_task.rs
+++ b/components/compositing/compositor_task.rs
@@ -13,10 +13,11 @@ use windowing::{WindowEvent, WindowMethods};
use euclid::point::Point2D;
use euclid::rect::Rect;
+use ipc_channel::ipc::IpcReceiver;
use layers::platform::surface::NativeDisplay;
use layers::layers::{BufferRequest, LayerBuffer, LayerBufferSet};
use msg::compositor_msg::{Epoch, LayerId, LayerProperties, FrameTreeId};
-use msg::compositor_msg::{PaintListener, ScriptListener};
+use msg::compositor_msg::{PaintListener, ScriptToCompositorMsg};
use msg::constellation_msg::{AnimationState, ConstellationChan, PipelineId};
use msg::constellation_msg::{Key, KeyState, KeyModifiers};
use profile_traits::mem;
@@ -61,31 +62,28 @@ impl CompositorReceiver for Receiver<Msg> {
}
}
-/// Implementation of the abstract `ScriptListener` interface.
-impl ScriptListener for Box<CompositorProxy+'static+Send> {
- fn scroll_fragment_point(&mut self,
- pipeline_id: PipelineId,
- layer_id: LayerId,
- point: Point2D<f32>) {
- self.send(Msg::ScrollFragmentPoint(pipeline_id, layer_id, point));
- }
-
- fn close(&mut self) {
- let (chan, port) = channel();
- self.send(Msg::Exit(chan));
- port.recv().unwrap();
- }
+pub fn run_script_listener_thread(mut compositor_proxy: Box<CompositorProxy + 'static + Send>,
+ receiver: IpcReceiver<ScriptToCompositorMsg>) {
+ while let Ok(msg) = receiver.recv() {
+ match msg {
+ ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point) => {
+ compositor_proxy.send(Msg::ScrollFragmentPoint(pipeline_id, layer_id, point));
+ }
- fn dup(&mut self) -> Box<ScriptListener+'static> {
- box self.clone_compositor_proxy() as Box<ScriptListener+'static>
- }
+ ScriptToCompositorMsg::Exit => {
+ let (chan, port) = channel();
+ compositor_proxy.send(Msg::Exit(chan));
+ port.recv().unwrap();
+ }
- fn set_title(&mut self, pipeline_id: PipelineId, title: Option<String>) {
- self.send(Msg::ChangePageTitle(pipeline_id, title))
- }
+ ScriptToCompositorMsg::SetTitle(pipeline_id, title) => {
+ compositor_proxy.send(Msg::ChangePageTitle(pipeline_id, title))
+ }
- fn send_key_event(&mut self, key: Key, state: KeyState, modifiers: KeyModifiers) {
- self.send(Msg::KeyEvent(key, state, modifiers));
+ ScriptToCompositorMsg::SendKeyEvent(key, key_state, key_modifiers) => {
+ compositor_proxy.send(Msg::KeyEvent(key, key_state, key_modifiers))
+ }
+ }
}
}