Allow individual layers to render their own background color

Instead of relying on a scene-wide background color, all layers can now
have their own background color.
This commit is contained in:
Martin Robinson 2014-09-23 19:43:29 -07:00
parent d168501555
commit fbd0b6f9d0
4 changed files with 57 additions and 55 deletions

View file

@ -6,11 +6,12 @@ use compositor_task::LayerProperties;
use events;
use pipeline::CompositionPipeline;
use azure::azure_hl::Color;
use azure::azure_hl;
use geom::point::TypedPoint2D;
use geom::size::Size2D;
use geom::rect::Rect;
use gfx::render_task::UnusedBufferMsg;
use layers::color::Color;
use layers::geometry::LayerPixel;
use layers::layers::{Layer, LayerBufferSet};
use layers::platform::surface::NativeSurfaceMethods;
@ -32,9 +33,6 @@ pub struct CompositorData {
/// Whether an ancestor layer that receives scroll events moves this layer.
pub scroll_policy: ScrollPolicy,
/// The color to use for the unrendered-content void
pub background_color: Color,
/// A monotonically increasing counter that keeps track of the current epoch.
/// add_buffer() calls that don't match the current epoch will be ignored.
pub epoch: Epoch,
@ -50,6 +48,10 @@ pub enum WantsScrollEventsFlag {
DoesntWantScrollEvents,
}
fn to_layers_color(color: &azure_hl::Color) -> Color {
Color { r: color.r, g: color.g, b: color.b, a: color.a }
}
impl CompositorData {
pub fn new_layer(pipeline: CompositionPipeline,
layer_properties: LayerProperties,
@ -61,20 +63,23 @@ impl CompositorData {
id: layer_properties.id,
wants_scroll_events: wants_scroll_events,
scroll_policy: layer_properties.scroll_policy,
background_color: layer_properties.background_color,
epoch: layer_properties.epoch,
scroll_offset: TypedPoint2D(0., 0.),
};
Rc::new(Layer::new(Rect::from_untyped(&layer_properties.rect),
tile_size, new_compositor_data))
tile_size,
to_layers_color(&layer_properties.background_color),
new_compositor_data))
}
pub fn update_layer_except_size(layer: Rc<Layer<CompositorData>>,
layer_properties: LayerProperties) {
layer.extra_data.borrow_mut().epoch = layer_properties.epoch;
layer.extra_data.borrow_mut().scroll_policy = layer_properties.scroll_policy;
layer.extra_data.borrow_mut().background_color = layer_properties.background_color;
*layer.background_color.borrow_mut() = to_layers_color(&layer_properties.background_color);
layer.contents_changed();
}