Skip to content

Commit

Permalink
Auto merge of #11410 - Ms2ger:script-listener-thread, r=nox
Browse files Browse the repository at this point in the history
Remove the script listener thread.

Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data:
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

Either:
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because refactoring

Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11410)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 25, 2016
2 parents 52f17a8 + e7f75ca commit 1640ade
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 172 deletions.
52 changes: 2 additions & 50 deletions components/compositing/compositor_thread.rs
Expand Up @@ -9,13 +9,13 @@ use compositor::{self, CompositingReason};
use euclid::point::Point2D;
use euclid::size::Size2D;
use gfx_traits::{Epoch, FrameTreeId, LayerId, LayerProperties, PaintListener};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::ipc::IpcSender;
use layers::layers::{BufferRequest, LayerBufferSet};
use layers::platform::surface::{NativeDisplay, NativeSurface};
use msg::constellation_msg::{Image, Key, KeyModifiers, KeyState, PipelineId};
use profile_traits::mem;
use profile_traits::time;
use script_traits::{AnimationState, ConstellationMsg, EventResult, ScriptToCompositorMsg};
use script_traits::{AnimationState, ConstellationMsg, EventResult};
use std::fmt::{Debug, Error, Formatter};
use std::rc::Rc;
use std::sync::mpsc::{Receiver, Sender, channel};
Expand Down Expand Up @@ -55,54 +55,6 @@ impl CompositorReceiver for Receiver<Msg> {
}
}

pub fn run_script_listener_thread(compositor_proxy: Box<CompositorProxy + 'static + Send>,
receiver: IpcReceiver<ScriptToCompositorMsg>) {
while let Ok(msg) = receiver.recv() {
match msg {
ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point, smooth) => {
compositor_proxy.send(Msg::ScrollFragmentPoint(pipeline_id,
layer_id,
point,
smooth));
}

ScriptToCompositorMsg::GetClientWindow(send) => {
compositor_proxy.send(Msg::GetClientWindow(send));
}

ScriptToCompositorMsg::MoveTo(point) => {
compositor_proxy.send(Msg::MoveTo(point));
}

ScriptToCompositorMsg::ResizeTo(size) => {
compositor_proxy.send(Msg::ResizeTo(size));
}

ScriptToCompositorMsg::Exit => {
compositor_proxy.send(Msg::Exit);
}

ScriptToCompositorMsg::SetTitle(pipeline_id, title) => {
compositor_proxy.send(Msg::ChangePageTitle(pipeline_id, title))
}

ScriptToCompositorMsg::SendKeyEvent(key, key_state, key_modifiers) => {
compositor_proxy.send(Msg::KeyEvent(key, key_state, key_modifiers))
}

ScriptToCompositorMsg::TouchEventProcessed(result) => {
compositor_proxy.send(Msg::TouchEventProcessed(result))
}

ScriptToCompositorMsg::GetScrollOffset(pid, lid, send) => {
compositor_proxy.send(Msg::GetScrollOffset(pid, lid, send));
}

ScriptToCompositorMsg::Exited => break,
}
}
}

pub trait RenderListener {
fn recomposite(&mut self, reason: CompositingReason);
}
Expand Down
47 changes: 42 additions & 5 deletions components/constellation/constellation.rs
Expand Up @@ -423,7 +423,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
initial_window_size: Option<TypedSize2D<PagePx, f32>>,
script_channel: Option<IpcSender<ConstellationControlMsg>>,
load_data: LoadData) {
let spawning_paint_only = script_channel.is_some();
let spawning_content = script_channel.is_none();
let (pipeline, unprivileged_pipeline_content, privileged_pipeline_content) =
Pipeline::create::<LTF, STF>(InitialPipelineState {
id: pipeline_id,
Expand All @@ -448,11 +448,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
webrender_api_sender: self.webrender_api_sender.clone(),
});

if spawning_paint_only {
privileged_pipeline_content.start_paint_thread();
} else {
privileged_pipeline_content.start_all();
privileged_pipeline_content.start();

if spawning_content {
// Spawn the child process.
//
// Yes, that's all there is to it!
Expand Down Expand Up @@ -812,6 +810,45 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
self.handle_alert(pipeline_id, message, sender);
}

Request::Script(FromScriptMsg::ScrollFragmentPoint(pipeline_id, layer_id, point, smooth)) => {
self.compositor_proxy.send(ToCompositorMsg::ScrollFragmentPoint(pipeline_id,
layer_id,
point,
smooth));
}

Request::Script(FromScriptMsg::GetClientWindow(send)) => {
self.compositor_proxy.send(ToCompositorMsg::GetClientWindow(send));
}

Request::Script(FromScriptMsg::MoveTo(point)) => {
self.compositor_proxy.send(ToCompositorMsg::MoveTo(point));
}

Request::Script(FromScriptMsg::ResizeTo(size)) => {
self.compositor_proxy.send(ToCompositorMsg::ResizeTo(size));
}

Request::Script(FromScriptMsg::Exit) => {
self.compositor_proxy.send(ToCompositorMsg::Exit);
}

Request::Script(FromScriptMsg::SetTitle(pipeline_id, title)) => {
self.compositor_proxy.send(ToCompositorMsg::ChangePageTitle(pipeline_id, title))
}

Request::Script(FromScriptMsg::SendKeyEvent(key, key_state, key_modifiers)) => {
self.compositor_proxy.send(ToCompositorMsg::KeyEvent(key, key_state, key_modifiers))
}

Request::Script(FromScriptMsg::TouchEventProcessed(result)) => {
self.compositor_proxy.send(ToCompositorMsg::TouchEventProcessed(result))
}

Request::Script(FromScriptMsg::GetScrollOffset(pid, lid, send)) => {
self.compositor_proxy.send(ToCompositorMsg::GetScrollOffset(pid, lid, send));
}


// Messages from layout thread

Expand Down
36 changes: 2 additions & 34 deletions components/constellation/pipeline.rs
Expand Up @@ -4,7 +4,6 @@

use compositing::CompositionPipeline;
use compositing::CompositorProxy;
use compositing::compositor_thread;
use compositing::compositor_thread::Msg as CompositorMsg;
use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg};
use euclid::scale_factor::ScaleFactor;
Expand All @@ -24,7 +23,7 @@ use profile_traits::mem as profile_mem;
use profile_traits::time;
use script_traits::{ConstellationControlMsg, InitialScriptState, MozBrowserEvent};
use script_traits::{LayoutControlMsg, LayoutMsg, NewLayoutInfo, ScriptMsg};
use script_traits::{ScriptToCompositorMsg, ScriptThreadFactory, TimerEventRequest};
use script_traits::{ScriptThreadFactory, TimerEventRequest};
use std::collections::HashMap;
use std::mem;
use std::sync::mpsc::{Receiver, Sender, channel};
Expand All @@ -34,7 +33,6 @@ use util::geometry::{PagePx, ViewportPx};
use util::ipc::OptionalIpcSender;
use util::opts::{self, Opts};
use util::prefs::{self, Pref};
use util::thread;
use webrender_traits;

/// A uniquely-identifiable pipeline of script thread, layout thread, and paint thread.
Expand Down Expand Up @@ -128,8 +126,6 @@ impl Pipeline {
.expect("Pipeline layout shutdown chan");
let (pipeline_chan, pipeline_port) = ipc::channel()
.expect("Pipeline main chan");;
let (script_to_compositor_chan, script_to_compositor_port) = ipc::channel()
.expect("Pipeline script to compositor chan");

let window_size = state.window_size.map(|size| {
WindowSizeData {
Expand Down Expand Up @@ -223,7 +219,6 @@ impl Pipeline {
pipeline_port: pipeline_port,
layout_shutdown_chan: layout_shutdown_chan,
paint_shutdown_chan: paint_shutdown_chan.clone(),
script_to_compositor_chan: script_to_compositor_chan,
pipeline_namespace_id: state.pipeline_namespace_id,
layout_content_process_shutdown_chan: layout_content_process_shutdown_chan,
layout_content_process_shutdown_port: layout_content_process_shutdown_port,
Expand All @@ -244,7 +239,6 @@ impl Pipeline {
chrome_to_paint_chan: chrome_to_paint_chan,
chrome_to_paint_port: chrome_to_paint_port,
paint_shutdown_chan: paint_shutdown_chan,
script_to_compositor_port: script_to_compositor_port,
};

(pipeline, unprivileged_pipeline_content, privileged_pipeline_content)
Expand Down Expand Up @@ -380,7 +374,6 @@ pub struct UnprivilegedPipelineContent {
layout_to_constellation_chan: IpcSender<LayoutMsg>,
scheduler_chan: IpcSender<TimerEventRequest>,
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
script_to_compositor_chan: IpcSender<ScriptToCompositorMsg>,
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
image_cache_thread: ImageCacheThread,
font_cache_thread: FontCacheThread,
Expand Down Expand Up @@ -414,7 +407,6 @@ impl UnprivilegedPipelineContent {
let layout_pair = STF::create(InitialScriptState {
id: self.id,
parent_info: self.parent_info,
compositor: self.script_to_compositor_chan,
control_chan: self.script_chan.clone(),
control_port: mem::replace(&mut self.script_port, None).expect("No script port."),
constellation_chan: self.constellation_chan.clone(),
Expand Down Expand Up @@ -467,7 +459,6 @@ impl UnprivilegedPipelineContent {
pub struct PrivilegedPipelineContent {
id: PipelineId,
compositor_proxy: Box<CompositorProxy + Send + 'static>,
script_to_compositor_port: IpcReceiver<ScriptToCompositorMsg>,
font_cache_thread: FontCacheThread,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: profile_mem::ProfilerChan,
Expand All @@ -480,30 +471,7 @@ pub struct PrivilegedPipelineContent {
}

impl PrivilegedPipelineContent {
pub fn start_all(self) {
PaintThread::create(self.id,
self.load_data.url,
self.chrome_to_paint_chan,
self.layout_to_paint_port,
self.chrome_to_paint_port,
self.compositor_proxy.clone_compositor_proxy(),
self.panic_chan,
self.font_cache_thread,
self.time_profiler_chan,
self.mem_profiler_chan,
self.paint_shutdown_chan);

let compositor_proxy_for_script_listener_thread =
self.compositor_proxy.clone_compositor_proxy();
let script_to_compositor_port = self.script_to_compositor_port;
thread::spawn_named("CompositorScriptListener".to_owned(), move || {
compositor_thread::run_script_listener_thread(
compositor_proxy_for_script_listener_thread,
script_to_compositor_port)
});
}

pub fn start_paint_thread(self) {
pub fn start(self) {
PaintThread::create(self.id,
self.load_data.url,
self.chrome_to_paint_chan,
Expand Down
16 changes: 8 additions & 8 deletions components/script/dom/document.rs
Expand Up @@ -106,8 +106,8 @@ use parse::{ParserRoot, ParserRef, MutNullableParserField};
use script_thread::{MainThreadScriptMsg, Runnable};
use script_traits::UntrustedNodeAddress;
use script_traits::{AnimationState, MouseButton, MouseEventType, MozBrowserEvent};
use script_traits::{ScriptMsg as ConstellationMsg, ScriptToCompositorMsg};
use script_traits::{TouchpadPressurePhase, TouchEventType, TouchId};
use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase};
use script_traits::{TouchEventType, TouchId};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::boxed::FnBox;
Expand Down Expand Up @@ -636,10 +636,10 @@ impl Document {
/// Sends this document's title to the compositor.
pub fn send_title_to_compositor(&self) {
let window = self.window();
let compositor = window.compositor();
compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(),
Some(String::from(self.Title()))))
.unwrap();
window.constellation_chan()
.send(ConstellationMsg::SetTitle(window.pipeline(),
Some(String::from(self.Title()))))
.unwrap();
}

pub fn dirty_all_nodes(&self) {
Expand Down Expand Up @@ -1049,7 +1049,7 @@ impl Document {
key: Key,
state: KeyState,
modifiers: KeyModifiers,
compositor: &IpcSender<ScriptToCompositorMsg>) {
constellation: &IpcSender<ConstellationMsg>) {
let focused = self.get_focused_element();
let body = self.GetBody();

Expand Down Expand Up @@ -1124,7 +1124,7 @@ impl Document {
}

if !prevented {
compositor.send(ScriptToCompositorMsg::SendKeyEvent(key, state, modifiers)).unwrap();
constellation.send(ConstellationMsg::SendKeyEvent(key, state, modifiers)).unwrap();
}

// This behavior is unspecced
Expand Down
22 changes: 7 additions & 15 deletions components/script/dom/window.rs
Expand Up @@ -62,7 +62,7 @@ use script_runtime::{ScriptChan, ScriptPort};
use script_thread::SendableMainThreadScriptChan;
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper};
use script_traits::{ConstellationControlMsg, UntrustedNodeAddress};
use script_traits::{DocumentState, MsDuration, ScriptToCompositorMsg, TimerEvent, TimerEventId};
use script_traits::{DocumentState, MsDuration, TimerEvent, TimerEventId};
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest, TimerSource};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
Expand Down Expand Up @@ -153,8 +153,6 @@ pub struct Window {
image_cache_chan: ImageCacheChan,
#[ignore_heap_size_of = "channels are hard"]
custom_message_chan: IpcSender<CustomResponseSender>,
#[ignore_heap_size_of = "TODO(#6911) newtypes containing unmeasurable types are hard"]
compositor: IpcSender<ScriptToCompositorMsg>,
browsing_context: MutNullableHeap<JS<BrowsingContext>>,
performance: MutNullableHeap<JS<Performance>>,
navigation_start: u64,
Expand Down Expand Up @@ -340,10 +338,6 @@ impl Window {
&self.image_cache_thread
}

pub fn compositor(&self) -> &IpcSender<ScriptToCompositorMsg> {
&self.compositor
}

pub fn browsing_context(&self) -> Root<BrowsingContext> {
self.browsing_context.get().unwrap()
}
Expand Down Expand Up @@ -775,7 +769,7 @@ impl WindowMethods for Window {
// Step 1
//TODO determine if this operation is allowed
let size = Size2D::new(x.to_u32().unwrap_or(1), y.to_u32().unwrap_or(1));
self.compositor.send(ScriptToCompositorMsg::ResizeTo(size)).unwrap()
self.constellation_chan.send(ConstellationMsg::ResizeTo(size)).unwrap()
}

// https://drafts.csswg.org/cssom-view/#dom-window-resizeby
Expand All @@ -790,7 +784,7 @@ impl WindowMethods for Window {
// Step 1
//TODO determine if this operation is allowed
let point = Point2D::new(x, y);
self.compositor.send(ScriptToCompositorMsg::MoveTo(point)).unwrap()
self.constellation_chan.send(ConstellationMsg::MoveTo(point)).unwrap()
}

// https://drafts.csswg.org/cssom-view/#dom-window-moveby
Expand Down Expand Up @@ -976,13 +970,13 @@ impl Window {
let size = self.current_viewport.get().size;
self.current_viewport.set(Rect::new(Point2D::new(Au::from_f32_px(x), Au::from_f32_px(y)), size));

self.compositor.send(ScriptToCompositorMsg::ScrollFragmentPoint(
self.pipeline(), layer_id, point, smooth)).unwrap()
let message = ConstellationMsg::ScrollFragmentPoint(self.pipeline(), layer_id, point, smooth);
self.constellation_chan.send(message).unwrap();
}

pub fn client_window(&self) -> (Size2D<u32>, Point2D<i32>) {
let (send, recv) = ipc::channel::<(Size2D<u32>, Point2D<i32>)>().unwrap();
self.compositor.send(ScriptToCompositorMsg::GetClientWindow(send)).unwrap();
self.constellation_chan.send(ConstellationMsg::GetClientWindow(send)).unwrap();
recv.recv().unwrap_or((Size2D::zero(), Point2D::zero()))
}

Expand Down Expand Up @@ -1180,7 +1174,7 @@ impl Window {
let pipeline_id = self.id;

let (send, recv) = ipc::channel::<Point2D<f32>>().unwrap();
self.compositor.send(ScriptToCompositorMsg::GetScrollOffset(pipeline_id, layer_id, send)).unwrap();
self.constellation_chan.send(ConstellationMsg::GetScrollOffset(pipeline_id, layer_id, send)).unwrap();
recv.recv().unwrap_or(Point2D::zero())
}

Expand Down Expand Up @@ -1450,7 +1444,6 @@ impl Window {
file_task_source: FileReadingTaskSource,
image_cache_chan: ImageCacheChan,
custom_message_chan: IpcSender<CustomResponseSender>,
compositor: IpcSender<ScriptToCompositorMsg>,
image_cache_thread: ImageCacheThread,
resource_threads: ResourceThreads,
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
Expand Down Expand Up @@ -1490,7 +1483,6 @@ impl Window {
custom_message_chan: custom_message_chan,
console: Default::default(),
crypto: Default::default(),
compositor: compositor,
navigator: Default::default(),
image_cache_thread: image_cache_thread,
mem_profiler_chan: mem_profiler_chan,
Expand Down

0 comments on commit 1640ade

Please sign in to comment.