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

decouple script from compositor, route through layout #517

Merged
merged 5 commits into from Jun 17, 2013
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

refactor compositor interfaces \--> RenderListener + ScriptListener; …

…AttachCompositorMsg added to render_task::Msg

updated to reflect comments
  • Loading branch information
Tim Kuehn
Tim Kuehn committed Jun 17, 2013
commit 577a410f806d991f48c9f350a060aa1aca72eab8
@@ -32,7 +32,7 @@ pub enum RenderState {
RenderingRenderState,
}

/// The interface used to by the renderer to acquire draw targets for each rendered frame and
/// The interface used by the renderer to acquire draw targets for each rendered frame and
/// submit them to be drawn to the display.
pub trait RenderListener {
fn get_gl_context(&self) -> AzGLContext;
@@ -22,31 +22,39 @@ use servo_net::util::spawn_listener;
use servo_util::time::{ProfilerChan, profile};
use servo_util::time;

pub enum Msg {
pub enum Msg<C> {
AttachCompositorMsg(C),
RenderMsg(RenderLayer),
ExitMsg(Chan<()>),
}

#[deriving(Clone)]
pub struct RenderChan {
chan: SharedChan<Msg>,
pub struct RenderChan<C> {
chan: SharedChan<Msg<C>>,
}

impl RenderChan {
pub fn new(chan: Chan<Msg>) -> RenderChan {
impl<C: RenderListener + Owned> Clone for RenderChan<C> {
pub fn clone(&self) -> RenderChan<C> {
RenderChan {
chan: self.chan.clone(),
}
}
}

impl<C: RenderListener + Owned> RenderChan<C> {
pub fn new(chan: Chan<Msg<C>>) -> RenderChan<C> {
RenderChan {
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: Msg) {
pub fn send(&self, msg: Msg<C>) {
self.chan.send(msg);
}
}

pub fn create_render_task<C: RenderListener + Owned>(port: Port<Msg>,
compositor: C,
opts: Opts,
profiler_chan: ProfilerChan) {
pub fn create_render_task<C: RenderListener + Owned>(port: Port<Msg<C>>,
compositor: C,
opts: Opts,
profiler_chan: ProfilerChan) {
let compositor_cell = Cell(compositor);
let opts_cell = Cell(opts);
let port = Cell(port);
@@ -103,7 +111,7 @@ priv struct ThreadRenderContext {
}

priv struct Renderer<C> {
port: Port<Msg>,
port: Port<Msg<C>>,
compositor: C,
thread_pool: TaskPool<ThreadRenderContext>,
opts: Opts,
@@ -120,6 +128,7 @@ impl<C: RenderListener + Owned> Renderer<C> {

loop {
match self.port.recv() {
AttachCompositorMsg(compositor) => self.compositor = compositor,
RenderMsg(render_layer) => self.render(render_layer),
ExitMsg(response_ch) => {
response_ch.send(());
@@ -132,7 +132,7 @@ impl CompositorTask {
}

/// Starts the compositor, which listens for messages on the specified port.
pub fn create_compositor_task(port: Port<Msg>,
pub fn create(port: Port<Msg>,
profiler_chan: ProfilerChan,
shutdown_chan: Chan<()>) {
let port = Cell(port);
@@ -24,20 +24,14 @@ use servo_util::time::{ProfilerChan};
pub struct Engine {
request_port: Port<Msg>,
compositor_chan: CompositorChan,
render_chan: RenderChan,
render_chan: RenderChan<CompositorChan>,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask,
layout_chan: LayoutChan,
script_chan: ScriptChan,
profiler_chan: ProfilerChan,
}

impl Drop for Engine {
fn finalize(&self) {
//self.profiler_chan.send(ForcePrintMsg);
}
}

impl Engine {
pub fn start(compositor_chan: CompositorChan,
opts: &Opts,
@@ -63,7 +57,9 @@ impl Engine {
// Create the layout port and channel.
let (layout_port, layout_chan) = closure_stream!(layout_interface::Msg, LayoutChan);

let (render_port, render_chan) = closure_stream!(render_task::Msg, RenderChan);
let (render_port, render_chan) = comm::stream::<render_task::Msg<CompositorChan>>();
let (render_port, render_chan) = (Cell(render_port), RenderChan::new(render_chan));


compositor_chan.send(SetLayoutChan(layout_chan.clone()));
let compositor_chan = Cell(compositor_chan);
@@ -5,6 +5,7 @@
//! The layout task. Performs layout on the DOM, builds display lists and sends them to be
/// rendered.

use compositing::CompositorChan;
use css::matching::MatchMethods;
use css::select::new_css_select_ctx;
use layout::aux::{LayoutData, LayoutAuxMethods};
@@ -47,7 +48,7 @@ use std::net::url::Url;

pub fn create_layout_task(port: Port<Msg>,
script_chan: ScriptChan,
render_chan: RenderChan,
render_chan: RenderChan<CompositorChan>,
img_cache_task: ImageCacheTask,
opts: Opts,
profiler_chan: ProfilerChan) {
@@ -66,7 +67,7 @@ pub fn create_layout_task(port: Port<Msg>,
struct Layout {
port: Port<Msg>,
script_chan: ScriptChan,
render_chan: RenderChan,
render_chan: RenderChan<CompositorChan>,
image_cache_task: ImageCacheTask,
local_image_cache: @mut LocalImageCache,
font_ctx: @mut FontContext,
@@ -83,7 +84,7 @@ struct Layout {
impl Layout {
fn new(port: Port<Msg>,
script_chan: ScriptChan,
render_chan: RenderChan,
render_chan: RenderChan<CompositorChan>,
image_cache_task: ImageCacheTask,
opts: &Opts,
profiler_chan: ProfilerChan)
@@ -12,7 +12,6 @@ use windowing::{ResizeCallback, ScrollCallback, WindowMethods, WindowMouseEvent,
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent, ZoomCallback};

use alert::{Alert, AlertMethods};
use core::cell::Cell;
use core::libc::c_int;
use geom::point::Point2D;
use geom::size::Size2D;
@@ -93,7 +93,7 @@ fn run(opts: &Opts) {
// Create the profiler channel.
let (profiler_port, profiler_chan) = comm::stream();
let profiler_chan = ProfilerChan::new(profiler_chan);
Profiler::create_profiler(profiler_port);
Profiler::create(profiler_port);
do opts.profiler_period.map |period| {
let profiler_chan = profiler_chan.clone();
let period = *period;
@@ -109,7 +109,7 @@ fn run(opts: &Opts) {
// Create the compositor.
let (compositor_port, compositor_chan) = comm::stream();
let compositor_chan = CompositorChan::new(compositor_chan);
CompositorTask::create_compositor_task(compositor_port, profiler_chan.clone(), shutdown_chan);
CompositorTask::create(compositor_port, profiler_chan.clone(), shutdown_chan);

// Create a Servo instance.

@@ -14,6 +14,8 @@ pub enum ReadyState {
FinishedLoading,
}

/// 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 : Clone {
fn set_ready_state(&self, ReadyState);
}
@@ -110,7 +110,7 @@ impl ProfilerCategory {
}

impl Profiler {
pub fn create_profiler(port: Port<ProfilerMsg>) {
pub fn create(port: Port<ProfilerMsg>) {
let port = Cell(port);
do spawn {
let mut profiler = Profiler::new(port.take());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.