aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/main/engine.rs27
-rwxr-xr-xsrc/components/main/servo.rc5
-rw-r--r--src/components/net/util.rs10
-rw-r--r--src/components/script/engine_interface.rs17
-rw-r--r--src/components/script/script.rc1
-rw-r--r--src/components/script/script_task.rs11
-rw-r--r--src/components/util/time.rs53
7 files changed, 74 insertions, 50 deletions
diff --git a/src/components/main/engine.rs b/src/components/main/engine.rs
index 6dd245214c8..6458876c8b6 100644
--- a/src/components/main/engine.rs
+++ b/src/components/main/engine.rs
@@ -4,13 +4,13 @@
use compositing::CompositorTask;
use layout::layout_task;
-use util::task::spawn_listener;
use core::cell::Cell;
-use core::comm::{Chan, Port, SharedChan};
+use core::comm::{Port, SharedChan};
use gfx::opts::Opts;
use gfx::render_task::RenderTask;
use gfx::render_task;
+use script::engine_interface::{EngineTask, ExitMsg, LoadUrlMsg, Msg};
use script::layout_interface::LayoutTask;
use script::layout_interface;
use script::script_task::{ExecuteMsg, LoadMsg, ScriptMsg, ScriptTask};
@@ -18,15 +18,7 @@ use script::script_task;
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use servo_net::resource_task::ResourceTask;
use servo_net::resource_task;
-use servo_util::time::{profiler_force_print, ProfilerChan, ProfilerPort, ProfilerTask};
-use std::net::url::Url;
-
-pub type EngineTask = Chan<Msg>;
-
-pub enum Msg {
- LoadUrlMsg(Url),
- ExitMsg(Chan<()>),
-}
+use servo_util::time::{ProfilerChan, ProfilerPort, ProfilerTask, ForcePrintMsg};
pub struct Engine {
request_port: Port<Msg>,
@@ -41,7 +33,7 @@ pub struct Engine {
impl Drop for Engine {
fn finalize(&self) {
- profiler_force_print(self.profiler_task.chan.clone());
+ self.profiler_task.chan.send(ForcePrintMsg);
}
}
@@ -56,10 +48,13 @@ impl Engine {
profiler_chan: ProfilerChan)
-> EngineTask {
let (script_port, script_chan) = (Cell(script_port), Cell(script_chan));
+ let (request_port, request_chan) = comm::stream();
+ let (request_port, request_chan) = (Cell(request_port), SharedChan::new(request_chan));
+ let request_chan_clone = request_chan.clone();
let profiler_port = Cell(profiler_port);
let opts = Cell(copy *opts);
- do spawn_listener::<Msg> |request| {
+ do task::spawn {
let render_task = RenderTask::new(compositor.clone(),
opts.with_ref(|o| copy *o),
profiler_chan.clone());
@@ -77,13 +72,14 @@ impl Engine {
let script_task = ScriptTask::new(script_port.take(),
script_chan.take(),
+ request_chan_clone.clone(),
layout_task.clone(),
resource_task.clone(),
image_cache_task.clone());
Engine {
- request_port: request,
+ request_port: request_port.take(),
compositor: compositor.clone(),
render_task: render_task,
resource_task: resource_task.clone(),
@@ -91,8 +87,9 @@ impl Engine {
layout_task: layout_task,
script_task: script_task,
profiler_task: profiler_task,
- }.run()
+ }.run();
}
+ request_chan.clone()
}
fn run(&self) {
diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc
index 50a599a0634..b092d4b30a6 100755
--- a/src/components/main/servo.rc
+++ b/src/components/main/servo.rc
@@ -34,7 +34,8 @@ extern mod core_graphics;
extern mod core_text;
use compositing::CompositorTask;
-use engine::{Engine, LoadUrlMsg};
+use engine::Engine;
+use script::engine_interface::{ExitMsg, LoadUrlMsg};
use core::comm::SharedChan;
use gfx::opts;
@@ -121,7 +122,7 @@ fn run(opts: &Opts) {
// Shut the engine down.
debug!("master: Shut down");
let (exit_response_from_engine, exit_chan) = comm::stream();
- engine_task.send(engine::ExitMsg(exit_chan));
+ engine_task.send(ExitMsg(exit_chan));
exit_response_from_engine.recv();
}
diff --git a/src/components/net/util.rs b/src/components/net/util.rs
index ec1aea92e86..cd8a177a7ef 100644
--- a/src/components/net/util.rs
+++ b/src/components/net/util.rs
@@ -5,11 +5,11 @@
use core::comm::{Chan, Port};
pub fn spawn_listener<A: Owned>(f: ~fn(Port<A>)) -> Chan<A> {
- let (setup_po, setup_ch) = comm::stream();
+ let (setup_port, setup_chan) = comm::stream();
do task::spawn {
- let (po, ch) = comm::stream();
- setup_ch.send(ch);
- f(po);
+ let (port, chan) = comm::stream();
+ setup_chan.send(chan);
+ f(port);
}
- setup_po.recv()
+ setup_port.recv()
}
diff --git a/src/components/script/engine_interface.rs b/src/components/script/engine_interface.rs
new file mode 100644
index 00000000000..2705ebdb137
--- /dev/null
+++ b/src/components/script/engine_interface.rs
@@ -0,0 +1,17 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+//! The high-level interface from script to engine. Using this abstract interface helps reduce
+/// coupling between these two components
+
+use core::comm::{Chan, SharedChan};
+use std::net::url::Url;
+
+pub type EngineTask = SharedChan<Msg>;
+
+pub enum Msg {
+ LoadUrlMsg(Url),
+ ExitMsg(Chan<()>),
+}
+
diff --git a/src/components/script/script.rc b/src/components/script/script.rc
index 0c40fc8aab3..dc303783472 100644
--- a/src/components/script/script.rc
+++ b/src/components/script/script.rc
@@ -65,5 +65,6 @@ pub mod html {
}
pub mod layout_interface;
+pub mod engine_interface;
pub mod script_task;
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index 69a588667c2..716440dfffe 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -16,6 +16,7 @@ use layout_interface::{HitTestResponse, LayoutQuery, LayoutResponse, LayoutTask}
use layout_interface::{MatchSelectorsDocumentDamage, QueryMsg, Reflow, ReflowDocumentDamage};
use layout_interface::{ReflowForDisplay, ReflowForScriptQuery, ReflowGoal, ReflowMsg};
use layout_interface;
+use engine_interface::{EngineTask, LoadUrlMsg};
use core::cast::transmute;
use core::cell::Cell;
@@ -65,6 +66,7 @@ impl ScriptTask {
/// Creates a new script task.
pub fn new(script_port: Port<ScriptMsg>,
script_chan: SharedChan<ScriptMsg>,
+ engine_task: EngineTask,
layout_task: LayoutTask,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask)
@@ -78,6 +80,7 @@ impl ScriptTask {
let script_context = ScriptContext::new(layout_task.clone(),
script_port.take(),
script_chan_copy.clone(),
+ engine_task.clone(),
resource_task.clone(),
image_cache_task.clone());
script_context.start();
@@ -117,6 +120,9 @@ pub struct ScriptContext {
/// messages.
script_chan: SharedChan<ScriptMsg>,
+ /// For communicating load url messages to the engine
+ engine_task: EngineTask,
+
/// The JavaScript runtime.
js_runtime: js::rust::rt,
/// The JavaScript context.
@@ -168,6 +174,7 @@ impl ScriptContext {
pub fn new(layout_task: LayoutTask,
script_port: Port<ScriptMsg>,
script_chan: SharedChan<ScriptMsg>,
+ engine_task: EngineTask,
resource_task: ResourceTask,
img_cache_task: ImageCacheTask)
-> @mut ScriptContext {
@@ -191,6 +198,8 @@ impl ScriptContext {
script_port: script_port,
script_chan: script_chan,
+ engine_task: engine_task,
+
js_runtime: js_runtime,
js_context: js_context,
js_compartment: compartment,
@@ -552,7 +561,7 @@ impl ScriptContext {
debug!("clicked on link to %?", attr.value);
let url = from_str(attr.value);
match url {
- Ok(url) => self.script_chan.send(LoadMsg(url)),
+ Ok(url) => self.engine_task.send(LoadUrlMsg(url)),
Err(msg) => debug!(msg)
};
break;
diff --git a/src/components/util/time.rs b/src/components/util/time.rs
index 8d2aceb8abd..c986676ec72 100644
--- a/src/components/util/time.rs
+++ b/src/components/util/time.rs
@@ -8,6 +8,9 @@ use core::cell::Cell;
use core::comm::{Port, SharedChan};
use std::sort::tim_sort;
+pub type ProfilerChan = SharedChan<ProfilerMsg>;
+pub type ProfilerPort = Port<ProfilerMsg>;
+
#[deriving(Eq)]
pub enum ProfilerCategory {
CompositingCategory,
@@ -26,6 +29,29 @@ pub enum ProfilerCategory {
// hackish but helps prevent errors when adding new categories
NUM_BUCKETS,
}
+// FIXME(#5873) this should be initialized by a NUM_BUCKETS cast,
+static BUCKETS: uint = 13;
+
+pub enum ProfilerMsg {
+ // Normal message used for reporting time
+ TimeMsg(ProfilerCategory, f64),
+ // Message used to force print the profiling metrics
+ ForcePrintMsg,
+}
+
+// front-end representation of the profiler used to communicate with the profiler context
+pub struct ProfilerTask {
+ chan: ProfilerChan,
+}
+
+// back end of the profiler that handles data aggregation and performance metrics
+pub struct ProfilerContext {
+ port: ProfilerPort,
+ buckets: ~[(ProfilerCategory, ~[f64])],
+ verbose: bool,
+ period: f64,
+ last_print: f64,
+}
impl ProfilerCategory {
@@ -76,20 +102,6 @@ impl ProfilerCategory {
fmt!("%s%?", padding, self)
}
}
-// FIXME(#5873) this should be initialized by a NUM_BUCKETS cast,
-static BUCKETS: uint = 13;
-
-pub enum ProfilerMsg {
- // Normal message used for reporting time
- TimeMsg(ProfilerCategory, f64),
- // Message used to force print the profiling metrics
- ForcePrintMsg,
-}
-pub type ProfilerChan = SharedChan<ProfilerMsg>;
-pub type ProfilerPort = Port<ProfilerMsg>;
-pub struct ProfilerTask {
- chan: ProfilerChan,
-}
impl ProfilerTask {
pub fn new(profiler_port: ProfilerPort,
@@ -109,14 +121,6 @@ impl ProfilerTask {
}
}
-pub struct ProfilerContext {
- port: ProfilerPort,
- buckets: ~[(ProfilerCategory, ~[f64])],
- verbose: bool,
- period: f64,
- mut last_print: f64,
-}
-
impl ProfilerContext {
pub fn new(port: ProfilerPort, period: Option<f64>) -> ProfilerContext {
let (verbose, period) = match period {
@@ -197,11 +201,6 @@ pub fn profile<T>(category: ProfilerCategory,
return val;
}
-
-pub fn profiler_force_print(profiler_chan: ProfilerChan) {
- profiler_chan.send(ForcePrintMsg);
-}
-
pub fn time<T>(msg: &str, callback: &fn() -> T) -> T{
let start_time = precise_time_ns();
let val = callback();