auto merge of #558 : tkuehn/servo/master, r=metajack

* constellation grants permission to renderers instead of passing tokens
* render tasks wrap layer buffer sets in ARCs
* removed no-longer-used field (constellation chan) from render task struct
This commit is contained in:
bors-servo 2013-07-03 18:36:35 -07:00
commit 32c147fbde
5 changed files with 61 additions and 81 deletions

View file

@ -8,8 +8,7 @@ use azure::{AzFloat, AzGLContext};
use azure::azure_hl::{B8G8R8A8, DrawTarget}; use azure::azure_hl::{B8G8R8A8, DrawTarget};
use display_list::DisplayList; use display_list::DisplayList;
use servo_msg::compositor_msg::{RenderListener, IdleRenderState, RenderingRenderState, LayerBuffer}; use servo_msg::compositor_msg::{RenderListener, IdleRenderState, RenderingRenderState, LayerBuffer};
use servo_msg::compositor_msg::{CompositorToken, LayerBufferSet}; use servo_msg::compositor_msg::{LayerBufferSet};
use servo_msg::constellation_msg::{ConstellationChan};
use font_context::FontContext; use font_context::FontContext;
use geom::matrix2d::Matrix2D; use geom::matrix2d::Matrix2D;
use geom::point::Point2D; use geom::point::Point2D;
@ -25,6 +24,8 @@ use std::uint;
use servo_util::time::{ProfilerChan, profile}; use servo_util::time::{ProfilerChan, profile};
use servo_util::time; use servo_util::time;
use extra::arc;
pub struct RenderLayer { pub struct RenderLayer {
display_list: DisplayList<()>, display_list: DisplayList<()>,
size: Size2D<uint> size: Size2D<uint>
@ -33,8 +34,8 @@ pub struct RenderLayer {
pub enum Msg { pub enum Msg {
RenderMsg(RenderLayer), RenderMsg(RenderLayer),
ReRenderMsg(f32), ReRenderMsg(f32),
TokenBestowMsg(CompositorToken), PaintPermissionGranted,
TokenInvalidateMsg, PaintPermissionRevoked,
ExitMsg(Chan<()>), ExitMsg(Chan<()>),
} }
@ -68,12 +69,10 @@ priv struct RenderTask<C> {
/// The layer to be rendered /// The layer to be rendered
render_layer: Option<RenderLayer>, render_layer: Option<RenderLayer>,
/// A channel to the constellation for surrendering token /// Permission to send paint messages to the compositor
constellation_chan: ConstellationChan, paint_permission: bool,
/// A token that grants permission to send paint messages to compositor
compositor_token: Option<CompositorToken>,
/// Cached copy of last layers rendered /// Cached copy of last layers rendered
last_paint_msg: Option<(LayerBufferSet, Size2D<uint>)>, last_paint_msg: Option<(arc::ARC<LayerBufferSet>, Size2D<uint>)>,
} }
impl<C: RenderListener + Owned> RenderTask<C> { impl<C: RenderListener + Owned> RenderTask<C> {
@ -81,35 +80,32 @@ impl<C: RenderListener + Owned> RenderTask<C> {
port: Port<Msg>, port: Port<Msg>,
compositor: C, compositor: C,
opts: Opts, opts: Opts,
constellation_chan: ConstellationChan,
profiler_chan: ProfilerChan) { profiler_chan: ProfilerChan) {
let compositor_cell = Cell::new(compositor); let compositor = Cell::new(compositor);
let opts_cell = Cell::new(opts); let opts = Cell::new(opts);
let port = Cell::new(port); let port = Cell::new(port);
let constellation_chan = Cell::new(constellation_chan); let profiler_chan = Cell::new(profiler_chan);
do spawn { do spawn {
let compositor = compositor_cell.take(); let compositor = compositor.take();
let share_gl_context = compositor.get_gl_context(); let share_gl_context = compositor.get_gl_context();
let opts = opts_cell.with_ref(|o| copy *o); let opts = opts.take();
let profiler_chan = profiler_chan.clone(); let profiler_chan = profiler_chan.take();
let profiler_chan_clone = profiler_chan.clone();
// FIXME: rust/#5967 // FIXME: rust/#5967
let mut render_task = RenderTask { let mut render_task = RenderTask {
id: id, id: id,
port: port.take(), port: port.take(),
compositor: compositor, compositor: compositor,
font_ctx: @mut FontContext::new(opts.render_backend, font_ctx: @mut FontContext::new(copy opts.render_backend,
false, false,
profiler_chan), profiler_chan.clone()),
opts: opts_cell.take(), opts: opts,
profiler_chan: profiler_chan_clone, profiler_chan: profiler_chan,
share_gl_context: share_gl_context, share_gl_context: share_gl_context,
render_layer: None, render_layer: None,
constellation_chan: constellation_chan.take(), paint_permission: false,
compositor_token: None,
last_paint_msg: None, last_paint_msg: None,
}; };
@ -129,8 +125,8 @@ impl<C: RenderListener + Owned> RenderTask<C> {
ReRenderMsg(scale) => { ReRenderMsg(scale) => {
self.render(scale); self.render(scale);
} }
TokenBestowMsg(token) => { PaintPermissionGranted => {
self.compositor_token = Some(token); self.paint_permission = true;
match self.last_paint_msg { match self.last_paint_msg {
Some((ref layer_buffer_set, ref layer_size)) => { Some((ref layer_buffer_set, ref layer_size)) => {
self.compositor.paint(self.id, layer_buffer_set.clone(), *layer_size); self.compositor.paint(self.id, layer_buffer_set.clone(), *layer_size);
@ -139,8 +135,8 @@ impl<C: RenderListener + Owned> RenderTask<C> {
None => {} None => {}
} }
} }
TokenInvalidateMsg => { PaintPermissionRevoked => {
self.compositor_token = None; self.paint_permission = false;
} }
ExitMsg(response_ch) => { ExitMsg(response_ch) => {
response_ch.send(()); response_ch.send(());
@ -232,9 +228,10 @@ impl<C: RenderListener + Owned> RenderTask<C> {
let layer_buffer_set = LayerBufferSet { let layer_buffer_set = LayerBufferSet {
buffers: new_buffers, buffers: new_buffers,
}; };
let layer_buffer_set = arc::ARC(layer_buffer_set);
debug!("render_task: returning surface"); debug!("render_task: returning surface");
if self.compositor_token.is_some() { if self.paint_permission {
self.compositor.paint(self.id, layer_buffer_set.clone(), render_layer.size); self.compositor.paint(self.id, layer_buffer_set.clone(), render_layer.size);
} }
debug!("caching paint msg"); debug!("caching paint msg");

View file

@ -23,7 +23,6 @@ use std::comm;
use std::comm::{Chan, SharedChan, Port}; use std::comm::{Chan, SharedChan, Port};
use std::num::Orderable; use std::num::Orderable;
use std::task; use std::task;
use std::util;
use geom::matrix::identity; use geom::matrix::identity;
use geom::point::Point2D; use geom::point::Point2D;
use geom::size::Size2D; use geom::size::Size2D;
@ -36,6 +35,7 @@ use servo_util::{time, url};
use servo_util::time::profile; use servo_util::time::profile;
use servo_util::time::ProfilerChan; use servo_util::time::ProfilerChan;
use extra::arc;
pub use windowing; pub use windowing;
/// The implementation of the layers-based compositor. /// The implementation of the layers-based compositor.
@ -47,28 +47,34 @@ pub struct CompositorChan {
/// Implementation of the abstract `ScriptListener` interface. /// Implementation of the abstract `ScriptListener` interface.
impl ScriptListener for CompositorChan { impl ScriptListener for CompositorChan {
fn set_ready_state(&self, ready_state: ReadyState) { fn set_ready_state(&self, ready_state: ReadyState) {
let msg = ChangeReadyState(ready_state); let msg = ChangeReadyState(ready_state);
self.chan.send(msg); self.chan.send(msg);
} }
} }
/// Implementation of the abstract `RenderListener` interface. /// Implementation of the abstract `RenderListener` interface.
impl RenderListener for CompositorChan { impl RenderListener for CompositorChan {
fn get_gl_context(&self) -> AzGLContext { fn get_gl_context(&self) -> AzGLContext {
let (port, chan) = comm::stream(); let (port, chan) = comm::stream();
self.chan.send(GetGLContext(chan)); self.chan.send(GetGLContext(chan));
port.recv() port.recv()
} }
fn paint(&self, id: uint, layer_buffer_set: LayerBufferSet, new_size: Size2D<uint>) {
fn paint(&self, id: uint, layer_buffer_set: arc::ARC<LayerBufferSet>, new_size: Size2D<uint>) {
self.chan.send(Paint(id, layer_buffer_set, new_size)) self.chan.send(Paint(id, layer_buffer_set, new_size))
} }
fn set_render_state(&self, render_state: RenderState) { fn set_render_state(&self, render_state: RenderState) {
self.chan.send(ChangeRenderState(render_state)) self.chan.send(ChangeRenderState(render_state))
} }
} }
impl CompositorChan { impl CompositorChan {
pub fn new(chan: Chan<Msg>) -> CompositorChan { pub fn new(chan: Chan<Msg>) -> CompositorChan {
CompositorChan { CompositorChan {
chan: SharedChan::new(chan), chan: SharedChan::new(chan),
@ -86,7 +92,7 @@ pub enum Msg {
/// Requests the compositors GL context. /// Requests the compositors GL context.
GetGLContext(Chan<AzGLContext>), GetGLContext(Chan<AzGLContext>),
/// Requests that the compositor paint the given layer buffer set for the given page size. /// Requests that the compositor paint the given layer buffer set for the given page size.
Paint(uint, LayerBufferSet, Size2D<uint>), Paint(uint, arc::ARC<LayerBufferSet>, Size2D<uint>),
/// Alerts the compositor to the current status of page loading. /// Alerts the compositor to the current status of page loading.
ChangeReadyState(ReadyState), ChangeReadyState(ReadyState),
/// Alerts the compositor to the current status of rendering. /// Alerts the compositor to the current status of rendering.
@ -277,16 +283,12 @@ impl CompositorTask {
*page_size = Size2D(new_size.width as f32, new_size.height as f32); *page_size = Size2D(new_size.width as f32, new_size.height as f32);
let mut new_layer_buffer_set = new_layer_buffer_set; let new_layer_buffer_set = new_layer_buffer_set.get();
// Iterate over the children of the container layer. // Iterate over the children of the container layer.
let mut current_layer_child = root_layer.first_child; let mut current_layer_child = root_layer.first_child;
// Replace the image layer data with the buffer data. Also compute the page for new_layer_buffer_set.buffers.iter().advance |buffer| {
// size here.
let buffers = util::replace(&mut new_layer_buffer_set.buffers, ~[]);
for buffers.each |buffer| {
let width = buffer.rect.size.width as uint; let width = buffer.rect.size.width as uint;
let height = buffer.rect.size.height as uint; let height = buffer.rect.size.height as uint;

View file

@ -9,9 +9,8 @@ use std::comm;
use std::comm::Port; use std::comm::Port;
use std::task; use std::task;
use gfx::opts::Opts; use gfx::opts::Opts;
use gfx::render_task::{TokenBestowMsg, TokenInvalidateMsg}; use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked};
use pipeline::Pipeline; use pipeline::Pipeline;
use servo_msg::compositor_msg::{CompositorToken};
use servo_msg::constellation_msg::{CompositorAck, ConstellationChan, ExitMsg}; use servo_msg::constellation_msg::{CompositorAck, ConstellationChan, ExitMsg};
use servo_msg::constellation_msg::{LoadUrlMsg, Msg, NavigateMsg, RendererReadyMsg}; use servo_msg::constellation_msg::{LoadUrlMsg, Msg, NavigateMsg, RendererReadyMsg};
use servo_msg::constellation_msg; use servo_msg::constellation_msg;
@ -33,8 +32,8 @@ pub struct Constellation {
pipelines: HashMap<uint, Pipeline>, pipelines: HashMap<uint, Pipeline>,
navigation_context: NavigationContext, navigation_context: NavigationContext,
next_id: uint, next_id: uint,
current_token_bearer: Option<uint>, current_painter: Option<uint>,
next_token_bearer: Option<uint>, next_painter: Option<uint>,
profiler_chan: ProfilerChan, profiler_chan: ProfilerChan,
opts: Opts, opts: Opts,
} }
@ -113,8 +112,8 @@ impl Constellation {
pipelines: HashMap::new(), pipelines: HashMap::new(),
navigation_context: NavigationContext::new(), navigation_context: NavigationContext::new(),
next_id: 0, next_id: 0,
current_token_bearer: None, current_painter: None,
next_token_bearer: None, next_painter: None,
profiler_chan: profiler_chan.take(), profiler_chan: profiler_chan.take(),
opts: opts.take(), opts: opts.take(),
}; };
@ -157,7 +156,7 @@ impl Constellation {
} else { } else {
pipeline.load(url); pipeline.load(url);
pipeline.navigation_type = Some(constellation_msg::Load); pipeline.navigation_type = Some(constellation_msg::Load);
self.next_token_bearer = Some(pipeline_id); self.next_painter = Some(pipeline_id);
} }
self.pipelines.insert(pipeline_id, pipeline); self.pipelines.insert(pipeline_id, pipeline);
} }
@ -186,23 +185,23 @@ impl Constellation {
pipeline.navigation_type = Some(constellation_msg::Navigate); pipeline.navigation_type = Some(constellation_msg::Navigate);
pipeline.reload(); pipeline.reload();
self.pipelines.insert(destination_id, pipeline); self.pipelines.insert(destination_id, pipeline);
self.next_token_bearer = Some(destination_id); self.next_painter = Some(destination_id);
self.update_token_bearer(); self.update_painter();
} }
// Notification that rendering has finished and is requesting permission to paint. // Notification that rendering has finished and is requesting permission to paint.
RendererReadyMsg(pipeline_id) => { RendererReadyMsg(pipeline_id) => {
let next_token_bearer = self.next_token_bearer; let next_painter = self.next_painter;
for next_token_bearer.iter().advance |&id| { for next_painter.iter().advance |&id| {
if pipeline_id == id { if pipeline_id == id {
self.update_token_bearer(); self.update_painter();
} }
} }
} }
// Acknowledgement from the compositor that it has updated its active pipeline id // Acknowledgement from the compositor that it has updated its active pipeline id
CompositorAck(id) => { CompositorAck(id) => {
self.bestow_compositor_token(id); self.grant_paint_permission(id);
} }
ExitMsg(sender) => { ExitMsg(sender) => {
@ -219,12 +218,12 @@ impl Constellation {
true true
} }
fn update_token_bearer(&mut self) { fn update_painter(&mut self) {
let current_token_bearer = replace(&mut self.current_token_bearer, None); let current_painter = replace(&mut self.current_painter, None);
for current_token_bearer.iter().advance |id| { for current_painter.iter().advance |id| {
self.pipelines.get(id).render_chan.send(TokenInvalidateMsg); self.pipelines.get(id).render_chan.send(PaintPermissionRevoked);
} }
let id = self.next_token_bearer.get(); let id = self.next_painter.get();
let pipeline = self.pipelines.get(&id); let pipeline = self.pipelines.get(&id);
self.compositor_chan.send(SetLayoutRenderChans(pipeline.layout_chan.clone(), self.compositor_chan.send(SetLayoutRenderChans(pipeline.layout_chan.clone(),
pipeline.render_chan.clone(), pipeline.render_chan.clone(),
@ -232,12 +231,12 @@ impl Constellation {
self.chan.clone())); self.chan.clone()));
} }
// Sends a compositor token to a renderer; optionally updates navigation to reflect a new page // Grants a renderer permission to paint; optionally updates navigation to reflect a new page
fn bestow_compositor_token(&mut self, id: uint) { fn grant_paint_permission(&mut self, id: uint) {
let pipeline = self.pipelines.get(&id); let pipeline = self.pipelines.get(&id);
pipeline.render_chan.send(TokenBestowMsg(CompositorToken::new())); pipeline.render_chan.send(PaintPermissionGranted);
self.current_token_bearer = Some(id); self.current_painter = Some(id);
self.next_token_bearer = None; self.next_painter = None;
// Don't navigate on Navigate type, because that is handled by forward/back // Don't navigate on Navigate type, because that is handled by forward/back
match pipeline.navigation_type.get() { match pipeline.navigation_type.get() {
constellation_msg::Load => { constellation_msg::Load => {

View file

@ -47,7 +47,6 @@ impl Pipeline {
render_port, render_port,
compositor_chan.clone(), compositor_chan.clone(),
copy opts, copy opts,
constellation_chan.clone(),
profiler_chan.clone()); profiler_chan.clone());
LayoutTask::create(layout_port, LayoutTask::create(layout_port,

View file

@ -6,7 +6,8 @@ use azure::azure_hl::DrawTarget;
use azure::azure::AzGLContext; use azure::azure::AzGLContext;
use geom::rect::Rect; use geom::rect::Rect;
use geom::size::Size2D; use geom::size::Size2D;
use std::util::NonCopyable;
use extra::arc;
#[deriving(Clone)] #[deriving(Clone)]
pub struct LayerBuffer { pub struct LayerBuffer {
@ -24,7 +25,6 @@ pub struct LayerBuffer {
/// A set of layer buffers. This is an atomic unit used to switch between the front and back /// A set of layer buffers. This is an atomic unit used to switch between the front and back
/// buffers. /// buffers.
#[deriving(Clone)]
pub struct LayerBufferSet { pub struct LayerBufferSet {
buffers: ~[LayerBuffer] buffers: ~[LayerBuffer]
} }
@ -49,7 +49,7 @@ pub enum ReadyState {
/// submit them to be drawn to the display. /// submit them to be drawn to the display.
pub trait RenderListener { pub trait RenderListener {
fn get_gl_context(&self) -> AzGLContext; fn get_gl_context(&self) -> AzGLContext;
fn paint(&self, id: uint, layer_buffer_set: LayerBufferSet, new_size: Size2D<uint>); fn paint(&self, id: uint, layer_buffer_set: arc::ARC<LayerBufferSet>, new_size: Size2D<uint>);
fn set_render_state(&self, render_state: RenderState); fn set_render_state(&self, render_state: RenderState);
} }
@ -58,20 +58,3 @@ pub trait RenderListener {
pub trait ScriptListener : Clone { pub trait ScriptListener : Clone {
fn set_ready_state(&self, ReadyState); fn set_ready_state(&self, ReadyState);
} }
/// Signifies to the renderer likely control of the compositor. Controlling the compositor token
/// is necessary but not sufficient for the renderer to successfully send paint messages to the
/// compositor. Only the render tasks controlling compositor tokens may send messages, and the
/// compositor is guaranteed to only accept messages from one of those tasks at a time.
pub struct CompositorToken {
construction_restrictor: NonCopyable,
}
impl CompositorToken {
pub fn new() -> CompositorToken {
CompositorToken {
// Of course, this doesn't guarantee that renderers will invalidate their tokens
construction_restrictor: NonCopyable::new(),
}
}
}