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

Next

decouple script from compositor

communicate via layout
refactor channel wrappers from *Task --> *Chan

fix merge fallout
  • Loading branch information
Tim Kuehn
Tim Kuehn committed Jun 15, 2013
commit b5dac3f426e1b30144ba9154059d9068aee16db0
@@ -34,7 +34,7 @@ pub enum RenderState {

/// The interface used to by the renderer to acquire draw targets for each rendered frame and
/// submit them to be drawn to the display.
pub trait Compositor {
pub trait RenderListener {
fn get_gl_context(&self) -> AzGLContext;
fn paint(&self, layer_buffer_set: LayerBufferSet, new_size: Size2D<uint>);
fn set_render_state(&self, render_state: RenderState);
@@ -5,7 +5,7 @@
// The task that handles all rendering/painting.

use azure::{AzFloat, AzGLContext};
use compositor::{Compositor, IdleRenderState, RenderingRenderState};
use compositor::{RenderListener, IdleRenderState, RenderingRenderState};
use font_context::FontContext;
use geom::matrix2d::Matrix2D;
use opts::Opts;
@@ -28,66 +28,70 @@ pub enum Msg {
}

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

impl RenderTask {
pub fn new<C:Compositor + Owned>(compositor: C,
opts: Opts,
profiler_chan: ProfilerChan)
-> RenderTask {
let compositor_cell = Cell(compositor);
let opts_cell = Cell(opts);
let (port, chan) = comm::stream();
let port = Cell(port);

do spawn {
let compositor = compositor_cell.take();
let share_gl_context = compositor.get_gl_context();

// FIXME: Annoying three-cell dance here. We need one-shot closures.
let opts = opts_cell.with_ref(|o| copy *o);
let n_threads = opts.n_render_threads;
let new_opts_cell = Cell(opts);

let profiler_chan = profiler_chan.clone();
let profiler_chan_copy = profiler_chan.clone();

let thread_pool = do TaskPool::new(n_threads, Some(SingleThreaded)) {
let opts_cell = Cell(new_opts_cell.with_ref(|o| copy *o));
let profiler_chan = Cell(profiler_chan.clone());

let f: ~fn(uint) -> ThreadRenderContext = |thread_index| {
let opts = opts_cell.with_ref(|opts| copy *opts);

ThreadRenderContext {
thread_index: thread_index,
font_ctx: @mut FontContext::new(opts.render_backend,
false,
profiler_chan.take()),
opts: opts,
}
};
f
};

// FIXME: rust/#5967
let mut renderer = Renderer {
port: port.take(),
compositor: compositor,
thread_pool: thread_pool,
opts: opts_cell.take(),
profiler_chan: profiler_chan_copy,
share_gl_context: share_gl_context,
};

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

RenderTask {
channel: SharedChan::new(chan),
}
pub fn create_render_task<C: RenderListener + Owned>(port: Port<Msg>,
compositor: C,
opts: Opts,
profiler_chan: ProfilerChan) {
let compositor_cell = Cell(compositor);
let opts_cell = Cell(opts);
let port = Cell(port);

do spawn {
let compositor = compositor_cell.take();
let share_gl_context = compositor.get_gl_context();

// FIXME: Annoying three-cell dance here. We need one-shot closures.
let opts = opts_cell.with_ref(|o| copy *o);
let n_threads = opts.n_render_threads;
let new_opts_cell = Cell(opts);

let profiler_chan = profiler_chan.clone();
let profiler_chan_copy = profiler_chan.clone();

let thread_pool = do TaskPool::new(n_threads, Some(SingleThreaded)) {
let opts_cell = Cell(new_opts_cell.with_ref(|o| copy *o));
let profiler_chan = Cell(profiler_chan.clone());

let f: ~fn(uint) -> ThreadRenderContext = |thread_index| {
let opts = opts_cell.with_ref(|opts| copy *opts);

ThreadRenderContext {
thread_index: thread_index,
font_ctx: @mut FontContext::new(opts.render_backend,
false,
profiler_chan.take()),
opts: opts,
}
};
f
};

// FIXME: rust/#5967
let mut renderer = Renderer {
port: port.take(),
compositor: compositor,
thread_pool: thread_pool,
opts: opts_cell.take(),
profiler_chan: profiler_chan_copy,
share_gl_context: share_gl_context,
};

renderer.start();
}
}

@@ -110,7 +114,7 @@ priv struct Renderer<C> {
share_gl_context: AzGLContext,
}

impl<C: Compositor + Owned> Renderer<C> {
impl<C: RenderListener + Owned> Renderer<C> {
fn start(&mut self) {
debug!("renderer: beginning rendering loop");

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.