Skip to content

Commit

Permalink
Auto merge of servo#8595 - bholley:generalize_wrappers, r=pcwalton
Browse files Browse the repository at this point in the history
Generalize the layout wrapper layer

There's still more refactoring to do, but this is the core stuff that's most likely to bitrot.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8595)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 19, 2015
2 parents 1dd4c08 + 2f6e949 commit a5babb8
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 254 deletions.
30 changes: 15 additions & 15 deletions components/layout/css/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use util::arc_ptr_eq;
use util::cache::{LRUCache, SimpleHashCache};
use util::opts;
use util::vec::ForgetfulSink;
use wrapper::{LayoutElement, LayoutNode};
use wrapper::{LayoutElement, LayoutNode, ServoLayoutElement, ServoLayoutNode};

pub struct ApplicableDeclarations {
pub normal: SmallVec<[DeclarationBlock; 16]>,
Expand Down Expand Up @@ -160,7 +160,7 @@ pub struct StyleSharingCandidateCache {
cache: LRUCache<StyleSharingCandidate, ()>,
}

fn create_common_style_affecting_attributes_from_element(element: &LayoutElement)
fn create_common_style_affecting_attributes_from_element(element: &ServoLayoutElement)
-> CommonStyleAffectingAttributes {
let mut flags = CommonStyleAffectingAttributes::empty();
for attribute_info in &common_style_affecting_attributes() {
Expand Down Expand Up @@ -211,7 +211,7 @@ impl StyleSharingCandidate {
/// Attempts to create a style sharing candidate from this node. Returns
/// the style sharing candidate or `None` if this node is ineligible for
/// style sharing.
fn new(element: &LayoutElement) -> Option<StyleSharingCandidate> {
fn new(element: &ServoLayoutElement) -> Option<StyleSharingCandidate> {
let parent_element = match element.parent_element() {
None => return None,
Some(parent_element) => parent_element,
Expand Down Expand Up @@ -257,7 +257,7 @@ impl StyleSharingCandidate {
})
}

fn can_share_style_with(&self, element: &LayoutElement) -> bool {
fn can_share_style_with(&self, element: &ServoLayoutElement) -> bool {
if *element.get_local_name() != self.local_name {
return false
}
Expand Down Expand Up @@ -342,7 +342,7 @@ impl StyleSharingCandidateCache {
self.cache.iter()
}

pub fn insert_if_possible(&mut self, element: &LayoutElement) {
pub fn insert_if_possible(&mut self, element: &ServoLayoutElement) {
match StyleSharingCandidate::new(element) {
None => {}
Some(candidate) => self.cache.insert(candidate, ())
Expand Down Expand Up @@ -376,7 +376,7 @@ pub trait ElementMatchMethods {
unsafe fn share_style_if_possible(&self,
style_sharing_candidate_cache:
&mut StyleSharingCandidateCache,
parent: Option<LayoutNode>)
parent: Option<ServoLayoutNode>)
-> StyleSharingResult;
}

Expand All @@ -396,7 +396,7 @@ pub trait MatchMethods {

unsafe fn cascade_node(&self,
layout_context: &SharedLayoutContext,
parent: Option<LayoutNode>,
parent: Option<ServoLayoutNode>,
applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache,
new_animations_sender: &Mutex<Sender<Animation>>);
Expand All @@ -418,12 +418,12 @@ trait PrivateMatchMethods {

trait PrivateElementMatchMethods {
fn share_style_with_candidate_if_possible(&self,
parent_node: Option<LayoutNode>,
parent_node: Option<ServoLayoutNode>,
candidate: &StyleSharingCandidate)
-> Option<Arc<ComputedValues>>;
}

impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
impl<'ln> PrivateMatchMethods for ServoLayoutNode<'ln> {
fn cascade_node_pseudo_element(&self,
layout_context: &SharedLayoutContext,
parent_style: Option<&Arc<ComputedValues>>,
Expand Down Expand Up @@ -502,9 +502,9 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
}
}

impl<'ln> PrivateElementMatchMethods for LayoutElement<'ln> {
impl<'ln> PrivateElementMatchMethods for ServoLayoutElement<'ln> {
fn share_style_with_candidate_if_possible(&self,
parent_node: Option<LayoutNode>,
parent_node: Option<ServoLayoutNode>,
candidate: &StyleSharingCandidate)
-> Option<Arc<ComputedValues>> {
let parent_node = match parent_node {
Expand Down Expand Up @@ -537,7 +537,7 @@ impl<'ln> PrivateElementMatchMethods for LayoutElement<'ln> {
}
}

impl<'ln> ElementMatchMethods for LayoutElement<'ln> {
impl<'ln> ElementMatchMethods for ServoLayoutElement<'ln> {
fn match_element(&self,
stylist: &Stylist,
parent_bf: Option<&BloomFilter>,
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<'ln> ElementMatchMethods for LayoutElement<'ln> {
unsafe fn share_style_if_possible(&self,
style_sharing_candidate_cache:
&mut StyleSharingCandidateCache,
parent: Option<LayoutNode>)
parent: Option<ServoLayoutNode>)
-> StyleSharingResult {
if opts::get().disable_share_style_cache {
return StyleSharingResult::CannotShare
Expand Down Expand Up @@ -603,7 +603,7 @@ impl<'ln> ElementMatchMethods for LayoutElement<'ln> {
}
}

impl<'ln> MatchMethods for LayoutNode<'ln> {
impl<'ln> MatchMethods for ServoLayoutNode<'ln> {
// The below two functions are copy+paste because I can't figure out how to
// write a function which takes a generic function. I don't think it can
// be done.
Expand Down Expand Up @@ -645,7 +645,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {

unsafe fn cascade_node(&self,
layout_context: &SharedLayoutContext,
parent: Option<LayoutNode>,
parent: Option<ServoLayoutNode>,
applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache,
new_animations_sender: &Mutex<Sender<Animation>>) {
Expand Down
12 changes: 6 additions & 6 deletions components/layout/layout_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use util::opts;
use util::task::spawn_named_with_send_on_failure;
use util::task_state;
use util::workqueue::WorkQueue;
use wrapper::{LayoutNode, ThreadSafeLayoutNode};
use wrapper::{LayoutDocument, LayoutElement, LayoutNode, ServoLayoutNode, ThreadSafeLayoutNode};

/// The number of screens of data we're allowed to generate display lists for in each direction.
pub const DISPLAY_PORT_SIZE_FACTOR: i32 = 8;
Expand Down Expand Up @@ -750,7 +750,7 @@ impl LayoutTask {
possibly_locked_rw_data.block(rw_data);
}

fn try_get_layout_root(&self, node: LayoutNode) -> Option<FlowRef> {
fn try_get_layout_root(&self, node: ServoLayoutNode) -> Option<FlowRef> {
let mut layout_data_ref = node.mutate_layout_data();
let layout_data =
match layout_data_ref.as_mut() {
Expand Down Expand Up @@ -828,7 +828,7 @@ impl LayoutTask {
property: &Atom,
layout_root: &mut FlowRef)
-> Option<String> {
let node = unsafe { LayoutNode::new(&requested_node) };
let node = unsafe { ServoLayoutNode::new(&requested_node) };

let layout_node = ThreadSafeLayoutNode::new(&node);
let layout_node = match pseudo {
Expand Down Expand Up @@ -1063,14 +1063,14 @@ impl LayoutTask {
fn handle_reflow<'a, 'b>(&mut self,
data: &ScriptReflow,
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let document = unsafe { LayoutNode::new(&data.document) };
let document = unsafe { ServoLayoutNode::new(&data.document) };
let document = document.as_document().unwrap();

debug!("layout: received layout request for: {}", self.url.serialize());

let mut rw_data = possibly_locked_rw_data.lock();

let node: LayoutNode = match document.root_node() {
let node: ServoLayoutNode = match document.root_node() {
None => {
// Since we cannot compute anything, give spec-required placeholders.
debug!("layout: No root node: bailing");
Expand Down Expand Up @@ -1418,7 +1418,7 @@ impl LayoutTask {
}
}

unsafe fn dirty_all_nodes(node: LayoutNode) {
unsafe fn dirty_all_nodes(node: ServoLayoutNode) {
for node in node.traverse_preorder() {
// TODO(cgaebel): mark nodes which are sensitive to media queries as
// "changed":
Expand Down
8 changes: 4 additions & 4 deletions components/layout/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use traversal::{PostorderDomTraversal, PreorderDomTraversal};
use util::opts;
use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
use wrapper::UnsafeLayoutNode;
use wrapper::{LayoutNode, layout_node_from_unsafe_layout_node, layout_node_to_unsafe_layout_node};
use wrapper::{LayoutNode, ServoLayoutNode, layout_node_from_unsafe_layout_node, layout_node_to_unsafe_layout_node};

const CHUNK_SIZE: usize = 64;

Expand Down Expand Up @@ -103,7 +103,7 @@ pub trait ParallelPreorderDomTraversal : PreorderDomTraversal {
let mut discovered_child_nodes = Vec::new();
for unsafe_node in *unsafe_nodes.0 {
// Get a real layout node.
let node: LayoutNode = unsafe {
let node: ServoLayoutNode = unsafe {
layout_node_from_unsafe_layout_node(&unsafe_node)
};

Expand Down Expand Up @@ -157,7 +157,7 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal {
/// fetch-and-subtract the parent's children count.
fn run_parallel(&self, unsafe_node: UnsafeLayoutNode) {
// Get a real layout node.
let mut node: LayoutNode = unsafe {
let mut node: ServoLayoutNode = unsafe {
layout_node_from_unsafe_layout_node(&unsafe_node)
};
loop {
Expand Down Expand Up @@ -440,7 +440,7 @@ fn run_queue_with_custom_work_data_type<To, F>(
queue.run(shared_layout_context);
}

pub fn traverse_dom_preorder(root: LayoutNode,
pub fn traverse_dom_preorder(root: ServoLayoutNode,
shared_layout_context: &SharedLayoutContext,
queue: &mut WorkQueue<SharedLayoutContext, WorkQueueData>) {
run_queue_with_custom_work_data_type(queue, |queue| {
Expand Down
6 changes: 3 additions & 3 deletions components/layout/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use traversal::{BuildDisplayList, ComputeAbsolutePositions};
use traversal::{PostorderDomTraversal, PreorderDomTraversal};
use util::geometry::ZERO_POINT;
use util::opts;
use wrapper::LayoutNode;
use wrapper::{LayoutNode, ServoLayoutNode};

pub fn traverse_dom_preorder(root: LayoutNode,
pub fn traverse_dom_preorder(root: ServoLayoutNode,
shared_layout_context: &SharedLayoutContext) {
fn doit(node: LayoutNode, recalc_style: RecalcStyleForNode, construct_flows: ConstructFlows) {
fn doit(node: ServoLayoutNode, recalc_style: RecalcStyleForNode, construct_flows: ConstructFlows) {
recalc_style.process(node);

for kid in node.children() {
Expand Down
14 changes: 7 additions & 7 deletions components/layout/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::cell::RefCell;
use std::mem;
use util::opts;
use util::tid::tid;
use wrapper::{LayoutNode, layout_node_to_unsafe_layout_node};
use wrapper::{LayoutNode, ServoLayoutNode, layout_node_to_unsafe_layout_node};
use wrapper::{ThreadSafeLayoutNode, UnsafeLayoutNode};

/// Every time we do another layout, the old bloom filters are invalid. This is
Expand Down Expand Up @@ -51,7 +51,7 @@ thread_local!(
///
/// If one does not exist, a new one will be made for you. If it is out of date,
/// it will be cleared and reused.
fn take_task_local_bloom_filter(parent_node: Option<LayoutNode>,
fn take_task_local_bloom_filter(parent_node: Option<ServoLayoutNode>,
root: OpaqueNode,
layout_context: &LayoutContext)
-> Box<BloomFilter> {
Expand Down Expand Up @@ -98,7 +98,7 @@ fn put_task_local_bloom_filter(bf: Box<BloomFilter>,

/// "Ancestors" in this context is inclusive of ourselves.
fn insert_ancestors_into_bloom_filter(bf: &mut Box<BloomFilter>,
mut n: LayoutNode,
mut n: ServoLayoutNode,
root: OpaqueNode) {
debug!("[{}] Inserting ancestors.", tid());
let mut ancestors = 0;
Expand All @@ -118,13 +118,13 @@ fn insert_ancestors_into_bloom_filter(bf: &mut Box<BloomFilter>,
/// A top-down traversal.
pub trait PreorderDomTraversal {
/// The operation to perform. Return true to continue or false to stop.
fn process(&self, node: LayoutNode);
fn process(&self, node: ServoLayoutNode);
}

/// A bottom-up traversal, with a optional in-order pass.
pub trait PostorderDomTraversal {
/// The operation to perform. Return true to continue or false to stop.
fn process(&self, node: LayoutNode);
fn process(&self, node: ServoLayoutNode);
}

/// A bottom-up, parallelizable traversal.
Expand All @@ -144,7 +144,7 @@ pub struct RecalcStyleForNode<'a> {
impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
#[inline]
#[allow(unsafe_code)]
fn process(&self, node: LayoutNode) {
fn process(&self, node: ServoLayoutNode) {
// Initialize layout data.
//
// FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML
Expand Down Expand Up @@ -249,7 +249,7 @@ pub struct ConstructFlows<'a> {
impl<'a> PostorderDomTraversal for ConstructFlows<'a> {
#[inline]
#[allow(unsafe_code)]
fn process(&self, node: LayoutNode) {
fn process(&self, node: ServoLayoutNode) {
// Construct flows for this node.
{
let tnode = ThreadSafeLayoutNode::new(&node);
Expand Down
Loading

0 comments on commit a5babb8

Please sign in to comment.