Auto merge of #26120 - servo:layout-2020-non-opaque-style-data, r=SimonSapin

Remove postorder traversal from layout 2020 during styling
This commit is contained in:
bors-servo 2020-04-07 10:38:16 -04:00 committed by GitHub
commit d8781c1054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 208 additions and 269 deletions

View file

@ -97,7 +97,7 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan;
use script_layout_interface::message::PendingRestyle;
use script_layout_interface::rpc::LayoutRPC;
use script_layout_interface::OpaqueStyleAndLayoutData;
use script_layout_interface::StyleAndOpaqueLayoutData;
use script_traits::serializable::BlobImpl;
use script_traits::transferable::MessagePortImpl;
use script_traits::{DocumentActivity, DrawAPaintImageResult};
@ -508,7 +508,7 @@ unsafe_no_jsmanaged_fields!(StatusCode);
unsafe_no_jsmanaged_fields!(SystemTime);
unsafe_no_jsmanaged_fields!(Instant);
unsafe_no_jsmanaged_fields!(RelativePos);
unsafe_no_jsmanaged_fields!(OpaqueStyleAndLayoutData);
unsafe_no_jsmanaged_fields!(StyleAndOpaqueLayoutData);
unsafe_no_jsmanaged_fields!(PathBuf);
unsafe_no_jsmanaged_fields!(DrawAPaintImageResult);
unsafe_no_jsmanaged_fields!(DocumentId);

View file

@ -396,7 +396,7 @@ impl Element {
/// style will be `None` for elements in a `display: none` subtree. otherwise, the element has a
/// layout box iff it doesn't have `display: none`.
pub fn style(&self) -> Option<Arc<ComputedValues>> {
window_from_node(self).style_query(self.upcast::<Node>().to_trusted_node_address())
self.upcast::<Node>().style()
}
// https://drafts.csswg.org/cssom-view/#css-layout-box

View file

@ -75,8 +75,9 @@ use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use net_traits::image::base::{Image, ImageMetadata};
use ref_slice::ref_slice;
use script_layout_interface::message::QueryMsg;
use script_layout_interface::{HTMLCanvasData, HTMLMediaData, LayoutElementType, LayoutNodeType};
use script_layout_interface::{OpaqueStyleAndLayoutData, SVGSVGData, TrustedNodeAddress};
use script_layout_interface::{SVGSVGData, StyleAndOpaqueLayoutData, TrustedNodeAddress};
use script_traits::DocumentActivity;
use script_traits::UntrustedNodeAddress;
use selectors::matching::{matches_selector_list, MatchingContext, MatchingMode};
@ -95,6 +96,7 @@ use std::ops::Range;
use std::sync::Arc as StdArc;
use style::context::QuirksMode;
use style::dom::OpaqueNode;
use style::properties::ComputedValues;
use style::selector_parser::{SelectorImpl, SelectorParser};
use style::stylesheets::Stylesheet;
use uuid::Uuid;
@ -152,8 +154,8 @@ pub struct Node {
///
/// Must be sent back to the layout thread to be destroyed when this
/// node is finalized.
#[ignore_malloc_size_of = "shrug"]
style_and_layout_data: UnsafeCell<Option<OpaqueStyleAndLayoutData>>,
#[ignore_malloc_size_of = "Unsafe cell"]
style_and_layout_data: UnsafeCell<Option<Box<StyleAndOpaqueLayoutData>>>,
}
bitflags! {
@ -1229,6 +1231,23 @@ impl Node {
_ => false,
}
}
#[allow(unsafe_code)]
pub fn style(&self) -> Option<Arc<ComputedValues>> {
if !window_from_node(self).layout_reflow(QueryMsg::StyleQuery) {
return None;
}
unsafe {
(*self.style_and_layout_data.get()).as_ref().map(|data| {
data.style_data
.element_data
.borrow()
.styles
.primary()
.clone()
})
}
}
}
/// Iterate through `nodes` until we find a `Node` that is not in `not_in`
@ -1282,9 +1301,9 @@ pub trait LayoutNodeHelpers<'dom> {
fn children_count(self) -> u32;
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData>;
unsafe fn init_style_and_layout_data(self, data: OpaqueStyleAndLayoutData);
unsafe fn take_style_and_layout_data(self) -> OpaqueStyleAndLayoutData;
fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData>;
unsafe fn init_style_and_opaque_layout_data(self, data: Box<StyleAndOpaqueLayoutData>);
unsafe fn take_style_and_opaque_layout_data(self) -> Box<StyleAndOpaqueLayoutData>;
fn text_content(self) -> Cow<'dom, str>;
fn selection(self) -> Option<Range<usize>>;
@ -1410,13 +1429,13 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
#[inline]
#[allow(unsafe_code)]
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
unsafe { (*self.unsafe_get().style_and_layout_data.get()).as_ref() }
fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData> {
unsafe { (*self.unsafe_get().style_and_layout_data.get()).as_deref() }
}
#[inline]
#[allow(unsafe_code)]
unsafe fn init_style_and_layout_data(self, val: OpaqueStyleAndLayoutData) {
unsafe fn init_style_and_opaque_layout_data(self, val: Box<StyleAndOpaqueLayoutData>) {
let data = &mut *self.unsafe_get().style_and_layout_data.get();
debug_assert!(data.is_none());
*data = Some(val);
@ -1424,7 +1443,7 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
#[inline]
#[allow(unsafe_code)]
unsafe fn take_style_and_layout_data(self) -> OpaqueStyleAndLayoutData {
unsafe fn take_style_and_opaque_layout_data(self) -> Box<StyleAndOpaqueLayoutData> {
(*self.unsafe_get().style_and_layout_data.get())
.take()
.unwrap()

View file

@ -131,7 +131,7 @@ use style::dom::OpaqueNode;
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
use style::media_queries;
use style::parser::ParserContext as CssParserContext;
use style::properties::{ComputedValues, PropertyId};
use style::properties::PropertyId;
use style::selector_parser::PseudoElement;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::CssRuleType;
@ -1904,13 +1904,6 @@ impl Window {
(element, response.rect)
}
pub fn style_query(&self, node: TrustedNodeAddress) -> Option<servo_arc::Arc<ComputedValues>> {
if !self.layout_reflow(QueryMsg::StyleQuery(node)) {
return None;
}
self.layout_rpc.style().0
}
pub fn text_index_query(
&self,
node: &Node,
@ -2461,7 +2454,7 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow
&QueryMsg::NodeScrollIdQuery(_n) => "\tNodeScrollIdQuery",
&QueryMsg::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery",
&QueryMsg::OffsetParentQuery(_n) => "\tOffsetParentQuery",
&QueryMsg::StyleQuery(_n) => "\tStyleQuery",
&QueryMsg::StyleQuery => "\tStyleQuery",
&QueryMsg::TextIndexQuery(..) => "\tTextIndexQuery",
&QueryMsg::ElementInnerTextQuery(_) => "\tElementInnerTextQuery",
&QueryMsg::InnerWindowDimensionsQuery(_) => "\tInnerWindowDimensionsQuery",