diff --git a/src/components/compositing/compositor.rs b/src/components/compositing/compositor.rs index 2107928a719..1034ec5f07c 100644 --- a/src/components/compositing/compositor.rs +++ b/src/components/compositing/compositor.rs @@ -404,13 +404,20 @@ impl IOCompositor { new_root.extra_data.borrow_mut().unrendered_color = unrendered_color; let parent_layer_id = new_root.extra_data.borrow().id; - assert!(CompositorData::add_child_if_necessary(new_root.clone(), - root_pipeline_id, - parent_layer_id, + match CompositorData::find_layer_with_layer_and_pipeline_id(new_root.clone(), + root_pipeline_id, + parent_layer_id) { + Some(ref mut parent_layer) => { + CompositorData::add_child_if_necessary(parent_layer.clone(), layer_id, Rect(Point2D(0f32, 0f32), size), size, - Scrollable)); + Scrollable); + } + None => { + fail!("Compositor: couldn't find parent layer"); + } + } // Release all tiles from the layer before dropping it. match self.scene.root { @@ -429,19 +436,26 @@ impl IOCompositor { rect: Rect, scroll_policy: ScrollPolicy) { match self.scene.root { - Some(ref root) => { - let parent_layer_id = root.extra_data.borrow().id; - let page_size = root.extra_data.borrow().page_size.unwrap(); - assert!(CompositorData::add_child_if_necessary(root.clone(), - pipeline_id, - parent_layer_id, + 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, + parent_layer_id) { + Some(ref mut parent_layer) => { + let page_size = root_layer.extra_data.borrow().page_size.unwrap(); + CompositorData::add_child_if_necessary(parent_layer.clone(), layer_id, rect, page_size, - scroll_policy)) + scroll_policy); + } + None => { + fail!("Compositor: couldn't find parent layer"); + } + } } - None => fail!("Compositor: Received new layer without initialized pipeline"), - }; + None => fail!("Compositor: Received new layer without initialized pipeline") + } self.ask_for_tiles(); } diff --git a/src/components/compositing/compositor_data.rs b/src/components/compositing/compositor_data.rs index 0a72fd955cb..ed67fe1584c 100644 --- a/src/components/compositing/compositor_data.rs +++ b/src/components/compositing/compositor_data.rs @@ -146,38 +146,18 @@ impl CompositorData { /// Adds a child layer to the layer with the given ID and the given pipeline, if it doesn't /// exist yet. The child layer will have the same pipeline, tile size, memory limit, and CPU /// painting status as its parent. - /// - /// Returns: - /// * True if the layer was added; - /// * True if the layer was not added because it already existed; - /// * False if the layer could not be added because no suitable parent layer with the given - /// ID and pipeline could be found. pub fn add_child_if_necessary(layer: Rc>, - pipeline_id: PipelineId, - parent_layer_id: LayerId, child_layer_id: LayerId, rect: Rect, page_size: Size2D, - scroll_policy: ScrollPolicy) -> bool { - if layer.extra_data.borrow().pipeline.id != pipeline_id || - layer.extra_data.borrow().id != parent_layer_id { - return layer.children().iter().any(|kid| { - CompositorData::add_child_if_necessary(kid.clone(), - pipeline_id, - parent_layer_id, - child_layer_id, - rect, - page_size, - scroll_policy) - }) - } - + scroll_policy: ScrollPolicy) { // See if we've already made this child layer. + let pipeline_id = layer.extra_data.borrow().pipeline.id; if layer.children().iter().any(|kid| { kid.extra_data.borrow().pipeline.id == pipeline_id && kid.extra_data.borrow().id == child_layer_id }) { - return true + return; } let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(), @@ -197,8 +177,6 @@ impl CompositorData { // Place the kid's layer in the container passed in. Layer::add_child(layer.clone(), new_kid.clone()); - - true } /// Move the layer's descendants that don't want scroll events and scroll by a relative