Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compositing: Make `ScriptListener` and `LayoutControlChan` messages go over IPC. #6596

Merged
merged 2 commits into from Jul 14, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -52,6 +52,9 @@ git = "https://github.com/servo/rust-png"
[dependencies.clipboard]
git = "https://github.com/aweinstock314/rust-clipboard"

[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"

[dependencies]
log = "*"
num = "0.1.24"
@@ -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))
}
}
}
}

@@ -19,6 +19,7 @@ use euclid::rect::{Rect, TypedRect};
use euclid::size::Size2D;
use euclid::scale_factor::ScaleFactor;
use gfx::font_cache_task::FontCacheTask;
use ipc_channel::ipc;
use layout_traits::{LayoutControlChan, LayoutControlMsg, LayoutTaskFactory};
use libc;
use msg::compositor_msg::{Epoch, LayerId};
@@ -1128,7 +1129,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// epoch matches what the compositor has drawn. If they match
// (and script is idle) then this pipeline won't change again
// and can be considered stable.
let (sender, receiver) = channel();
let (sender, receiver) = ipc::channel().unwrap();
let LayoutControlChan(ref layout_chan) = pipeline.layout_chan;
layout_chan.send(LayoutControlMsg::GetCurrentEpoch(sender)).unwrap();
let layout_task_epoch = receiver.recv().unwrap();
@@ -14,6 +14,7 @@ extern crate azure;
extern crate devtools_traits;
extern crate euclid;
extern crate gfx;
extern crate ipc_channel;
extern crate layers;
extern crate layout_traits;
extern crate png;
@@ -7,13 +7,16 @@ use layout_traits::{LayoutControlMsg, LayoutTaskFactory, LayoutControlChan};
use script_traits::{ScriptControlChan, ScriptTaskFactory};
use script_traits::{NewLayoutInfo, ConstellationControlMsg};

use compositor_task;
use devtools_traits::DevtoolsControlChan;
use euclid::rect::{TypedRect};
use euclid::scale_factor::ScaleFactor;
use gfx::paint_task::Msg as PaintMsg;
use gfx::paint_task::{PaintChan, PaintTask};
use gfx::font_cache_task::FontCacheTask;
use ipc_channel::ipc;
use layers::geometry::DevicePixel;
use msg::compositor_msg::ScriptListener;
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType, MozBrowserEvent};
use profile_traits::mem;
@@ -22,6 +25,7 @@ use net_traits::ResourceTask;
use net_traits::image_cache_task::ImageCacheTask;
use net_traits::storage_task::StorageTask;
use std::sync::mpsc::{Receiver, channel};
use std::thread;
use url::Url;
use util::geometry::{PagePx, ViewportPx};
use util::opts;
@@ -81,7 +85,7 @@ impl Pipeline {
let (paint_port, paint_chan) = PaintChan::new();
let (paint_shutdown_chan, paint_shutdown_port) = channel();
let (layout_shutdown_chan, layout_shutdown_port) = channel();
let (pipeline_chan, pipeline_port) = channel();
let (pipeline_chan, pipeline_port) = ipc::channel().unwrap();

let failure = Failure {
pipeline_id: id,
@@ -91,6 +95,8 @@ impl Pipeline {
let script_chan = match script_chan {
None => {
let (script_chan, script_port) = channel();
let (script_to_compositor_chan, script_to_compositor_port) =
ipc::channel().unwrap();

let window_size = window_rect.map(|rect| {
WindowSizeData {
@@ -100,10 +106,18 @@ impl Pipeline {
}
});

let compositor_proxy_for_script_listener_thread =
compositor_proxy.clone_compositor_proxy();
thread::spawn(move || {
compositor_task::run_script_listener_thread(
compositor_proxy_for_script_listener_thread,
script_to_compositor_port)
});

ScriptTaskFactory::create(None::<&mut STF>,
id,
parent_info,
compositor_proxy.clone_compositor_proxy(),
ScriptListener::new(script_to_compositor_chan),
&layout_pair,
ScriptControlChan(script_chan.clone()),
script_port,
@@ -55,6 +55,9 @@ git = "https://github.com/servo/rust-selectors"
[dependencies.clock_ticks]
git = "https://github.com/tomaka/clock_ticks"

[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"

[dependencies]
log = "*"
encoding = "0.2"
@@ -39,6 +39,7 @@ use gfx::display_list::StackingContext;
use gfx::font_cache_task::FontCacheTask;
use gfx::paint_task::Msg as PaintMsg;
use gfx::paint_task::{PaintChan, PaintLayer};
use ipc_channel::ipc::IpcReceiver;
use layout_traits::{LayoutControlMsg, LayoutTaskFactory};
use log;
use msg::compositor_msg::{Epoch, ScrollPolicy, LayerId};
@@ -65,6 +66,7 @@ use std::mem::transmute;
use std::ops::{Deref, DerefMut};
use std::sync::mpsc::{channel, Sender, Receiver, Select};
use std::sync::{Arc, Mutex, MutexGuard};
use std::thread;
use style::computed_values::{filter, mix_blend_mode};
use style::media_queries::{MediaType, MediaQueryList, Device};
use style::selector_matching::Stylist;
@@ -155,7 +157,7 @@ pub struct LayoutTask {
/// The port on which we receive messages from the script task.
pub port: Receiver<Msg>,

/// The port on which we receive messages from the constellation
/// The port on which we receive messages from the constellation.
pub pipeline_port: Receiver<LayoutControlMsg>,

/// The port on which we receive messages from the image cache
@@ -213,7 +215,7 @@ impl LayoutTaskFactory for LayoutTask {
url: Url,
is_iframe: bool,
chan: OpaqueScriptLayoutChannel,
pipeline_port: Receiver<LayoutControlMsg>,
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: ConstellationChan,
failure_msg: Failure,
script_chan: ScriptControlChan,
@@ -284,7 +286,7 @@ impl LayoutTask {
is_iframe: bool,
port: Receiver<Msg>,
chan: LayoutChan,
pipeline_port: Receiver<LayoutControlMsg>,
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: ConstellationChan,
script_chan: ScriptControlChan,
paint_chan: PaintChan,
@@ -314,12 +316,20 @@ impl LayoutTask {
let (image_cache_sender, image_cache_receiver) = channel();
let (canvas_layers_sender, canvas_layers_receiver) = channel();

// Start a thread to proxy IPC messages from the layout thread to us.
let (pipeline_sender, pipeline_receiver) = channel();
thread::spawn(move || {
while let Ok(message) = pipeline_port.recv() {
pipeline_sender.send(message).unwrap()
}
});

LayoutTask {
id: id,
url: url,
is_iframe: is_iframe,
port: port,
pipeline_port: pipeline_port,
pipeline_port: pipeline_receiver,
chan: chan,
script_chan: script_chan,
constellation_chan: constellation_chan.clone(),
@@ -46,6 +46,7 @@ extern crate fnv;
extern crate euclid;
extern crate gfx;
extern crate gfx_traits;
extern crate ipc_channel;
extern crate layout_traits;
extern crate libc;
extern crate msg;
@@ -25,6 +25,12 @@ path = "../profile_traits"
[dependencies.util]
path = "../util"

[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"

[dependencies]
url = "0.2.35"
euclid = "0.1"
serde = "*"
serde_macros = "*"

@@ -2,12 +2,17 @@
* 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 euclid;
extern crate gfx;
extern crate ipc_channel;
extern crate script_traits;
extern crate msg;
extern crate profile_traits;
extern crate net_traits;
extern crate serde;
extern crate url;
extern crate util;

@@ -19,27 +24,29 @@ extern crate util;
use euclid::rect::Rect;
use gfx::font_cache_task::FontCacheTask;
use gfx::paint_task::PaintChan;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::compositor_msg::{Epoch, LayerId};
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, PipelineExitType};
use profile_traits::mem;
use profile_traits::time;
use net_traits::image_cache_task::ImageCacheTask;
use script_traits::{ScriptControlChan, OpaqueScriptLayoutChannel};
use std::sync::mpsc::{Sender, Receiver};
use std::sync::mpsc::Sender;
use util::geometry::Au;
use url::Url;

/// Messages sent to the layout task from the constellation and/or compositor.
#[derive(Deserialize, Serialize)]
pub enum LayoutControlMsg {
ExitNow(PipelineExitType),
GetCurrentEpoch(Sender<Epoch>),
GetCurrentEpoch(IpcSender<Epoch>),
TickAnimations,
SetVisibleRects(Vec<(LayerId, Rect<Au>)>),
}

/// A channel wrapper for constellation messages
#[derive(Clone)]
pub struct LayoutControlChan(pub Sender<LayoutControlMsg>);
#[derive(Clone, Deserialize, Serialize)]
pub struct LayoutControlChan(pub IpcSender<LayoutControlMsg>);

// A static method creating a layout task
// Here to remove the compositor -> layout dependency
@@ -50,7 +57,7 @@ pub trait LayoutTaskFactory {
url: Url,
is_iframe: bool,
chan: OpaqueScriptLayoutChannel,
pipeline_port: Receiver<LayoutControlMsg>,
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: ConstellationChan,
failure_msg: Failure,
script_chan: ScriptControlChan,
@@ -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 = "*"
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.