From 4f1bda0c3668190ef2c1635366844056be4442ff Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Wed, 12 Nov 2014 12:01:36 -0800 Subject: [PATCH] Remove some code duplication in the Compositor It is possible to share the code which creates root layers. --- components/compositing/compositor.rs | 81 ++++++++++++---------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 50a47af45a4..04d39298a35 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -423,29 +423,7 @@ impl IOCompositor { self.ready_states.insert(frame_tree.pipeline.id, Blank); self.render_states.insert(frame_tree.pipeline.id, RenderingRenderState); - let layer_properties = LayerProperties { - pipeline_id: frame_tree.pipeline.id, - epoch: Epoch(0), - id: LayerId::null(), - rect: Rect::zero(), - background_color: azure_hl::Color::new(0., 0., 0., 0.), - scroll_policy: Scrollable, - }; - let root_layer = CompositorData::new_layer(frame_tree.pipeline.clone(), - layer_properties, - WantsScrollEvents, - opts::get().tile_size); - - match frame_rect { - Some(ref frame_rect) => { - *root_layer.masks_to_bounds.borrow_mut() = true; - - let frame_rect = frame_rect.to_untyped(); - *root_layer.bounds.borrow_mut() = Rect::from_untyped(&frame_rect); - } - None => {} - } - + let root_layer = create_root_layer_for_pipeline_and_rect(&frame_tree.pipeline, frame_rect); for kid in frame_tree.children.iter() { root_layer.add_child(self.create_frame_tree_root_layers(&kid.frame_tree, kid.rect)); } @@ -453,31 +431,10 @@ impl IOCompositor { } fn update_frame_tree(&mut self, frame_tree_diff: &FrameTreeDiff) { - let layer_properties = LayerProperties { - pipeline_id: frame_tree_diff.pipeline.id, - epoch: Epoch(0), - id: LayerId::null(), - rect: Rect::zero(), - background_color: azure_hl::Color::new(0., 0., 0., 0.), - scroll_policy: Scrollable, - }; - let root_layer = CompositorData::new_layer(frame_tree_diff.pipeline.clone(), - layer_properties, - WantsScrollEvents, - opts::get().tile_size); - - match frame_tree_diff.rect { - Some(ref frame_rect) => { - *root_layer.masks_to_bounds.borrow_mut() = true; - - let frame_rect = frame_rect.to_untyped(); - *root_layer.bounds.borrow_mut() = Rect::from_untyped(&frame_rect); - } - None => {} - } - let parent_layer = self.find_pipeline_root_layer(frame_tree_diff.parent_pipeline.id); - parent_layer.add_child(root_layer); + parent_layer.add_child( + create_root_layer_for_pipeline_and_rect(&frame_tree_diff.pipeline, + frame_tree_diff.rect)); } fn find_pipeline_root_layer(&self, pipeline_id: PipelineId) -> Rc> { @@ -1122,6 +1079,36 @@ fn find_layer_with_pipeline_and_layer_id_for_layer(layer: Rc>) + -> Rc> { + let layer_properties = LayerProperties { + pipeline_id: pipeline.id, + epoch: Epoch(0), + id: LayerId::null(), + rect: Rect::zero(), + background_color: azure_hl::Color::new(0., 0., 0., 0.), + scroll_policy: Scrollable, + }; + + let root_layer = CompositorData::new_layer(pipeline.clone(), + layer_properties, + WantsScrollEvents, + opts::get().tile_size); + + match frame_rect { + Some(ref frame_rect) => { + *root_layer.masks_to_bounds.borrow_mut() = true; + + let frame_rect = frame_rect.to_untyped(); + *root_layer.bounds.borrow_mut() = Rect::from_untyped(&frame_rect); + } + None => {} + } + + return root_layer; +} + impl CompositorEventListener for IOCompositor where Window: WindowMethods { fn handle_event(&mut self, msg: WindowEvent) -> bool { // Check for new messages coming from the other tasks in the system.