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:
Patrick Walton 2015-07-10 18:08:03 -07:00
parent 2947d78e4e
commit e841065351
14 changed files with 211 additions and 82 deletions

View file

@ -22,12 +22,17 @@ git = "https://github.com/servo/rust-layers"
[dependencies.png]
git = "https://github.com/servo/rust-png"
[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"
[dependencies]
url = "0.2.35"
bitflags = "*"
hyper = "0.5"
rustc-serialize = "0.3.4"
euclid = "0.1"
serde = "*"
serde_macros = "*"
[target.x86_64-apple-darwin.dependencies]
core-foundation = "*"

View file

@ -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()
}
}

View file

@ -57,7 +57,7 @@ pub struct WindowSizeData {
pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>,
}
#[derive(PartialEq, Eq, Copy, Clone)]
#[derive(PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
pub enum KeyState {
Pressed,
Released,
@ -65,7 +65,7 @@ pub enum KeyState {
}
//N.B. Based on the glutin key enum
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
pub enum Key {
Space,
Apostrophe,
@ -191,6 +191,7 @@ pub enum Key {
}
bitflags! {
#[derive(Deserialize, Serialize)]
flags KeyModifiers: u8 {
const NONE = 0x00,
const SHIFT = 0x01,
@ -368,10 +369,10 @@ pub struct FrameId(pub u32);
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug)]
pub struct WorkerId(pub u32);
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
pub struct PipelineId(pub u32);
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
pub struct SubpageId(pub u32);
// The type of pipeline exit. During complete shutdowns, pipelines do not have to

View file

@ -2,13 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
extern crate azure;
#[macro_use] extern crate bitflags;
extern crate euclid;
extern crate hyper;
extern crate ipc_channel;
extern crate layers;
extern crate png;
extern crate rustc_serialize;
extern crate serde;
extern crate util;
extern crate url;
extern crate style;