mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
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:
commit
32c147fbde
5 changed files with 61 additions and 81 deletions
|
@ -8,8 +8,7 @@ use azure::{AzFloat, AzGLContext};
|
|||
use azure::azure_hl::{B8G8R8A8, DrawTarget};
|
||||
use display_list::DisplayList;
|
||||
use servo_msg::compositor_msg::{RenderListener, IdleRenderState, RenderingRenderState, LayerBuffer};
|
||||
use servo_msg::compositor_msg::{CompositorToken, LayerBufferSet};
|
||||
use servo_msg::constellation_msg::{ConstellationChan};
|
||||
use servo_msg::compositor_msg::{LayerBufferSet};
|
||||
use font_context::FontContext;
|
||||
use geom::matrix2d::Matrix2D;
|
||||
use geom::point::Point2D;
|
||||
|
@ -25,6 +24,8 @@ use std::uint;
|
|||
use servo_util::time::{ProfilerChan, profile};
|
||||
use servo_util::time;
|
||||
|
||||
use extra::arc;
|
||||
|
||||
pub struct RenderLayer {
|
||||
display_list: DisplayList<()>,
|
||||
size: Size2D<uint>
|
||||
|
@ -33,8 +34,8 @@ pub struct RenderLayer {
|
|||
pub enum Msg {
|
||||
RenderMsg(RenderLayer),
|
||||
ReRenderMsg(f32),
|
||||
TokenBestowMsg(CompositorToken),
|
||||
TokenInvalidateMsg,
|
||||
PaintPermissionGranted,
|
||||
PaintPermissionRevoked,
|
||||
ExitMsg(Chan<()>),
|
||||
}
|
||||
|
||||
|
@ -68,12 +69,10 @@ priv struct RenderTask<C> {
|
|||
|
||||
/// The layer to be rendered
|
||||
render_layer: Option<RenderLayer>,
|
||||
/// A channel to the constellation for surrendering token
|
||||
constellation_chan: ConstellationChan,
|
||||
/// A token that grants permission to send paint messages to compositor
|
||||
compositor_token: Option<CompositorToken>,
|
||||
/// Permission to send paint messages to the compositor
|
||||
paint_permission: bool,
|
||||
/// 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> {
|
||||
|
@ -81,35 +80,32 @@ impl<C: RenderListener + Owned> RenderTask<C> {
|
|||
port: Port<Msg>,
|
||||
compositor: C,
|
||||
opts: Opts,
|
||||
constellation_chan: ConstellationChan,
|
||||
profiler_chan: ProfilerChan) {
|
||||
let compositor_cell = Cell::new(compositor);
|
||||
let opts_cell = Cell::new(opts);
|
||||
let compositor = Cell::new(compositor);
|
||||
let opts = Cell::new(opts);
|
||||
let port = Cell::new(port);
|
||||
let constellation_chan = Cell::new(constellation_chan);
|
||||
let profiler_chan = Cell::new(profiler_chan);
|
||||
|
||||
do spawn {
|
||||
let compositor = compositor_cell.take();
|
||||
let compositor = compositor.take();
|
||||
let share_gl_context = compositor.get_gl_context();
|
||||
let opts = opts_cell.with_ref(|o| copy *o);
|
||||
let profiler_chan = profiler_chan.clone();
|
||||
let profiler_chan_clone = profiler_chan.clone();
|
||||
let opts = opts.take();
|
||||
let profiler_chan = profiler_chan.take();
|
||||
|
||||
// FIXME: rust/#5967
|
||||
let mut render_task = RenderTask {
|
||||
id: id,
|
||||
port: port.take(),
|
||||
compositor: compositor,
|
||||
font_ctx: @mut FontContext::new(opts.render_backend,
|
||||
font_ctx: @mut FontContext::new(copy opts.render_backend,
|
||||
false,
|
||||
profiler_chan),
|
||||
opts: opts_cell.take(),
|
||||
profiler_chan: profiler_chan_clone,
|
||||
profiler_chan.clone()),
|
||||
opts: opts,
|
||||
profiler_chan: profiler_chan,
|
||||
share_gl_context: share_gl_context,
|
||||
render_layer: None,
|
||||
|
||||
constellation_chan: constellation_chan.take(),
|
||||
compositor_token: None,
|
||||
paint_permission: false,
|
||||
last_paint_msg: None,
|
||||
};
|
||||
|
||||
|
@ -129,8 +125,8 @@ impl<C: RenderListener + Owned> RenderTask<C> {
|
|||
ReRenderMsg(scale) => {
|
||||
self.render(scale);
|
||||
}
|
||||
TokenBestowMsg(token) => {
|
||||
self.compositor_token = Some(token);
|
||||
PaintPermissionGranted => {
|
||||
self.paint_permission = true;
|
||||
match self.last_paint_msg {
|
||||
Some((ref layer_buffer_set, ref layer_size)) => {
|
||||
self.compositor.paint(self.id, layer_buffer_set.clone(), *layer_size);
|
||||
|
@ -139,8 +135,8 @@ impl<C: RenderListener + Owned> RenderTask<C> {
|
|||
None => {}
|
||||
}
|
||||
}
|
||||
TokenInvalidateMsg => {
|
||||
self.compositor_token = None;
|
||||
PaintPermissionRevoked => {
|
||||
self.paint_permission = false;
|
||||
}
|
||||
ExitMsg(response_ch) => {
|
||||
response_ch.send(());
|
||||
|
@ -232,9 +228,10 @@ impl<C: RenderListener + Owned> RenderTask<C> {
|
|||
let layer_buffer_set = LayerBufferSet {
|
||||
buffers: new_buffers,
|
||||
};
|
||||
let layer_buffer_set = arc::ARC(layer_buffer_set);
|
||||
|
||||
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);
|
||||
}
|
||||
debug!("caching paint msg");
|
||||
|
|
|
@ -23,7 +23,6 @@ use std::comm;
|
|||
use std::comm::{Chan, SharedChan, Port};
|
||||
use std::num::Orderable;
|
||||
use std::task;
|
||||
use std::util;
|
||||
use geom::matrix::identity;
|
||||
use geom::point::Point2D;
|
||||
use geom::size::Size2D;
|
||||
|
@ -36,6 +35,7 @@ use servo_util::{time, url};
|
|||
use servo_util::time::profile;
|
||||
use servo_util::time::ProfilerChan;
|
||||
|
||||
use extra::arc;
|
||||
pub use windowing;
|
||||
|
||||
/// The implementation of the layers-based compositor.
|
||||
|
@ -47,28 +47,34 @@ pub struct CompositorChan {
|
|||
|
||||
/// Implementation of the abstract `ScriptListener` interface.
|
||||
impl ScriptListener for CompositorChan {
|
||||
|
||||
fn set_ready_state(&self, ready_state: ReadyState) {
|
||||
let msg = ChangeReadyState(ready_state);
|
||||
self.chan.send(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Implementation of the abstract `RenderListener` interface.
|
||||
impl RenderListener for CompositorChan {
|
||||
|
||||
fn get_gl_context(&self) -> AzGLContext {
|
||||
let (port, chan) = comm::stream();
|
||||
self.chan.send(GetGLContext(chan));
|
||||
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))
|
||||
}
|
||||
|
||||
fn set_render_state(&self, render_state: RenderState) {
|
||||
self.chan.send(ChangeRenderState(render_state))
|
||||
}
|
||||
}
|
||||
|
||||
impl CompositorChan {
|
||||
|
||||
pub fn new(chan: Chan<Msg>) -> CompositorChan {
|
||||
CompositorChan {
|
||||
chan: SharedChan::new(chan),
|
||||
|
@ -86,7 +92,7 @@ pub enum Msg {
|
|||
/// Requests the compositors GL context.
|
||||
GetGLContext(Chan<AzGLContext>),
|
||||
/// 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.
|
||||
ChangeReadyState(ReadyState),
|
||||
/// 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);
|
||||
|
||||
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.
|
||||
let mut current_layer_child = root_layer.first_child;
|
||||
|
||||
// Replace the image layer data with the buffer data. Also compute the page
|
||||
// size here.
|
||||
let buffers = util::replace(&mut new_layer_buffer_set.buffers, ~[]);
|
||||
|
||||
for buffers.each |buffer| {
|
||||
for new_layer_buffer_set.buffers.iter().advance |buffer| {
|
||||
let width = buffer.rect.size.width as uint;
|
||||
let height = buffer.rect.size.height as uint;
|
||||
|
||||
|
|
|
@ -9,9 +9,8 @@ use std::comm;
|
|||
use std::comm::Port;
|
||||
use std::task;
|
||||
use gfx::opts::Opts;
|
||||
use gfx::render_task::{TokenBestowMsg, TokenInvalidateMsg};
|
||||
use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked};
|
||||
use pipeline::Pipeline;
|
||||
use servo_msg::compositor_msg::{CompositorToken};
|
||||
use servo_msg::constellation_msg::{CompositorAck, ConstellationChan, ExitMsg};
|
||||
use servo_msg::constellation_msg::{LoadUrlMsg, Msg, NavigateMsg, RendererReadyMsg};
|
||||
use servo_msg::constellation_msg;
|
||||
|
@ -33,8 +32,8 @@ pub struct Constellation {
|
|||
pipelines: HashMap<uint, Pipeline>,
|
||||
navigation_context: NavigationContext,
|
||||
next_id: uint,
|
||||
current_token_bearer: Option<uint>,
|
||||
next_token_bearer: Option<uint>,
|
||||
current_painter: Option<uint>,
|
||||
next_painter: Option<uint>,
|
||||
profiler_chan: ProfilerChan,
|
||||
opts: Opts,
|
||||
}
|
||||
|
@ -113,8 +112,8 @@ impl Constellation {
|
|||
pipelines: HashMap::new(),
|
||||
navigation_context: NavigationContext::new(),
|
||||
next_id: 0,
|
||||
current_token_bearer: None,
|
||||
next_token_bearer: None,
|
||||
current_painter: None,
|
||||
next_painter: None,
|
||||
profiler_chan: profiler_chan.take(),
|
||||
opts: opts.take(),
|
||||
};
|
||||
|
@ -157,7 +156,7 @@ impl Constellation {
|
|||
} else {
|
||||
pipeline.load(url);
|
||||
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);
|
||||
}
|
||||
|
@ -186,23 +185,23 @@ impl Constellation {
|
|||
pipeline.navigation_type = Some(constellation_msg::Navigate);
|
||||
pipeline.reload();
|
||||
self.pipelines.insert(destination_id, pipeline);
|
||||
self.next_token_bearer = Some(destination_id);
|
||||
self.update_token_bearer();
|
||||
self.next_painter = Some(destination_id);
|
||||
self.update_painter();
|
||||
}
|
||||
|
||||
// Notification that rendering has finished and is requesting permission to paint.
|
||||
RendererReadyMsg(pipeline_id) => {
|
||||
let next_token_bearer = self.next_token_bearer;
|
||||
for next_token_bearer.iter().advance |&id| {
|
||||
let next_painter = self.next_painter;
|
||||
for next_painter.iter().advance |&id| {
|
||||
if pipeline_id == id {
|
||||
self.update_token_bearer();
|
||||
self.update_painter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Acknowledgement from the compositor that it has updated its active pipeline id
|
||||
CompositorAck(id) => {
|
||||
self.bestow_compositor_token(id);
|
||||
self.grant_paint_permission(id);
|
||||
}
|
||||
|
||||
ExitMsg(sender) => {
|
||||
|
@ -219,12 +218,12 @@ impl Constellation {
|
|||
true
|
||||
}
|
||||
|
||||
fn update_token_bearer(&mut self) {
|
||||
let current_token_bearer = replace(&mut self.current_token_bearer, None);
|
||||
for current_token_bearer.iter().advance |id| {
|
||||
self.pipelines.get(id).render_chan.send(TokenInvalidateMsg);
|
||||
fn update_painter(&mut self) {
|
||||
let current_painter = replace(&mut self.current_painter, None);
|
||||
for current_painter.iter().advance |id| {
|
||||
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);
|
||||
self.compositor_chan.send(SetLayoutRenderChans(pipeline.layout_chan.clone(),
|
||||
pipeline.render_chan.clone(),
|
||||
|
@ -232,12 +231,12 @@ impl Constellation {
|
|||
self.chan.clone()));
|
||||
}
|
||||
|
||||
// Sends a compositor token to a renderer; optionally updates navigation to reflect a new page
|
||||
fn bestow_compositor_token(&mut self, id: uint) {
|
||||
// Grants a renderer permission to paint; optionally updates navigation to reflect a new page
|
||||
fn grant_paint_permission(&mut self, id: uint) {
|
||||
let pipeline = self.pipelines.get(&id);
|
||||
pipeline.render_chan.send(TokenBestowMsg(CompositorToken::new()));
|
||||
self.current_token_bearer = Some(id);
|
||||
self.next_token_bearer = None;
|
||||
pipeline.render_chan.send(PaintPermissionGranted);
|
||||
self.current_painter = Some(id);
|
||||
self.next_painter = None;
|
||||
// Don't navigate on Navigate type, because that is handled by forward/back
|
||||
match pipeline.navigation_type.get() {
|
||||
constellation_msg::Load => {
|
||||
|
|
|
@ -47,7 +47,6 @@ impl Pipeline {
|
|||
render_port,
|
||||
compositor_chan.clone(),
|
||||
copy opts,
|
||||
constellation_chan.clone(),
|
||||
profiler_chan.clone());
|
||||
|
||||
LayoutTask::create(layout_port,
|
||||
|
|
|
@ -6,7 +6,8 @@ use azure::azure_hl::DrawTarget;
|
|||
use azure::azure::AzGLContext;
|
||||
use geom::rect::Rect;
|
||||
use geom::size::Size2D;
|
||||
use std::util::NonCopyable;
|
||||
|
||||
use extra::arc;
|
||||
|
||||
#[deriving(Clone)]
|
||||
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
|
||||
/// buffers.
|
||||
#[deriving(Clone)]
|
||||
pub struct LayerBufferSet {
|
||||
buffers: ~[LayerBuffer]
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ pub enum ReadyState {
|
|||
/// submit them to be drawn to the display.
|
||||
pub trait RenderListener {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -58,20 +58,3 @@ pub trait RenderListener {
|
|||
pub trait ScriptListener : Clone {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue