mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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.
This commit is contained in:
parent
2947d78e4e
commit
e841065351
14 changed files with 211 additions and 82 deletions
|
@ -7,6 +7,7 @@ use constellation_msg::{Key, KeyState, KeyModifiers};
|
|||
use euclid::point::Point2D;
|
||||
use euclid::rect::Rect;
|
||||
use euclid::Matrix4;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use layers::platform::surface::NativeDisplay;
|
||||
use layers::layers::{BufferRequest, LayerBufferSet};
|
||||
use std::fmt::{Formatter, Debug};
|
||||
|
@ -35,7 +36,7 @@ impl FrameTreeId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Copy, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize)]
|
||||
pub struct LayerId(pub usize, pub u32);
|
||||
|
||||
impl Debug for LayerId {
|
||||
|
@ -115,16 +116,47 @@ pub trait PaintListener {
|
|||
fn notify_paint_task_exiting(&mut self, pipeline_id: PipelineId);
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum ScriptToCompositorMsg {
|
||||
ScrollFragmentPoint(PipelineId, LayerId, Point2D<f32>),
|
||||
SetTitle(PipelineId, Option<String>),
|
||||
SendKeyEvent(Key, KeyState, KeyModifiers),
|
||||
Exit,
|
||||
}
|
||||
|
||||
/// The interface used by the script task to tell the compositor to update its ready state,
|
||||
/// which is used in displaying the appropriate message in the window's title.
|
||||
pub trait ScriptListener {
|
||||
fn scroll_fragment_point(&mut self,
|
||||
pipeline_id: PipelineId,
|
||||
layer_id: LayerId,
|
||||
point: Point2D<f32>);
|
||||
/// Informs the compositor that the title of the page with the given pipeline ID has changed.
|
||||
fn set_title(&mut self, pipeline_id: PipelineId, new_title: Option<String>);
|
||||
fn close(&mut self);
|
||||
fn dup(&mut self) -> Box<ScriptListener+'static>;
|
||||
fn send_key_event(&mut self, key: Key, state: KeyState, modifiers: KeyModifiers);
|
||||
#[derive(Clone)]
|
||||
pub struct ScriptListener(IpcSender<ScriptToCompositorMsg>);
|
||||
|
||||
impl ScriptListener {
|
||||
pub fn new(sender: IpcSender<ScriptToCompositorMsg>) -> ScriptListener {
|
||||
ScriptListener(sender)
|
||||
}
|
||||
|
||||
pub fn scroll_fragment_point(&mut self,
|
||||
pipeline_id: PipelineId,
|
||||
layer_id: LayerId,
|
||||
point: Point2D<f32>) {
|
||||
self.0
|
||||
.send(ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
self.0.send(ScriptToCompositorMsg::Exit).unwrap()
|
||||
}
|
||||
|
||||
pub fn dup(&mut self) -> ScriptListener {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
pub fn set_title(&mut self, pipeline_id: PipelineId, title: Option<String>) {
|
||||
self.0.send(ScriptToCompositorMsg::SetTitle(pipeline_id, title)).unwrap()
|
||||
}
|
||||
|
||||
pub fn send_key_event(&mut self, key: Key, state: KeyState, modifiers: KeyModifiers) {
|
||||
self.0.send(ScriptToCompositorMsg::SendKeyEvent(key, state, modifiers)).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue