Auto merge of #11804 - Ms2ger:layout-thread-crate, r=jdm

Introduce a layout_thread crate; drop the dependency of layout on script.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11804)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-20 17:00:13 -05:00 committed by GitHub
commit a94d3ee744
10 changed files with 223 additions and 106 deletions

View file

@ -21,7 +21,6 @@ gfx_traits = {path = "../gfx_traits"}
heapsize = "0.3.0"
heapsize_plugin = "0.1.2"
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
layout_traits = {path = "../layout_traits"}
libc = "0.2"
log = "0.3.5"
msg = {path = "../msg"}
@ -30,11 +29,9 @@ plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
rustc-serialize = "0.3"
script = {path = "../script"}
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = {version = "0.6", features = ["heap_size"]}
serde_json = "0.7"
serde_macros = "0.7"
smallvec = "0.1"
string_cache = {version = "0.2.20", features = ["heap_size"]}

View file

@ -46,7 +46,6 @@ use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, HAS_LAYER,
use gfx::display_list::{ClippingRegion, StackingContext};
use gfx_traits::{LayerId, StackingContextId};
use layout_debug;
use layout_thread::DISPLAY_PORT_SIZE_FACTOR;
use model::{CollapsibleMargins, MaybeAuto, specified, specified_or_none};
use model::{self, IntrinsicISizes, MarginCollapseInfo};
use rustc_serialize::{Encodable, Encoder};
@ -64,6 +63,9 @@ use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use util::geometry::MAX_RECT;
use util::print_tree::PrintTree;
/// The number of screens of data we're allowed to generate display lists for in each direction.
const DISPLAY_PORT_SIZE_FACTOR: i32 = 8;
/// Information specific to floated blocks.
#[derive(Clone, RustcEncodable)]
pub struct FloatedBlockInfo {

View file

@ -6,7 +6,6 @@
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(custom_derive)]
#![feature(mpsc_select)]
#![feature(nonzero)]
#![feature(plugin)]
#![feature(raw)]
@ -32,7 +31,6 @@ extern crate gfx;
extern crate gfx_traits;
extern crate heapsize;
extern crate ipc_channel;
extern crate layout_traits;
extern crate libc;
#[macro_use]
extern crate log;
@ -46,11 +44,9 @@ extern crate profile_traits;
#[macro_use]
extern crate range;
extern crate rustc_serialize;
extern crate script;
extern crate script_layout_interface;
extern crate script_traits;
extern crate selectors;
extern crate serde_json;
extern crate smallvec;
#[macro_use(atom, ns)] extern crate string_cache;
extern crate style;
@ -63,32 +59,31 @@ extern crate util;
extern crate webrender_traits;
#[macro_use]
mod layout_debug;
pub mod layout_debug;
mod animation;
pub mod animation;
mod block;
mod construct;
mod context;
pub mod construct;
pub mod context;
mod data;
mod display_list_builder;
pub mod display_list_builder;
mod flex;
mod floats;
mod flow;
pub mod flow;
mod flow_list;
mod flow_ref;
pub mod flow_ref;
mod fragment;
mod generated_content;
mod incremental;
pub mod incremental;
mod inline;
pub mod layout_thread;
mod list_item;
mod model;
mod multicol;
mod opaque_node;
mod parallel;
pub mod parallel;
mod persistent_list;
mod query;
mod sequential;
pub mod query;
pub mod sequential;
mod table;
mod table_caption;
mod table_cell;
@ -97,9 +92,9 @@ mod table_row;
mod table_rowgroup;
mod table_wrapper;
mod text;
mod traversal;
mod webrender_helpers;
mod wrapper;
pub mod traversal;
pub mod webrender_helpers;
pub mod wrapper;
// For unit tests:
pub use fragment::Fragment;

View file

@ -12,9 +12,9 @@ use euclid::size::Size2D;
use flow;
use flow_ref::FlowRef;
use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
use gfx::display_list::OpaqueNode;
use gfx::display_list::{DisplayItemMetadata, DisplayList, OpaqueNode, ScrollOffsetMap};
use gfx_traits::LayerId;
use layout_thread::LayoutThreadData;
use ipc_channel::ipc::IpcSender;
use opaque_node::OpaqueNodeMethods;
use script_layout_interface::rpc::{ContentBoxResponse, ContentBoxesResponse};
use script_layout_interface::rpc::{HitTestResponse, LayoutRPC};
@ -35,10 +35,57 @@ use style::properties::ComputedValues;
use style::properties::longhands::{display, position};
use style::properties::style_structs;
use style::selector_impl::PseudoElement;
use style::servo::Stylist;
use style::values::AuExtensionMethods;
use style_traits::cursor::Cursor;
use wrapper::ThreadSafeLayoutNodeHelpers;
/// Mutable data belonging to the LayoutThread.
///
/// This needs to be protected by a mutex so we can do fast RPCs.
pub struct LayoutThreadData {
/// The channel on which messages can be sent to the constellation.
pub constellation_chan: IpcSender<ConstellationMsg>,
/// The root stacking context.
pub display_list: Option<Arc<DisplayList>>,
/// Performs CSS selector matching and style resolution.
pub stylist: Arc<Stylist>,
/// A queued response for the union of the content boxes of a node.
pub content_box_response: Rect<Au>,
/// A queued response for the content boxes of a node.
pub content_boxes_response: Vec<Rect<Au>>,
/// A queued response for the client {top, left, width, height} of a node in pixels.
pub client_rect_response: Rect<i32>,
pub layer_id_response: Option<LayerId>,
/// A queued response for the node at a given point
pub hit_test_response: (Option<DisplayItemMetadata>, bool),
/// A pair of overflow property in x and y
pub overflow_response: NodeOverflowResponse,
/// A queued response for the scroll {top, left, width, height} of a node in pixels.
pub scroll_area_response: Rect<i32>,
/// A queued response for the resolved style property of an element.
pub resolved_style_response: Option<String>,
/// A queued response for the offset parent/rect of a node.
pub offset_parent_response: OffsetParentResponse,
/// A queued response for the offset parent/rect of a node.
pub margin_style_response: MarginStyleResponse,
/// Scroll offsets of stacking contexts. This will only be populated if WebRender is in use.
pub stacking_context_scroll_offsets: ScrollOffsetMap,
}
pub struct LayoutRPCImpl(pub Arc<Mutex<LayoutThreadData>>);
// https://drafts.csswg.org/cssom-view/#overflow-directions

View file

@ -0,0 +1,36 @@
[package]
name = "layout_thread"
version = "0.0.1"
authors = ["The Servo Project Developers"]
publish = false
[lib]
name = "layout_thread"
path = "lib.rs"
[dependencies]
app_units = {version = "0.2.3", features = ["plugins"]}
azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]}
euclid = {version = "0.6.4", features = ["plugins"]}
fnv = "1.0"
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.3.0"
heapsize_plugin = "0.1.2"
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
layout = {path = "../layout"}
layout_traits = {path = "../layout_traits"}
log = "0.3.5"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
script = {path = "../script"}
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
serde_json = "0.7"
serde_macros = "0.7"
style = {path = "../style"}
url = {version = "1.0.0", features = ["heap_size"]}
util = {path = "../util"}
webrender_traits = {git = "https://github.com/servo/webrender_traits"}

View file

@ -5,47 +5,83 @@
//! The layout thread. Performs layout on the DOM, builds display lists and sends them to be
//! painted.
#![allow(unsafe_code)]
#![feature(box_syntax)]
#![feature(custom_derive)]
#![feature(mpsc_select)]
#![feature(plugin)]
#![plugin(heapsize_plugin)]
#![plugin(plugins)]
extern crate app_units;
extern crate azure;
extern crate core;
extern crate euclid;
extern crate fnv;
extern crate gfx;
extern crate gfx_traits;
extern crate heapsize;
extern crate ipc_channel;
#[macro_use]
extern crate layout;
extern crate layout_traits;
#[macro_use]
extern crate log;
extern crate msg;
extern crate net_traits;
#[macro_use]
extern crate profile_traits;
extern crate script;
extern crate script_layout_interface;
extern crate script_traits;
extern crate serde_json;
extern crate style;
extern crate url;
extern crate util;
extern crate webrender_traits;
use animation;
use app_units::Au;
use azure::azure::AzColor;
use construct::ConstructionResult;
use context::{LayoutContext, SharedLayoutContext, heap_size_of_local_context};
use display_list_builder::ToGfxColor;
use euclid::Matrix4D;
use euclid::point::Point2D;
use euclid::rect::Rect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::Size2D;
use flow::{self, Flow, ImmutableFlowUtils, MutableOwnedFlowUtils};
use flow_ref::{self, FlowRef};
use fnv::FnvHasher;
use gfx::display_list::{ClippingRegion, DisplayItemMetadata, DisplayList, LayerInfo, OpaqueNode};
use gfx::display_list::{ScrollOffsetMap, StackingContext, StackingContextType, WebRenderImageInfo};
use gfx::display_list::{ClippingRegion, DisplayList, LayerInfo, OpaqueNode};
use gfx::display_list::{StackingContext, StackingContextType, WebRenderImageInfo};
use gfx::font;
use gfx::font_cache_thread::FontCacheThread;
use gfx::font_context;
use gfx::paint_thread::LayoutToPaintMsg;
use gfx_traits::{color, Epoch, FragmentType, LayerId, ScrollPolicy, StackingContextId};
use heapsize::HeapSizeOf;
use incremental::{LayoutDamageComputation, REFLOW_ENTIRE_DOCUMENT};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout_debug;
use layout::animation;
use layout::construct::ConstructionResult;
use layout::context::{LayoutContext, SharedLayoutContext, heap_size_of_local_context};
use layout::display_list_builder::ToGfxColor;
use layout::flow::{self, Flow, ImmutableFlowUtils, MutableOwnedFlowUtils};
use layout::flow_ref::{self, FlowRef};
use layout::incremental::{LayoutDamageComputation, REFLOW_ENTIRE_DOCUMENT};
use layout::layout_debug;
use layout::parallel;
use layout::query::process_offset_parent_query;
use layout::query::{LayoutRPCImpl, LayoutThreadData, process_content_box_request, process_content_boxes_request};
use layout::query::{process_node_geometry_request, process_node_layer_id_request, process_node_scroll_area_request};
use layout::query::{process_node_overflow_request, process_resolved_style_request, process_margin_style_query};
use layout::sequential;
use layout::traversal::RecalcStyleAndConstructFlows;
use layout::webrender_helpers::{WebRenderDisplayListConverter, WebRenderFrameBuilder};
use layout::wrapper::{LayoutNodeLayoutData, NonOpaqueStyleAndLayoutData};
use layout_traits::LayoutThreadFactory;
use log;
use msg::constellation_msg::{PanicMsg, PipelineId};
use net_traits::image_cache_thread::UsePlaceholder;
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread};
use parallel;
use profile_traits::mem::{self, Report, ReportKind, ReportsChan};
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use profile_traits::time::{self, TimerMetadata, profile};
use query::process_offset_parent_query;
use query::{LayoutRPCImpl, process_content_box_request, process_content_boxes_request};
use query::{process_node_geometry_request, process_node_layer_id_request, process_node_scroll_area_request};
use query::{process_node_overflow_request, process_resolved_style_request, process_margin_style_query};
use script::layout_wrapper::ServoLayoutNode;
use script_layout_interface::message::{Msg, NewLayoutThreadInfo, Reflow, ReflowQueryType, ScriptReflow};
use script_layout_interface::reporter::CSSErrorReporter;
@ -55,8 +91,6 @@ use script_layout_interface::wrapper_traits::LayoutNode;
use script_layout_interface::{OpaqueStyleAndLayoutData, PartialStyleAndLayoutData};
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
use script_traits::{StackingContextScrollState, UntrustedNodeAddress};
use sequential;
use serde_json;
use std::borrow::ToOwned;
use std::cell::RefCell;
use std::collections::HashMap;
@ -77,7 +111,6 @@ use style::properties::ComputedValues;
use style::selector_matching::USER_OR_USER_AGENT_STYLESHEETS;
use style::servo::{SharedStyleContext, Stylesheet, Stylist};
use style::stylesheets::CSSRuleIteratorExt;
use traversal::RecalcStyleAndConstructFlows;
use url::Url;
use util::geometry::MAX_RECT;
use util::ipc::OptionalIpcSender;
@ -85,62 +118,10 @@ use util::opts;
use util::thread;
use util::thread_state;
use util::workqueue::WorkQueue;
use webrender_helpers::{WebRenderDisplayListConverter, WebRenderFrameBuilder};
use webrender_traits;
use wrapper::{LayoutNodeLayoutData, NonOpaqueStyleAndLayoutData};
/// 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;
/// The number of screens we have to traverse before we decide to generate new display lists.
const DISPLAY_PORT_THRESHOLD_SIZE_FACTOR: i32 = 4;
/// Mutable data belonging to the LayoutThread.
///
/// This needs to be protected by a mutex so we can do fast RPCs.
pub struct LayoutThreadData {
/// The channel on which messages can be sent to the constellation.
pub constellation_chan: IpcSender<ConstellationMsg>,
/// The root stacking context.
pub display_list: Option<Arc<DisplayList>>,
/// Performs CSS selector matching and style resolution.
pub stylist: Arc<Stylist>,
/// A queued response for the union of the content boxes of a node.
pub content_box_response: Rect<Au>,
/// A queued response for the content boxes of a node.
pub content_boxes_response: Vec<Rect<Au>>,
/// A queued response for the client {top, left, width, height} of a node in pixels.
pub client_rect_response: Rect<i32>,
pub layer_id_response: Option<LayerId>,
/// A queued response for the node at a given point
pub hit_test_response: (Option<DisplayItemMetadata>, bool),
/// A pair of overflow property in x and y
pub overflow_response: NodeOverflowResponse,
/// A queued response for the scroll {top, left, width, height} of a node in pixels.
pub scroll_area_response: Rect<i32>,
/// A queued response for the resolved style property of an element.
pub resolved_style_response: Option<String>,
/// A queued response for the offset parent/rect of a node.
pub offset_parent_response: OffsetParentResponse,
/// A queued response for the offset parent/rect of a node.
pub margin_style_response: MarginStyleResponse,
/// Scroll offsets of stacking contexts. This will only be populated if WebRender is in use.
pub stacking_context_scroll_offsets: ScrollOffsetMap,
}
/// Information needed by the layout thread.
pub struct LayoutThread {
/// The ID of the pipeline that we belong to.

View file

@ -21,6 +21,7 @@ dependencies = [
"ipc-channel 0.2.3 (git+https://github.com/servo/ipc-channel)",
"layout 0.0.1",
"layout_tests 0.0.1",
"layout_thread 0.0.1",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
@ -1131,7 +1132,6 @@ dependencies = [
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.3 (git+https://github.com/servo/ipc-channel)",
"layout_traits 0.0.1",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
@ -1140,11 +1140,9 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1165,6 +1163,37 @@ dependencies = [
"layout 0.0.1",
]
[[package]]
name = "layout_thread"
version = "0.0.1"
dependencies = [
"app_units 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.4.5 (git+https://github.com/servo/rust-azure)",
"euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.0.1",
"gfx_traits 0.0.1",
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.3 (git+https://github.com/servo/ipc-channel)",
"layout 0.0.1",
"layout_traits 0.0.1",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"plugins 0.0.1",
"profile_traits 0.0.1",
"script 0.0.1",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
]
[[package]]
name = "layout_traits"
version = "0.0.1"

View file

@ -57,6 +57,7 @@ util = {path = "../util"}
script = {path = "../script"}
script_traits = {path = "../script_traits"}
layout = {path = "../layout"}
layout_thread = {path = "../layout_thread"}
gfx = {path = "../gfx"}
style = {path = "../style"}
canvas = {path = "../canvas"}

View file

@ -31,7 +31,7 @@ pub extern crate devtools_traits;
pub extern crate euclid;
pub extern crate gfx;
pub extern crate ipc_channel;
pub extern crate layout;
pub extern crate layout_thread;
pub extern crate msg;
pub extern crate net;
pub extern crate net_traits;
@ -233,7 +233,7 @@ fn create_constellation(opts: opts::Opts,
};
let constellation_chan =
Constellation::<script_layout_interface::message::Msg,
layout::layout_thread::LayoutThread,
layout_thread::LayoutThread,
script::script_thread::ScriptThread>::start(initial_state);
// Send the URL command to the constellation.
@ -267,7 +267,7 @@ pub fn run_content_process(token: String) {
script::init();
unprivileged_content.start_all::<script_layout_interface::message::Msg,
layout::layout_thread::LayoutThread,
layout_thread::LayoutThread,
script::script_thread::ScriptThread>(true);
}

35
ports/cef/Cargo.lock generated
View file

@ -1043,7 +1043,6 @@ dependencies = [
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.3 (git+https://github.com/servo/ipc-channel)",
"layout_traits 0.0.1",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
@ -1052,11 +1051,9 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1070,6 +1067,37 @@ dependencies = [
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
]
[[package]]
name = "layout_thread"
version = "0.0.1"
dependencies = [
"app_units 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.4.5 (git+https://github.com/servo/rust-azure)",
"euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.0.1",
"gfx_traits 0.0.1",
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.3 (git+https://github.com/servo/ipc-channel)",
"layout 0.0.1",
"layout_traits 0.0.1",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"plugins 0.0.1",
"profile_traits 0.0.1",
"script 0.0.1",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
]
[[package]]
name = "layout_traits"
version = "0.0.1"
@ -1896,6 +1924,7 @@ dependencies = [
"glutin_app 0.0.1",
"ipc-channel 0.2.3 (git+https://github.com/servo/ipc-channel)",
"layout 0.0.1",
"layout_thread 0.0.1",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",