Pass creation/update data for compositor layers in a struct

Use a new LayerProperties struct to hold all the data necessary to
create or update compositor layers. This reduces a lot of duplication
when passing it along.
This commit is contained in:
Martin Robinson 2014-07-08 11:03:45 -07:00
parent 5e52023177
commit ca77ca998e
3 changed files with 74 additions and 135 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use compositor_data::CompositorData; use compositor_data::CompositorData;
use compositor_task::{Msg, CompositorTask, Exit, ChangeReadyState, SetIds}; use compositor_task::{Msg, CompositorTask, Exit, ChangeReadyState, SetIds, LayerProperties};
use compositor_task::{GetGraphicsMetadata, CreateOrUpdateRootLayer, CreateOrUpdateDescendantLayer}; use compositor_task::{GetGraphicsMetadata, CreateOrUpdateRootLayer, CreateOrUpdateDescendantLayer};
use compositor_task::{SetLayerClipRect, Paint, ScrollFragmentPoint, LoadComplete}; use compositor_task::{SetLayerClipRect, Paint, ScrollFragmentPoint, LoadComplete};
use compositor_task::{ShutdownComplete, ChangeRenderState}; use compositor_task::{ShutdownComplete, ChangeRenderState};
@ -18,12 +18,12 @@ use windowing::{QuitWindowEvent, RefreshWindowEvent, ResizeWindowEvent, ScrollWi
use windowing::{WindowEvent, WindowMethods, WindowNavigateMsg, ZoomWindowEvent}; use windowing::{WindowEvent, WindowMethods, WindowNavigateMsg, ZoomWindowEvent};
use windowing::PinchZoomWindowEvent; use windowing::PinchZoomWindowEvent;
use azure::azure_hl::{SourceSurfaceMethods, Color}; use azure::azure_hl::SourceSurfaceMethods;
use azure::azure_hl; use azure::azure_hl;
use geom::matrix::identity; use geom::matrix::identity;
use geom::point::{Point2D, TypedPoint2D}; use geom::point::{Point2D, TypedPoint2D};
use geom::rect::Rect; use geom::rect::Rect;
use geom::size::{Size2D, TypedSize2D}; use geom::size::TypedSize2D;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use layers::layers::LayerBufferSet; use layers::layers::LayerBufferSet;
use layers::platform::surface::NativeCompositingGraphicsContext; use layers::platform::surface::NativeCompositingGraphicsContext;
@ -34,7 +34,7 @@ use layers::layers::Layer;
use opengles::gl2; use opengles::gl2;
use png; use png;
use servo_msg::compositor_msg::{Blank, Epoch, FinishedLoading, IdleRenderState}; use servo_msg::compositor_msg::{Blank, Epoch, FinishedLoading, IdleRenderState};
use servo_msg::compositor_msg::{LayerId, ReadyState, RenderState, ScrollPolicy, Scrollable}; use servo_msg::compositor_msg::{LayerId, ReadyState, RenderState};
use servo_msg::constellation_msg::{ConstellationChan, ExitMsg, LoadUrlMsg, NavigateMsg}; use servo_msg::constellation_msg::{ConstellationChan, ExitMsg, LoadUrlMsg, NavigateMsg};
use servo_msg::constellation_msg::{PipelineId, ResizedWindowMsg, WindowSizeData}; use servo_msg::constellation_msg::{PipelineId, ResizedWindowMsg, WindowSizeData};
use servo_msg::constellation_msg; use servo_msg::constellation_msg;
@ -286,28 +286,14 @@ impl IOCompositor {
chan.send(Some(azure_hl::current_graphics_metadata())); chan.send(Some(azure_hl::current_graphics_metadata()));
} }
(Ok(CreateOrUpdateRootLayer(pipeline_id, layer_id, epoch, size, color)), (Ok(CreateOrUpdateRootLayer(layer_properties)),
NotShuttingDown) => { NotShuttingDown) => {
self.create_or_update_root_layer(pipeline_id, self.create_or_update_root_layer(layer_properties);
layer_id,
epoch,
size,
color);
} }
(Ok(CreateOrUpdateDescendantLayer(pipeline_id, (Ok(CreateOrUpdateDescendantLayer(layer_properties)),
layer_id,
epoch,
rect,
scroll_behavior,
color)),
NotShuttingDown) => { NotShuttingDown) => {
self.create_or_update_descendant_layer(pipeline_id, self.create_or_update_descendant_layer(layer_properties);
layer_id,
epoch,
rect,
scroll_behavior,
color);
} }
(Ok(SetLayerClipRect(pipeline_id, layer_id, new_rect)), NotShuttingDown) => { (Ok(SetLayerClipRect(pipeline_id, layer_id, new_rect)), NotShuttingDown) => {
@ -355,24 +341,14 @@ impl IOCompositor {
self.send_window_size(); self.send_window_size();
} }
fn update_layer_if_exists(&mut self, fn update_layer_if_exists(&mut self, properties: LayerProperties) -> bool {
pipeline_id: PipelineId,
layer_id: LayerId,
epoch: Epoch,
rect: Rect<f32>,
unrendered_color: Color)
-> bool {
match self.scene.root { match self.scene.root {
Some(ref root_layer) => { Some(ref root_layer) => {
match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(), match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(),
pipeline_id, properties.pipeline_id,
layer_id) { properties.id) {
Some(existing_layer) => { Some(existing_layer) => {
CompositorData::update_layer(existing_layer.clone(), CompositorData::update_layer(existing_layer.clone(), properties);
epoch,
rect,
unrendered_color);
true true
} }
None => false, None => false,
@ -382,40 +358,24 @@ impl IOCompositor {
} }
} }
fn create_or_update_root_layer(&mut self, fn create_or_update_root_layer(&mut self, layer_properties: LayerProperties) {
pipeline_id: PipelineId, let need_new_root_layer = !self.update_layer_if_exists(layer_properties);
layer_id: LayerId,
epoch: Epoch,
size: Size2D<f32>,
unrendered_color: Color) {
let new_root_rect = Rect(Point2D(0f32, 0f32), size);
let need_new_root_layer = !self.update_layer_if_exists(pipeline_id,
layer_id,
epoch,
new_root_rect,
unrendered_color);
if need_new_root_layer { if need_new_root_layer {
let root_pipeline = match self.root_pipeline { let root_pipeline = match self.root_pipeline {
Some(ref root_pipeline) => root_pipeline.clone(), Some(ref root_pipeline) => root_pipeline.clone(),
None => fail!("Compositor: Making new layer without initialized pipeline"), None => fail!("Compositor: Making new layer without initialized pipeline"),
}; };
let new_compositor_data = CompositorData::new_root(root_pipeline, let new_compositor_data = CompositorData::new_root(root_pipeline,
epoch, layer_properties.epoch,
size, layer_properties.rect.size,
self.opts.cpu_painting, self.opts.cpu_painting,
unrendered_color); layer_properties.background_color);
let size = layer_properties.rect.size;
let new_root = Rc::new(Layer::new(size, let new_root = Rc::new(Layer::new(size,
self.opts.tile_size, self.opts.tile_size,
new_compositor_data)); new_compositor_data));
CompositorData::add_child(new_root.clone(), CompositorData::add_child(new_root.clone(), layer_properties, size);
layer_id,
epoch,
new_root_rect,
size,
Scrollable,
unrendered_color);
// Release all tiles from the layer before dropping it. // Release all tiles from the layer before dropping it.
match self.scene.root { match self.scene.root {
@ -425,56 +385,30 @@ impl IOCompositor {
self.scene.root = Some(new_root); self.scene.root = Some(new_root);
} }
self.scroll_layer_to_fragment_point_if_necessary(pipeline_id, layer_id); self.scroll_layer_to_fragment_point_if_necessary(layer_properties.pipeline_id,
layer_properties.id);
self.ask_for_tiles(); self.ask_for_tiles();
} }
fn create_or_update_descendant_layer(&mut self, fn create_or_update_descendant_layer(&mut self, layer_properties: LayerProperties) {
pipeline_id: PipelineId, if !self.update_layer_if_exists(layer_properties) {
layer_id: LayerId, self.create_descendant_layer(layer_properties);
epoch: Epoch,
rect: Rect<f32>,
scroll_policy: ScrollPolicy,
unrendered_color: Color) {
if !self.update_layer_if_exists(pipeline_id,
layer_id,
epoch,
rect,
unrendered_color) {
self.create_descendant_layer(pipeline_id,
layer_id,
epoch,
rect,
scroll_policy,
unrendered_color);
} }
self.scroll_layer_to_fragment_point_if_necessary(pipeline_id, layer_id); self.scroll_layer_to_fragment_point_if_necessary(layer_properties.pipeline_id,
layer_properties.id);
self.ask_for_tiles(); self.ask_for_tiles();
} }
fn create_descendant_layer(&self, fn create_descendant_layer(&self, layer_properties: LayerProperties) {
pipeline_id: PipelineId,
layer_id: LayerId,
epoch: Epoch,
rect: Rect<f32>,
scroll_policy: ScrollPolicy,
unrendered_color: Color) {
match self.scene.root { match self.scene.root {
Some(ref root_layer) => { Some(ref root_layer) => {
let parent_layer_id = root_layer.extra_data.borrow().id; let parent_layer_id = root_layer.extra_data.borrow().id;
match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(), match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(),
pipeline_id, layer_properties.pipeline_id,
parent_layer_id) { parent_layer_id) {
Some(ref mut parent_layer) => { Some(ref mut parent_layer) => {
let page_size = root_layer.extra_data.borrow().page_size.unwrap(); let page_size = root_layer.extra_data.borrow().page_size.unwrap();
CompositorData::add_child(parent_layer.clone(), CompositorData::add_child(parent_layer.clone(), layer_properties, page_size);
layer_id,
epoch,
rect,
page_size,
scroll_policy,
unrendered_color);
} }
None => { None => {
fail!("Compositor: couldn't find parent layer"); fail!("Compositor: couldn't find parent layer");

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use compositor_task::LayerProperties;
use pipeline::CompositionPipeline; use pipeline::CompositionPipeline;
use windowing::{MouseWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent}; use windowing::{MouseWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent};
use windowing::{MouseWindowMouseUpEvent}; use windowing::{MouseWindowMouseUpEvent};
@ -146,27 +147,23 @@ impl CompositorData {
/// exist yet. The child layer will have the same pipeline, tile size, memory limit, and CPU /// exist yet. The child layer will have the same pipeline, tile size, memory limit, and CPU
/// painting status as its parent. /// painting status as its parent.
pub fn add_child(layer: Rc<Layer<CompositorData>>, pub fn add_child(layer: Rc<Layer<CompositorData>>,
child_layer_id: LayerId, layer_properties: LayerProperties,
epoch: Epoch, page_size: Size2D<f32>) {
rect: Rect<f32>,
page_size: Size2D<f32>,
scroll_policy: ScrollPolicy,
unrendered_color: Color) {
let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(), let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(),
child_layer_id, layer_properties.id,
epoch, layer_properties.epoch,
rect, layer_properties.rect,
Some(page_size), Some(page_size),
layer.extra_data.borrow().cpu_painting, layer.extra_data.borrow().cpu_painting,
DoesntWantScrollEvents, DoesntWantScrollEvents,
scroll_policy, layer_properties.scroll_policy,
unrendered_color); layer_properties.background_color);
let new_kid = Rc::new(Layer::new(page_size, let new_kid = Rc::new(Layer::new(page_size,
Layer::tile_size(layer.clone()), Layer::tile_size(layer.clone()),
new_compositor_data)); new_compositor_data));
new_kid.extra_data.borrow_mut().scissor = Some(rect); new_kid.extra_data.borrow_mut().scissor = Some(layer_properties.rect);
*new_kid.origin.borrow_mut() = rect.origin; *new_kid.origin.borrow_mut() = layer_properties.rect.origin;
// Place the kid's layer in the container passed in. // Place the kid's layer in the container passed in.
Layer::add_child(layer.clone(), new_kid.clone()); Layer::add_child(layer.clone(), new_kid.clone());
@ -416,13 +413,10 @@ impl CompositorData {
} }
} }
pub fn update_layer(layer: Rc<Layer<CompositorData>>, pub fn update_layer(layer: Rc<Layer<CompositorData>>, layer_properties: LayerProperties) {
epoch: Epoch, layer.extra_data.borrow_mut().epoch = layer_properties.epoch;
rect: Rect<f32>, layer.extra_data.borrow_mut().unrendered_color = layer_properties.background_color;
unrendered_color: Color) { CompositorData::resize(layer.clone(), layer_properties.rect.size);
layer.extra_data.borrow_mut().epoch = epoch;
layer.extra_data.borrow_mut().unrendered_color = unrendered_color;
CompositorData::resize(layer.clone(), rect.size);
} }
// Resize and unhide a pre-existing layer. A new layer's size is set during creation. // Resize and unhide a pre-existing layer. A new layer's size is set during creation.

View file

@ -61,6 +61,31 @@ impl ScriptListener for CompositorChan {
} }
} }
pub struct LayerProperties {
pub pipeline_id: PipelineId,
pub epoch: Epoch,
pub id: LayerId,
pub rect: Rect<f32>,
pub background_color: Color,
pub scroll_policy: ScrollPolicy,
}
impl LayerProperties {
fn new(pipeline_id: PipelineId, epoch: Epoch, metadata: &LayerMetadata) -> LayerProperties {
LayerProperties {
pipeline_id: pipeline_id,
epoch: epoch,
id: metadata.id,
rect: Rect(Point2D(metadata.position.origin.x as f32,
metadata.position.origin.y as f32),
Size2D(metadata.position.size.width as f32,
metadata.position.size.height as f32)),
background_color: metadata.background_color,
scroll_policy: metadata.scroll_policy,
}
}
}
/// Implementation of the abstract `RenderListener` interface. /// Implementation of the abstract `RenderListener` interface.
impl RenderListener for CompositorChan { impl RenderListener for CompositorChan {
fn get_graphics_metadata(&self) -> Option<NativeGraphicsMetadata> { fn get_graphics_metadata(&self) -> Option<NativeGraphicsMetadata> {
@ -86,29 +111,15 @@ impl RenderListener for CompositorChan {
// `position: fixed` but will not be sufficient to handle `overflow: scroll` or transforms. // `position: fixed` but will not be sufficient to handle `overflow: scroll` or transforms.
let mut first = true; let mut first = true;
for metadata in metadata.iter() { for metadata in metadata.iter() {
let origin = Point2D(metadata.position.origin.x as f32, let layer_properties = LayerProperties::new(pipeline_id, epoch, metadata);
metadata.position.origin.y as f32);
let size = Size2D(metadata.position.size.width as f32,
metadata.position.size.height as f32);
let rect = Rect(origin, size);
if first { if first {
self.chan.send(CreateOrUpdateRootLayer(pipeline_id, self.chan.send(CreateOrUpdateRootLayer(layer_properties));
metadata.id,
epoch,
size,
metadata.background_color));
first = false first = false
} else { } else {
self.chan self.chan.send(CreateOrUpdateDescendantLayer(layer_properties));
.send(CreateOrUpdateDescendantLayer(pipeline_id,
metadata.id,
epoch,
rect,
metadata.scroll_policy,
metadata.background_color));
} }
self.chan.send(SetLayerClipRect(pipeline_id, metadata.id, rect)); self.chan.send(SetLayerClipRect(pipeline_id, metadata.id, layer_properties.rect));
} }
} }
@ -160,10 +171,10 @@ pub enum Msg {
/// Tells the compositor to create the root layer for a pipeline if necessary (i.e. if no layer /// Tells the compositor to create the root layer for a pipeline if necessary (i.e. if no layer
/// with that ID exists). /// with that ID exists).
CreateOrUpdateRootLayer(PipelineId, LayerId, Epoch, Size2D<f32>, Color), CreateOrUpdateRootLayer(LayerProperties),
/// Tells the compositor to create a descendant layer for a pipeline if necessary (i.e. if no /// Tells the compositor to create a descendant layer for a pipeline if necessary (i.e. if no
/// layer with that ID exists). /// layer with that ID exists).
CreateOrUpdateDescendantLayer(PipelineId, LayerId, Epoch, Rect<f32>, ScrollPolicy, Color), CreateOrUpdateDescendantLayer(LayerProperties),
/// Alerts the compositor that the specified layer's clipping rect has changed. /// Alerts the compositor that the specified layer's clipping rect has changed.
SetLayerClipRect(PipelineId, LayerId, Rect<f32>), SetLayerClipRect(PipelineId, LayerId, Rect<f32>),
/// Scroll a page in a window /// Scroll a page in a window