From ca77ca998e3e7714da449b39ce6169e9eb81b8d4 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Tue, 8 Jul 2014 11:03:45 -0700 Subject: [PATCH] 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. --- src/components/compositing/compositor.rs | 124 ++++-------------- src/components/compositing/compositor_data.rs | 34 ++--- src/components/compositing/compositor_task.rs | 51 ++++--- 3 files changed, 74 insertions(+), 135 deletions(-) diff --git a/src/components/compositing/compositor.rs b/src/components/compositing/compositor.rs index 522aba58245..bd76573a0b0 100644 --- a/src/components/compositing/compositor.rs +++ b/src/components/compositing/compositor.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 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::{SetLayerClipRect, Paint, ScrollFragmentPoint, LoadComplete}; use compositor_task::{ShutdownComplete, ChangeRenderState}; @@ -18,12 +18,12 @@ use windowing::{QuitWindowEvent, RefreshWindowEvent, ResizeWindowEvent, ScrollWi use windowing::{WindowEvent, WindowMethods, WindowNavigateMsg, ZoomWindowEvent}; use windowing::PinchZoomWindowEvent; -use azure::azure_hl::{SourceSurfaceMethods, Color}; +use azure::azure_hl::SourceSurfaceMethods; use azure::azure_hl; use geom::matrix::identity; use geom::point::{Point2D, TypedPoint2D}; use geom::rect::Rect; -use geom::size::{Size2D, TypedSize2D}; +use geom::size::TypedSize2D; use geom::scale_factor::ScaleFactor; use layers::layers::LayerBufferSet; use layers::platform::surface::NativeCompositingGraphicsContext; @@ -34,7 +34,7 @@ use layers::layers::Layer; use opengles::gl2; use png; 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::{PipelineId, ResizedWindowMsg, WindowSizeData}; use servo_msg::constellation_msg; @@ -286,28 +286,14 @@ impl IOCompositor { chan.send(Some(azure_hl::current_graphics_metadata())); } - (Ok(CreateOrUpdateRootLayer(pipeline_id, layer_id, epoch, size, color)), + (Ok(CreateOrUpdateRootLayer(layer_properties)), NotShuttingDown) => { - self.create_or_update_root_layer(pipeline_id, - layer_id, - epoch, - size, - color); + self.create_or_update_root_layer(layer_properties); } - (Ok(CreateOrUpdateDescendantLayer(pipeline_id, - layer_id, - epoch, - rect, - scroll_behavior, - color)), + (Ok(CreateOrUpdateDescendantLayer(layer_properties)), NotShuttingDown) => { - self.create_or_update_descendant_layer(pipeline_id, - layer_id, - epoch, - rect, - scroll_behavior, - color); + self.create_or_update_descendant_layer(layer_properties); } (Ok(SetLayerClipRect(pipeline_id, layer_id, new_rect)), NotShuttingDown) => { @@ -355,24 +341,14 @@ impl IOCompositor { self.send_window_size(); } - fn update_layer_if_exists(&mut self, - pipeline_id: PipelineId, - layer_id: LayerId, - epoch: Epoch, - rect: Rect, - unrendered_color: Color) - -> bool { - + fn update_layer_if_exists(&mut self, properties: LayerProperties) -> bool { match self.scene.root { Some(ref root_layer) => { match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(), - pipeline_id, - layer_id) { + properties.pipeline_id, + properties.id) { Some(existing_layer) => { - CompositorData::update_layer(existing_layer.clone(), - epoch, - rect, - unrendered_color); + CompositorData::update_layer(existing_layer.clone(), properties); true } None => false, @@ -382,40 +358,24 @@ impl IOCompositor { } } - fn create_or_update_root_layer(&mut self, - pipeline_id: PipelineId, - layer_id: LayerId, - epoch: Epoch, - size: Size2D, - 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); - + fn create_or_update_root_layer(&mut self, layer_properties: LayerProperties) { + let need_new_root_layer = !self.update_layer_if_exists(layer_properties); if need_new_root_layer { let root_pipeline = match self.root_pipeline { Some(ref root_pipeline) => root_pipeline.clone(), None => fail!("Compositor: Making new layer without initialized pipeline"), }; let new_compositor_data = CompositorData::new_root(root_pipeline, - epoch, - size, + layer_properties.epoch, + layer_properties.rect.size, self.opts.cpu_painting, - unrendered_color); + layer_properties.background_color); + let size = layer_properties.rect.size; let new_root = Rc::new(Layer::new(size, self.opts.tile_size, new_compositor_data)); - CompositorData::add_child(new_root.clone(), - layer_id, - epoch, - new_root_rect, - size, - Scrollable, - unrendered_color); + CompositorData::add_child(new_root.clone(), layer_properties, size); // Release all tiles from the layer before dropping it. match self.scene.root { @@ -425,56 +385,30 @@ impl IOCompositor { 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(); } - fn create_or_update_descendant_layer(&mut self, - pipeline_id: PipelineId, - layer_id: LayerId, - epoch: Epoch, - rect: Rect, - 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); + fn create_or_update_descendant_layer(&mut self, layer_properties: LayerProperties) { + if !self.update_layer_if_exists(layer_properties) { + self.create_descendant_layer(layer_properties); } - 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(); } - fn create_descendant_layer(&self, - pipeline_id: PipelineId, - layer_id: LayerId, - epoch: Epoch, - rect: Rect, - scroll_policy: ScrollPolicy, - unrendered_color: Color) { - + fn create_descendant_layer(&self, layer_properties: LayerProperties) { match self.scene.root { Some(ref root_layer) => { let parent_layer_id = root_layer.extra_data.borrow().id; match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(), - pipeline_id, + layer_properties.pipeline_id, parent_layer_id) { Some(ref mut parent_layer) => { let page_size = root_layer.extra_data.borrow().page_size.unwrap(); - CompositorData::add_child(parent_layer.clone(), - layer_id, - epoch, - rect, - page_size, - scroll_policy, - unrendered_color); + CompositorData::add_child(parent_layer.clone(), layer_properties, page_size); } None => { fail!("Compositor: couldn't find parent layer"); diff --git a/src/components/compositing/compositor_data.rs b/src/components/compositing/compositor_data.rs index f75a7347253..af845f5312a 100644 --- a/src/components/compositing/compositor_data.rs +++ b/src/components/compositing/compositor_data.rs @@ -2,6 +2,7 @@ * 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/. */ +use compositor_task::LayerProperties; use pipeline::CompositionPipeline; use windowing::{MouseWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent}; 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 /// painting status as its parent. pub fn add_child(layer: Rc>, - child_layer_id: LayerId, - epoch: Epoch, - rect: Rect, - page_size: Size2D, - scroll_policy: ScrollPolicy, - unrendered_color: Color) { + layer_properties: LayerProperties, + page_size: Size2D) { let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(), - child_layer_id, - epoch, - rect, + layer_properties.id, + layer_properties.epoch, + layer_properties.rect, Some(page_size), layer.extra_data.borrow().cpu_painting, DoesntWantScrollEvents, - scroll_policy, - unrendered_color); + layer_properties.scroll_policy, + layer_properties.background_color); let new_kid = Rc::new(Layer::new(page_size, Layer::tile_size(layer.clone()), new_compositor_data)); - new_kid.extra_data.borrow_mut().scissor = Some(rect); - *new_kid.origin.borrow_mut() = rect.origin; + new_kid.extra_data.borrow_mut().scissor = Some(layer_properties.rect); + *new_kid.origin.borrow_mut() = layer_properties.rect.origin; // Place the kid's layer in the container passed in. Layer::add_child(layer.clone(), new_kid.clone()); @@ -416,13 +413,10 @@ impl CompositorData { } } - pub fn update_layer(layer: Rc>, - epoch: Epoch, - rect: Rect, - unrendered_color: Color) { - layer.extra_data.borrow_mut().epoch = epoch; - layer.extra_data.borrow_mut().unrendered_color = unrendered_color; - CompositorData::resize(layer.clone(), rect.size); + pub fn update_layer(layer: Rc>, layer_properties: LayerProperties) { + layer.extra_data.borrow_mut().epoch = layer_properties.epoch; + layer.extra_data.borrow_mut().unrendered_color = layer_properties.background_color; + CompositorData::resize(layer.clone(), layer_properties.rect.size); } // Resize and unhide a pre-existing layer. A new layer's size is set during creation. diff --git a/src/components/compositing/compositor_task.rs b/src/components/compositing/compositor_task.rs index 78779439996..7534131a935 100644 --- a/src/components/compositing/compositor_task.rs +++ b/src/components/compositing/compositor_task.rs @@ -61,6 +61,31 @@ impl ScriptListener for CompositorChan { } } +pub struct LayerProperties { + pub pipeline_id: PipelineId, + pub epoch: Epoch, + pub id: LayerId, + pub rect: Rect, + 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. impl RenderListener for CompositorChan { fn get_graphics_metadata(&self) -> Option { @@ -86,29 +111,15 @@ impl RenderListener for CompositorChan { // `position: fixed` but will not be sufficient to handle `overflow: scroll` or transforms. let mut first = true; for metadata in metadata.iter() { - let origin = Point2D(metadata.position.origin.x as f32, - 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); + let layer_properties = LayerProperties::new(pipeline_id, epoch, metadata); if first { - self.chan.send(CreateOrUpdateRootLayer(pipeline_id, - metadata.id, - epoch, - size, - metadata.background_color)); + self.chan.send(CreateOrUpdateRootLayer(layer_properties)); first = false } else { - self.chan - .send(CreateOrUpdateDescendantLayer(pipeline_id, - metadata.id, - epoch, - rect, - metadata.scroll_policy, - metadata.background_color)); + self.chan.send(CreateOrUpdateDescendantLayer(layer_properties)); } - 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 /// with that ID exists). - CreateOrUpdateRootLayer(PipelineId, LayerId, Epoch, Size2D, Color), + CreateOrUpdateRootLayer(LayerProperties), /// Tells the compositor to create a descendant layer for a pipeline if necessary (i.e. if no /// layer with that ID exists). - CreateOrUpdateDescendantLayer(PipelineId, LayerId, Epoch, Rect, ScrollPolicy, Color), + CreateOrUpdateDescendantLayer(LayerProperties), /// Alerts the compositor that the specified layer's clipping rect has changed. SetLayerClipRect(PipelineId, LayerId, Rect), /// Scroll a page in a window