mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Update to latest rust-layers
Layers now store their complete boundaries, so we can eliminate the various ways these were stored in Servo.
This commit is contained in:
parent
78eeb8e2e7
commit
71225e87ca
4 changed files with 47 additions and 93 deletions
|
@ -372,7 +372,8 @@ impl IOCompositor {
|
||||||
self.opts.cpu_painting,
|
self.opts.cpu_painting,
|
||||||
layer_properties.background_color);
|
layer_properties.background_color);
|
||||||
let size = layer_properties.rect.size;
|
let size = layer_properties.rect.size;
|
||||||
let new_root = Rc::new(Layer::new(size,
|
let new_root = Rc::new(Layer::new(layer_properties.rect,
|
||||||
|
size,
|
||||||
self.opts.tile_size,
|
self.opts.tile_size,
|
||||||
new_compositor_data));
|
new_compositor_data));
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use pipeline::CompositionPipeline;
|
||||||
|
|
||||||
use azure::azure_hl::Color;
|
use azure::azure_hl::Color;
|
||||||
use geom::matrix::identity;
|
use geom::matrix::identity;
|
||||||
use geom::point::{Point2D, TypedPoint2D};
|
use geom::point::TypedPoint2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::size::{Size2D, TypedSize2D};
|
use geom::size::{Size2D, TypedSize2D};
|
||||||
use gfx::render_task::{ReRenderMsg, UnusedBufferMsg};
|
use gfx::render_task::{ReRenderMsg, UnusedBufferMsg};
|
||||||
|
@ -41,9 +41,6 @@ pub struct CompositorData {
|
||||||
/// top left corner of the page.
|
/// top left corner of the page.
|
||||||
pub scroll_offset: TypedPoint2D<PagePx, f32>,
|
pub scroll_offset: TypedPoint2D<PagePx, f32>,
|
||||||
|
|
||||||
/// The bounds of this layer in terms of its parent (a.k.a. the scissor box).
|
|
||||||
pub bounds: Rect<f32>,
|
|
||||||
|
|
||||||
/// The size of the underlying page in page coordinates. This is an option
|
/// The size of the underlying page in page coordinates. This is an option
|
||||||
/// because we may not know the size of the page until layout is finished completely.
|
/// because we may not know the size of the page until layout is finished completely.
|
||||||
/// if we have no size yet, the layer is hidden until a size message is recieved.
|
/// if we have no size yet, the layer is hidden until a size message is recieved.
|
||||||
|
@ -65,8 +62,6 @@ pub struct CompositorData {
|
||||||
/// The color to use for the unrendered-content void
|
/// The color to use for the unrendered-content void
|
||||||
pub unrendered_color: Color,
|
pub unrendered_color: Color,
|
||||||
|
|
||||||
pub scissor: Option<Rect<f32>>,
|
|
||||||
|
|
||||||
/// A monotonically increasing counter that keeps track of the current epoch.
|
/// A monotonically increasing counter that keeps track of the current epoch.
|
||||||
/// add_buffer() calls that don't match the current epoch will be ignored.
|
/// add_buffer() calls that don't match the current epoch will be ignored.
|
||||||
pub epoch: Epoch,
|
pub epoch: Epoch,
|
||||||
|
@ -82,7 +77,6 @@ impl CompositorData {
|
||||||
pub fn new(pipeline: CompositionPipeline,
|
pub fn new(pipeline: CompositionPipeline,
|
||||||
layer_id: LayerId,
|
layer_id: LayerId,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
bounds: Rect<f32>,
|
|
||||||
page_size: Option<Size2D<f32>>,
|
page_size: Option<Size2D<f32>>,
|
||||||
cpu_painting: bool,
|
cpu_painting: bool,
|
||||||
wants_scroll_events: WantsScrollEventsFlag,
|
wants_scroll_events: WantsScrollEventsFlag,
|
||||||
|
@ -93,14 +87,12 @@ impl CompositorData {
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
id: layer_id,
|
id: layer_id,
|
||||||
scroll_offset: TypedPoint2D(0f32, 0f32),
|
scroll_offset: TypedPoint2D(0f32, 0f32),
|
||||||
bounds: bounds,
|
|
||||||
page_size: page_size,
|
page_size: page_size,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
wants_scroll_events: wants_scroll_events,
|
wants_scroll_events: wants_scroll_events,
|
||||||
scroll_policy: scroll_policy,
|
scroll_policy: scroll_policy,
|
||||||
cpu_painting: cpu_painting,
|
cpu_painting: cpu_painting,
|
||||||
unrendered_color: unrendered_color,
|
unrendered_color: unrendered_color,
|
||||||
scissor: None,
|
|
||||||
epoch: epoch,
|
epoch: epoch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +105,6 @@ impl CompositorData {
|
||||||
CompositorData::new(pipeline,
|
CompositorData::new(pipeline,
|
||||||
LayerId::null(),
|
LayerId::null(),
|
||||||
epoch,
|
epoch,
|
||||||
Rect(Point2D(0f32, 0f32), page_size),
|
|
||||||
Some(page_size),
|
Some(page_size),
|
||||||
cpu_painting,
|
cpu_painting,
|
||||||
WantsScrollEvents,
|
WantsScrollEvents,
|
||||||
|
@ -130,19 +121,16 @@ impl CompositorData {
|
||||||
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.id,
|
||||||
layer_properties.epoch,
|
layer_properties.epoch,
|
||||||
layer_properties.rect,
|
|
||||||
Some(page_size),
|
Some(page_size),
|
||||||
layer.extra_data.borrow().cpu_painting,
|
layer.extra_data.borrow().cpu_painting,
|
||||||
DoesntWantScrollEvents,
|
DoesntWantScrollEvents,
|
||||||
layer_properties.scroll_policy,
|
layer_properties.scroll_policy,
|
||||||
layer_properties.background_color);
|
layer_properties.background_color);
|
||||||
let new_kid = Rc::new(Layer::new(page_size,
|
let new_kid = Rc::new(Layer::new(layer_properties.rect,
|
||||||
|
page_size,
|
||||||
Layer::tile_size(layer.clone()),
|
Layer::tile_size(layer.clone()),
|
||||||
new_compositor_data));
|
new_compositor_data));
|
||||||
|
|
||||||
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.
|
// Place the kid's layer in the container passed in.
|
||||||
Layer::add_child(layer.clone(), new_kid.clone());
|
Layer::add_child(layer.clone(), new_kid.clone());
|
||||||
}
|
}
|
||||||
|
@ -178,18 +166,16 @@ impl CompositorData {
|
||||||
}
|
}
|
||||||
|
|
||||||
let send_child_buffer_request = |kid: &Rc<Layer<CompositorData>>| -> bool {
|
let send_child_buffer_request = |kid: &Rc<Layer<CompositorData>>| -> bool {
|
||||||
match kid.extra_data.borrow().scissor {
|
|
||||||
Some(scissor) => {
|
|
||||||
let mut new_rect = window_rect;
|
let mut new_rect = window_rect;
|
||||||
let offset = kid.extra_data.borrow().scroll_offset.to_untyped();
|
let offset = kid.extra_data.borrow().scroll_offset.to_untyped();
|
||||||
new_rect.origin.x = new_rect.origin.x - offset.x;
|
new_rect.origin.x = new_rect.origin.x - offset.x;
|
||||||
new_rect.origin.y = new_rect.origin.y - offset.y;
|
new_rect.origin.y = new_rect.origin.y - offset.y;
|
||||||
match new_rect.intersection(&scissor) {
|
match new_rect.intersection(&*kid.bounds.borrow()) {
|
||||||
Some(new_rect) => {
|
Some(new_rect) => {
|
||||||
// Child layers act as if they are rendered at (0,0), so we
|
// Child layers act as if they are rendered at (0,0), so we
|
||||||
// subtract the layer's (x,y) coords in its containing page
|
// subtract the layer's (x,y) coords in its containing page
|
||||||
// to make the child_rect appear in coordinates local to it.
|
// to make the child_rect appear in coordinates local to it.
|
||||||
let child_rect = Rect(new_rect.origin.sub(&scissor.origin),
|
let child_rect = Rect(new_rect.origin.sub(&kid.bounds.borrow().origin),
|
||||||
new_rect.size);
|
new_rect.size);
|
||||||
CompositorData::send_buffer_requests_recursively(kid.clone(),
|
CompositorData::send_buffer_requests_recursively(kid.clone(),
|
||||||
graphics_context,
|
graphics_context,
|
||||||
|
@ -200,9 +186,6 @@ impl CompositorData {
|
||||||
false // Layer is offscreen
|
false // Layer is offscreen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
None => fail!("child layer not clipped!"),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
layer.children().iter().filter(|x| !x.extra_data.borrow().hidden)
|
layer.children().iter().filter(|x| !x.extra_data.borrow().hidden)
|
||||||
|
@ -225,16 +208,12 @@ impl CompositorData {
|
||||||
layer_id) {
|
layer_id) {
|
||||||
Some(child_node) => {
|
Some(child_node) => {
|
||||||
debug!("compositor_data: node found for set_clipping_rect()");
|
debug!("compositor_data: node found for set_clipping_rect()");
|
||||||
*child_node.origin.borrow_mut() = new_rect.origin;
|
let old_rect = child_node.bounds.borrow().clone();
|
||||||
let old_rect = child_node.extra_data.borrow().scissor.clone();
|
*child_node.bounds.borrow_mut() = new_rect;
|
||||||
child_node.extra_data.borrow_mut().scissor = Some(new_rect);
|
|
||||||
match old_rect {
|
|
||||||
Some(old_rect) => {
|
|
||||||
// Rect is unhidden
|
// Rect is unhidden
|
||||||
Layer::set_status_page(layer.clone(), old_rect, Normal, false);
|
Layer::set_status_page(layer.clone(), old_rect, Normal, false);
|
||||||
}
|
|
||||||
None => {} // Nothing to do
|
|
||||||
}
|
|
||||||
// Hide the new rect
|
// Hide the new rect
|
||||||
Layer::set_status_page(layer.clone(), new_rect, Hidden, false);
|
Layer::set_status_page(layer.clone(), new_rect, Hidden, false);
|
||||||
|
|
||||||
|
@ -276,20 +255,14 @@ impl CompositorData {
|
||||||
let _ = layer.extra_data.borrow().pipeline.render_chan.send_opt(msg);
|
let _ = layer.extra_data.borrow().pipeline.render_chan.send_opt(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
let scissor_clone = layer.extra_data.borrow().scissor.clone();
|
|
||||||
match scissor_clone {
|
|
||||||
Some(scissor) => {
|
|
||||||
// Call scroll for bounds checking if the page shrunk. Use (-1, -1) as the
|
// Call scroll for bounds checking if the page shrunk. Use (-1, -1) as the
|
||||||
// cursor position to make sure the scroll isn't propagated downwards.
|
// cursor position to make sure the scroll isn't propagated downwards.
|
||||||
let size: TypedSize2D<PagePx, f32> = Size2D::from_untyped(&scissor.size);
|
let size: TypedSize2D<PagePx, f32> = Size2D::from_untyped(&layer.bounds.borrow().size);
|
||||||
events::handle_scroll_event(layer.clone(),
|
events::handle_scroll_event(layer.clone(),
|
||||||
TypedPoint2D(0f32, 0f32),
|
TypedPoint2D(0f32, 0f32),
|
||||||
TypedPoint2D(-1f32, -1f32),
|
TypedPoint2D(-1f32, -1f32),
|
||||||
size);
|
size);
|
||||||
layer.extra_data.borrow_mut().hidden = false;
|
layer.extra_data.borrow_mut().hidden = false;
|
||||||
}
|
|
||||||
None => {} // Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
CompositorData::set_occlusions(layer.clone());
|
CompositorData::set_occlusions(layer.clone());
|
||||||
}
|
}
|
||||||
|
@ -437,12 +410,7 @@ impl CompositorData {
|
||||||
fn set_occlusions(layer: Rc<Layer<CompositorData>>) {
|
fn set_occlusions(layer: Rc<Layer<CompositorData>>) {
|
||||||
for kid in layer.children().iter() {
|
for kid in layer.children().iter() {
|
||||||
if !kid.extra_data.borrow().hidden {
|
if !kid.extra_data.borrow().hidden {
|
||||||
match kid.extra_data.borrow().scissor {
|
Layer::set_status_page(layer.clone(), *kid.bounds.borrow(), Hidden, false);
|
||||||
None => {} // Nothing to do
|
|
||||||
Some(rect) => {
|
|
||||||
Layer::set_status_page(layer.clone(), rect, Hidden, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,7 @@ pub fn handle_scroll_event(layer: Rc<Layer<CompositorData>>,
|
||||||
// Allow children to scroll.
|
// Allow children to scroll.
|
||||||
let cursor = cursor - layer.extra_data.borrow().scroll_offset;
|
let cursor = cursor - layer.extra_data.borrow().scroll_offset;
|
||||||
for child in layer.children().iter() {
|
for child in layer.children().iter() {
|
||||||
match child.extra_data.borrow().scissor {
|
let rect: TypedRect<PagePx, f32> = Rect::from_untyped(&*child.bounds.borrow());
|
||||||
None => {
|
|
||||||
error!("CompositorData: unable to perform cursor hit test for layer");
|
|
||||||
}
|
|
||||||
Some(rect) => {
|
|
||||||
let rect: TypedRect<PagePx, f32> = Rect::from_untyped(&rect);
|
|
||||||
if rect.contains(&cursor) &&
|
if rect.contains(&cursor) &&
|
||||||
handle_scroll_event(child.clone(),
|
handle_scroll_event(child.clone(),
|
||||||
delta,
|
delta,
|
||||||
|
@ -74,8 +69,6 @@ pub fn handle_scroll_event(layer: Rc<Layer<CompositorData>>,
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This scroll event is mine!
|
// This scroll event is mine!
|
||||||
// Scroll this layer!
|
// Scroll this layer!
|
||||||
|
@ -141,19 +134,12 @@ pub fn send_mouse_event(layer: Rc<Layer<CompositorData>>,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
match child.extra_data.borrow().scissor {
|
let rect: TypedRect<PagePx, f32> = Rect::from_untyped(&*child.bounds.borrow());
|
||||||
None => {
|
|
||||||
error!("CompositorData: unable to perform cursor hit test for layer");
|
|
||||||
}
|
|
||||||
Some(rect) => {
|
|
||||||
let rect: TypedRect<PagePx, f32> = Rect::from_untyped(&rect);
|
|
||||||
if rect.contains(&cursor) {
|
if rect.contains(&cursor) {
|
||||||
send_mouse_event(child.clone(), event, cursor - rect.origin);
|
send_mouse_event(child.clone(), event, cursor - rect.origin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This mouse event is mine!
|
// This mouse event is mine!
|
||||||
let message = match event {
|
let message = match event {
|
||||||
|
@ -215,4 +201,3 @@ pub fn move(layer: Rc<Layer<CompositorData>>,
|
||||||
let offset = layer.extra_data.borrow().scroll_offset.clone();
|
let offset = layer.extra_data.borrow().scroll_offset.clone();
|
||||||
scroll(layer.clone(), offset)
|
scroll(layer.clone(), offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f49717435a375a1e3beb26777b7303204e0a1a8a
|
Subproject commit 168305cc4229eb79fb33ad045ec0b39f8097966a
|
Loading…
Add table
Add a link
Reference in a new issue