permission bool replaces compositor token

This commit is contained in:
Tim Kuehn 2013-07-03 14:09:48 -07:00
parent 525519efac
commit 6ba2f8d535
3 changed files with 34 additions and 52 deletions

View file

@ -8,7 +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 servo_msg::constellation_msg::{ConstellationChan};
use font_context::FontContext; use font_context::FontContext;
use geom::matrix2d::Matrix2D; use geom::matrix2d::Matrix2D;
@ -33,8 +33,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,10 +68,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 /// A channel to the constellation for -- just in case
constellation_chan: ConstellationChan, constellation_chan: ConstellationChan,
/// A token that grants permission to send paint messages to compositor /// Permission to send paint messages to the compositor
compositor_token: Option<CompositorToken>, paint_permission: bool,
/// Cached copy of last layers rendered /// Cached copy of last layers rendered
last_paint_msg: Option<(LayerBufferSet, Size2D<uint>)>, last_paint_msg: Option<(LayerBufferSet, Size2D<uint>)>,
} }
@ -109,7 +109,7 @@ impl<C: RenderListener + Owned> RenderTask<C> {
render_layer: None, render_layer: None,
constellation_chan: constellation_chan.take(), constellation_chan: constellation_chan.take(),
compositor_token: None, paint_permission: false,
last_paint_msg: None, last_paint_msg: None,
}; };
@ -129,8 +129,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 +139,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(());
@ -234,7 +234,7 @@ impl<C: RenderListener + Owned> RenderTask<C> {
}; };
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

@ -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

@ -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(),
}
}
}