Simplify CompositorData creation

We already have a layer_properties struct, so we should always use it
instead of passing the information in it out-of-band.
This commit is contained in:
Cameron Zwarich 2014-07-19 20:14:42 -07:00
parent 61105dcbff
commit 31049adc1d
2 changed files with 23 additions and 31 deletions

View file

@ -2,7 +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_data::CompositorData; use compositor_data::{CompositorData, WantsScrollEvents};
use compositor_task::{Msg, CompositorTask, Exit, ChangeReadyState, SetIds, LayerProperties}; 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};
@ -34,7 +34,7 @@ use layers::scene::Scene;
use layers::layers::Layer; 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, FixedPosition, FinishedLoading, IdleRenderState};
use servo_msg::compositor_msg::{LayerId, ReadyState, RenderState}; 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};
@ -364,9 +364,18 @@ impl IOCompositor {
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,
layer_properties.epoch, let root_properties = LayerProperties {
layer_properties.background_color); pipeline_id: root_pipeline.id,
epoch: layer_properties.epoch,
id: LayerId::null(),
rect: Rect::zero(),
background_color: layer_properties.background_color,
scroll_policy: FixedPosition,
};
let new_compositor_data = CompositorData::new(root_pipeline,
root_properties,
WantsScrollEvents);
let new_root = Rc::new(Layer::new(layer_properties.rect, let new_root = Rc::new(Layer::new(layer_properties.rect,
self.opts.tile_size, self.opts.tile_size,
new_compositor_data)); new_compositor_data));

View file

@ -13,7 +13,7 @@ use geom::size::{Size2D, TypedSize2D};
use gfx::render_task::{ReRenderRequest, RenderChan, UnusedBufferMsg}; use gfx::render_task::{ReRenderRequest, RenderChan, UnusedBufferMsg};
use layers::layers::{Layer, LayerBufferSet}; use layers::layers::{Layer, LayerBufferSet};
use layers::platform::surface::NativeSurfaceMethods; use layers::platform::surface::NativeSurfaceMethods;
use servo_msg::compositor_msg::{Epoch, FixedPosition, LayerId}; use servo_msg::compositor_msg::{Epoch, LayerId};
use servo_msg::compositor_msg::ScrollPolicy; use servo_msg::compositor_msg::ScrollPolicy;
use servo_msg::constellation_msg::PipelineId; use servo_msg::constellation_msg::PipelineId;
use servo_util::geometry::PagePx; use servo_util::geometry::PagePx;
@ -53,45 +53,28 @@ pub enum WantsScrollEventsFlag {
impl CompositorData { impl CompositorData {
pub fn new(pipeline: CompositionPipeline, pub fn new(pipeline: CompositionPipeline,
layer_id: LayerId, layer_properties: LayerProperties,
epoch: Epoch, wants_scroll_events: WantsScrollEventsFlag)
wants_scroll_events: WantsScrollEventsFlag,
scroll_policy: ScrollPolicy,
background_color: Color)
-> CompositorData { -> CompositorData {
CompositorData { CompositorData {
pipeline: pipeline, pipeline: pipeline,
id: layer_id, id: layer_properties.id,
scroll_offset: TypedPoint2D(0f32, 0f32), scroll_offset: TypedPoint2D(0f32, 0f32),
wants_scroll_events: wants_scroll_events, wants_scroll_events: wants_scroll_events,
scroll_policy: scroll_policy, scroll_policy: layer_properties.scroll_policy,
background_color: background_color, background_color: layer_properties.background_color,
epoch: epoch, epoch: layer_properties.epoch,
} }
} }
pub fn new_root(pipeline: CompositionPipeline,
epoch: Epoch,
background_color: Color) -> CompositorData {
CompositorData::new(pipeline,
LayerId::null(),
epoch,
WantsScrollEvents,
FixedPosition,
background_color)
}
/// Adds a child layer to the layer with the given ID and the given pipeline, if it doesn't /// 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 /// 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>>,
layer_properties: LayerProperties) { layer_properties: LayerProperties) {
let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(), let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(),
layer_properties.id, layer_properties,
layer_properties.epoch, DoesntWantScrollEvents);
DoesntWantScrollEvents,
layer_properties.scroll_policy,
layer_properties.background_color);
let new_kid = Rc::new(Layer::new(layer_properties.rect, let new_kid = Rc::new(Layer::new(layer_properties.rect,
layer.tile_size, layer.tile_size,
new_compositor_data)); new_compositor_data));