mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Make DOM own the style and layout data, in an UnsafeCell
The previous Cell was a lie.
This commit is contained in:
parent
516e8e0aa6
commit
185a402d9c
17 changed files with 74 additions and 180 deletions
|
@ -1036,7 +1036,7 @@ fn inner_text_collection_steps<'dom>(
|
|||
_ => child,
|
||||
};
|
||||
|
||||
let element_data = unsafe {
|
||||
let element_data = {
|
||||
&node.get_style_and_layout_data().as_ref().map(|opaque| {
|
||||
&opaque
|
||||
.downcast_ref::<StyleAndLayoutData>()
|
||||
|
|
|
@ -73,7 +73,7 @@ where
|
|||
// flow construction:
|
||||
// (1) They child doesn't yet have layout data (preorder traversal initializes it).
|
||||
// (2) The parent element has restyle damage (so the text flow also needs fixup).
|
||||
(unsafe { node.get_raw_data().is_none() }) || !parent_data.damage.is_empty()
|
||||
node.get_raw_data().is_none() || !parent_data.damage.is_empty()
|
||||
}
|
||||
|
||||
fn shared_context(&self) -> &SharedStyleContext {
|
||||
|
|
|
@ -39,24 +39,22 @@ use style::selector_parser::RestyleDamage;
|
|||
use style::values::computed::counters::ContentItem;
|
||||
use style::values::generics::counters::Content;
|
||||
|
||||
pub trait LayoutNodeLayoutData {
|
||||
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
|
||||
/// than only the style::data::ElementData.
|
||||
fn borrow_layout_data(&self) -> Option<AtomicRef<LayoutData>>;
|
||||
fn mutate_layout_data(&self) -> Option<AtomicRefMut<LayoutData>>;
|
||||
pub trait LayoutNodeLayoutData<'dom> {
|
||||
fn borrow_layout_data(self) -> Option<AtomicRef<'dom, LayoutData>>;
|
||||
fn mutate_layout_data(self) -> Option<AtomicRefMut<'dom, LayoutData>>;
|
||||
fn flow_debug_id(self) -> usize;
|
||||
}
|
||||
|
||||
impl<'dom, T> LayoutNodeLayoutData for T
|
||||
impl<'dom, T> LayoutNodeLayoutData<'dom> for T
|
||||
where
|
||||
T: GetLayoutData<'dom>,
|
||||
{
|
||||
fn borrow_layout_data(&self) -> Option<AtomicRef<LayoutData>> {
|
||||
unsafe { self.get_raw_data().map(|d| d.layout_data.borrow()) }
|
||||
fn borrow_layout_data(self) -> Option<AtomicRef<'dom, LayoutData>> {
|
||||
self.get_raw_data().map(|d| d.layout_data.borrow())
|
||||
}
|
||||
|
||||
fn mutate_layout_data(&self) -> Option<AtomicRefMut<LayoutData>> {
|
||||
unsafe { self.get_raw_data().map(|d| d.layout_data.borrow_mut()) }
|
||||
fn mutate_layout_data(self) -> Option<AtomicRefMut<'dom, LayoutData>> {
|
||||
self.get_raw_data().map(|d| d.layout_data.borrow_mut())
|
||||
}
|
||||
|
||||
fn flow_debug_id(self) -> usize {
|
||||
|
@ -65,15 +63,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub trait GetRawData {
|
||||
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
|
||||
pub trait GetRawData<'dom> {
|
||||
fn get_raw_data(self) -> Option<&'dom StyleAndLayoutData>;
|
||||
}
|
||||
|
||||
impl<'dom, T> GetRawData for T
|
||||
impl<'dom, T> GetRawData<'dom> for T
|
||||
where
|
||||
T: GetLayoutData<'dom>,
|
||||
{
|
||||
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
|
||||
fn get_raw_data(self) -> Option<&'dom StyleAndLayoutData> {
|
||||
self.get_style_and_layout_data()
|
||||
.map(|opaque| opaque.downcast_ref().unwrap())
|
||||
}
|
||||
|
@ -144,7 +142,7 @@ where
|
|||
debug_assert!(node.is_element());
|
||||
}
|
||||
|
||||
let damage = unsafe {
|
||||
let damage = {
|
||||
let data = node.get_raw_data().unwrap();
|
||||
|
||||
if !data
|
||||
|
|
|
@ -369,7 +369,7 @@ pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode<'dom> + Send + Sync {
|
|||
fn style(self, context: &LayoutContext) -> ServoArc<ComputedValues>;
|
||||
|
||||
fn as_opaque(self) -> OpaqueNode;
|
||||
fn layout_data_mut(&self) -> AtomicRefMut<LayoutDataForElement>;
|
||||
fn layout_data_mut(self) -> AtomicRefMut<'dom, LayoutDataForElement>;
|
||||
fn element_box_slot(&self) -> BoxSlot<'dom>;
|
||||
fn pseudo_element_box_slot(&self, which: WhichPseudoElement) -> BoxSlot<'dom>;
|
||||
fn unset_pseudo_element_box(self, which: WhichPseudoElement);
|
||||
|
@ -447,12 +447,10 @@ where
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn layout_data_mut(&self) -> AtomicRefMut<LayoutDataForElement> {
|
||||
unsafe {
|
||||
self.get_raw_data()
|
||||
.map(|d| d.layout_data.borrow_mut())
|
||||
.unwrap()
|
||||
}
|
||||
fn layout_data_mut(self) -> AtomicRefMut<'dom, LayoutDataForElement> {
|
||||
self.get_raw_data()
|
||||
.map(|d| d.layout_data.borrow_mut())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn element_box_slot(&self) -> BoxSlot<'dom> {
|
||||
|
|
|
@ -63,7 +63,7 @@ where
|
|||
}
|
||||
|
||||
fn text_node_needs_traversal(node: E::ConcreteNode, parent_data: &ElementData) -> bool {
|
||||
(unsafe { node.get_raw_data().is_none() }) || !parent_data.damage.is_empty()
|
||||
node.get_raw_data().is_none() || !parent_data.damage.is_empty()
|
||||
}
|
||||
|
||||
fn shared_context(&self) -> &SharedStyleContext {
|
||||
|
|
|
@ -7,15 +7,15 @@
|
|||
use crate::data::StyleAndLayoutData;
|
||||
use script_layout_interface::wrapper_traits::GetLayoutData;
|
||||
|
||||
pub trait GetRawData {
|
||||
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
|
||||
pub trait GetRawData<'dom> {
|
||||
fn get_raw_data(self) -> Option<&'dom StyleAndLayoutData>;
|
||||
}
|
||||
|
||||
impl<'dom, T> GetRawData for T
|
||||
impl<'dom, T> GetRawData<'dom> for T
|
||||
where
|
||||
T: GetLayoutData<'dom>,
|
||||
{
|
||||
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
|
||||
fn get_raw_data(self) -> Option<&'dom StyleAndLayoutData> {
|
||||
self.get_style_and_layout_data()
|
||||
.map(|opaque| opaque.downcast_ref().unwrap())
|
||||
}
|
||||
|
|
|
@ -91,10 +91,6 @@ use style::str::is_whitespace;
|
|||
use style::stylist::CascadeData;
|
||||
use style::CaseSensitivityExt;
|
||||
|
||||
pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) {
|
||||
drop(Box::from_raw(data.as_ptr()));
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ServoLayoutNode<'dom> {
|
||||
/// The wrapped node.
|
||||
|
@ -234,7 +230,7 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
|||
}
|
||||
|
||||
fn opaque(&self) -> OpaqueNode {
|
||||
unsafe { self.get_jsmanaged().opaque() }
|
||||
self.get_jsmanaged().opaque()
|
||||
}
|
||||
|
||||
fn debug_id(self) -> usize {
|
||||
|
@ -291,34 +287,33 @@ impl<'ln> LayoutNode<'ln> for ServoLayoutNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'ln> GetLayoutData<'ln> for ServoLayoutNode<'ln> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
unsafe { self.get_jsmanaged().get_style_and_layout_data() }
|
||||
impl<'dom> GetLayoutData<'dom> for ServoLayoutNode<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.get_jsmanaged().get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'le> GetLayoutData<'le> for ServoLayoutElement<'le> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoLayoutElement<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.as_node().get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> GetLayoutData<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoThreadSafeLayoutNode<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.node.get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'le> GetLayoutData<'le> for ServoThreadSafeLayoutElement<'le> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoThreadSafeLayoutElement<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.element.as_node().get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> ServoLayoutNode<'ln> {
|
||||
/// Returns the interior of this node as a `LayoutDom`. This is highly unsafe for layout to
|
||||
/// call and as such is marked `unsafe`.
|
||||
pub unsafe fn get_jsmanaged(&self) -> LayoutDom<'ln, Node> {
|
||||
impl<'dom> ServoLayoutNode<'dom> {
|
||||
/// Returns the interior of this node as a `LayoutDom`.
|
||||
pub fn get_jsmanaged(self) -> LayoutDom<'dom, Node> {
|
||||
self.node
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +537,7 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
|
||||
unsafe fn clear_data(&self) {
|
||||
if self.get_raw_data().is_some() {
|
||||
drop_style_and_layout_data(self.as_node().take_style_and_layout_data());
|
||||
drop(self.as_node().take_style_and_layout_data());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -700,7 +695,7 @@ impl<'le> ServoLayoutElement<'le> {
|
|||
}
|
||||
|
||||
fn get_style_data(&self) -> Option<&StyleData> {
|
||||
self.get_style_and_layout_data().map(|opaque| unsafe {
|
||||
self.get_style_and_layout_data().map(|opaque| {
|
||||
&opaque
|
||||
.downcast_ref::<StyleAndLayoutData>()
|
||||
.unwrap()
|
||||
|
@ -1065,7 +1060,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'ln OpaqueStyleAndLayoutData> {
|
||||
self.node.get_style_and_layout_data()
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ extern crate profile_traits;
|
|||
|
||||
mod dom_wrapper;
|
||||
|
||||
use crate::dom_wrapper::drop_style_and_layout_data;
|
||||
use crate::dom_wrapper::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode};
|
||||
use app_units::Au;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
|
@ -692,7 +691,6 @@ impl LayoutThread {
|
|||
Msg::GetRPC(..) => LayoutHangAnnotation::GetRPC,
|
||||
Msg::TickAnimations(..) => LayoutHangAnnotation::TickAnimations,
|
||||
Msg::AdvanceClockMs(..) => LayoutHangAnnotation::AdvanceClockMs,
|
||||
Msg::ReapStyleAndLayoutData(..) => LayoutHangAnnotation::ReapStyleAndLayoutData,
|
||||
Msg::CollectReports(..) => LayoutHangAnnotation::CollectReports,
|
||||
Msg::PrepareToExit(..) => LayoutHangAnnotation::PrepareToExit,
|
||||
Msg::ExitNow => LayoutHangAnnotation::ExitNow,
|
||||
|
@ -833,9 +831,6 @@ impl LayoutThread {
|
|||
webrender_api::ScrollClamping::ToContentBounds,
|
||||
);
|
||||
},
|
||||
Msg::ReapStyleAndLayoutData(dead_data) => unsafe {
|
||||
drop_style_and_layout_data(dead_data)
|
||||
},
|
||||
Msg::CollectReports(reports_chan) => {
|
||||
self.collect_reports(reports_chan, possibly_locked_rw_data);
|
||||
},
|
||||
|
@ -967,9 +962,6 @@ impl LayoutThread {
|
|||
response_chan.send(()).unwrap();
|
||||
loop {
|
||||
match self.port.recv().unwrap() {
|
||||
Msg::ReapStyleAndLayoutData(dead_data) => unsafe {
|
||||
drop_style_and_layout_data(dead_data)
|
||||
},
|
||||
Msg::ExitNow => {
|
||||
debug!("layout thread is exiting...");
|
||||
self.exit_now();
|
||||
|
|
|
@ -91,10 +91,6 @@ use style::str::is_whitespace;
|
|||
use style::stylist::CascadeData;
|
||||
use style::CaseSensitivityExt;
|
||||
|
||||
pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) {
|
||||
drop(Box::from_raw(data.as_ptr()));
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ServoLayoutNode<'dom> {
|
||||
/// The wrapped node.
|
||||
|
@ -298,26 +294,26 @@ impl<'ln> LayoutNode<'ln> for ServoLayoutNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'ln> GetLayoutData<'ln> for ServoLayoutNode<'ln> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoLayoutNode<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
unsafe { self.get_jsmanaged().get_style_and_layout_data() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'le> GetLayoutData<'le> for ServoLayoutElement<'le> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoLayoutElement<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.as_node().get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> GetLayoutData<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoThreadSafeLayoutNode<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.node.get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'le> GetLayoutData<'le> for ServoThreadSafeLayoutElement<'le> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
impl<'dom> GetLayoutData<'dom> for ServoThreadSafeLayoutElement<'dom> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
self.element.as_node().get_style_and_layout_data()
|
||||
}
|
||||
}
|
||||
|
@ -549,7 +545,7 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
|
||||
unsafe fn clear_data(&self) {
|
||||
if self.get_raw_data().is_some() {
|
||||
drop_style_and_layout_data(self.as_node().take_style_and_layout_data());
|
||||
drop(self.as_node().take_style_and_layout_data());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -707,7 +703,7 @@ impl<'le> ServoLayoutElement<'le> {
|
|||
}
|
||||
|
||||
fn get_style_data(&self) -> Option<&StyleData> {
|
||||
self.get_style_and_layout_data().map(|opaque| unsafe {
|
||||
self.get_style_and_layout_data().map(|opaque| {
|
||||
&opaque
|
||||
.downcast_ref::<StyleAndLayoutData>()
|
||||
.unwrap()
|
||||
|
@ -1072,7 +1068,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
fn get_style_and_layout_data(self) -> Option<&'ln OpaqueStyleAndLayoutData> {
|
||||
self.node.get_style_and_layout_data()
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ extern crate profile_traits;
|
|||
|
||||
mod dom_wrapper;
|
||||
|
||||
use crate::dom_wrapper::drop_style_and_layout_data;
|
||||
use crate::dom_wrapper::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode};
|
||||
use app_units::Au;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
|
@ -640,7 +639,6 @@ impl LayoutThread {
|
|||
Msg::GetRPC(..) => LayoutHangAnnotation::GetRPC,
|
||||
Msg::TickAnimations(..) => LayoutHangAnnotation::TickAnimations,
|
||||
Msg::AdvanceClockMs(..) => LayoutHangAnnotation::AdvanceClockMs,
|
||||
Msg::ReapStyleAndLayoutData(..) => LayoutHangAnnotation::ReapStyleAndLayoutData,
|
||||
Msg::CollectReports(..) => LayoutHangAnnotation::CollectReports,
|
||||
Msg::PrepareToExit(..) => LayoutHangAnnotation::PrepareToExit,
|
||||
Msg::ExitNow => LayoutHangAnnotation::ExitNow,
|
||||
|
@ -779,9 +777,6 @@ impl LayoutThread {
|
|||
webrender_api::ScrollClamping::ToContentBounds,
|
||||
);
|
||||
},
|
||||
Msg::ReapStyleAndLayoutData(dead_data) => unsafe {
|
||||
drop_style_and_layout_data(dead_data)
|
||||
},
|
||||
Msg::CollectReports(reports_chan) => {
|
||||
self.collect_reports(reports_chan, possibly_locked_rw_data);
|
||||
},
|
||||
|
@ -890,9 +885,6 @@ impl LayoutThread {
|
|||
response_chan.send(()).unwrap();
|
||||
loop {
|
||||
match self.port.recv().unwrap() {
|
||||
Msg::ReapStyleAndLayoutData(dead_data) => unsafe {
|
||||
drop_style_and_layout_data(dead_data)
|
||||
},
|
||||
Msg::ExitNow => {
|
||||
debug!("layout thread is exiting...");
|
||||
self.exit_now();
|
||||
|
|
|
@ -532,7 +532,6 @@ pub enum LayoutHangAnnotation {
|
|||
GetRPC,
|
||||
TickAnimations,
|
||||
AdvanceClockMs,
|
||||
ReapStyleAndLayoutData,
|
||||
CollectReports,
|
||||
PrepareToExit,
|
||||
ExitNow,
|
||||
|
|
|
@ -65,7 +65,6 @@ use crate::dom::virtualmethods::{vtable_for, VirtualMethods};
|
|||
use crate::dom::window::Window;
|
||||
use crate::script_thread::ScriptThread;
|
||||
use app_units::Au;
|
||||
use crossbeam_channel::Sender;
|
||||
use devtools_traits::NodeInfo;
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
|
||||
|
@ -76,7 +75,6 @@ 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::Msg;
|
||||
use script_layout_interface::{HTMLCanvasData, HTMLMediaData, LayoutElementType, LayoutNodeType};
|
||||
use script_layout_interface::{OpaqueStyleAndLayoutData, SVGSVGData, TrustedNodeAddress};
|
||||
use script_traits::DocumentActivity;
|
||||
|
@ -99,7 +97,6 @@ use style::context::QuirksMode;
|
|||
use style::dom::OpaqueNode;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::stylesheets::Stylesheet;
|
||||
use style::thread_state;
|
||||
use uuid::Uuid;
|
||||
|
||||
//
|
||||
|
@ -155,7 +152,8 @@ pub struct Node {
|
|||
///
|
||||
/// Must be sent back to the layout thread to be destroyed when this
|
||||
/// node is finalized.
|
||||
style_and_layout_data: Cell<Option<OpaqueStyleAndLayoutData>>,
|
||||
#[ignore_malloc_size_of = "shrug"]
|
||||
style_and_layout_data: UnsafeCell<Option<OpaqueStyleAndLayoutData>>,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
@ -205,15 +203,6 @@ impl NodeFlags {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for Node {
|
||||
#[allow(unsafe_code)]
|
||||
fn drop(&mut self) {
|
||||
if let Some(data) = self.style_and_layout_data.get() {
|
||||
self.dispose(data, ScriptThread::get_any_layout_chan().as_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// suppress observers flag
|
||||
/// <https://dom.spec.whatwg.org/#concept-node-insert>
|
||||
/// <https://dom.spec.whatwg.org/#concept-node-remove>
|
||||
|
@ -224,21 +213,6 @@ enum SuppressObserver {
|
|||
}
|
||||
|
||||
impl Node {
|
||||
/// Sends the style and layout data, if any, back to the layout thread to be destroyed.
|
||||
pub(crate) fn dispose(
|
||||
&self,
|
||||
data: OpaqueStyleAndLayoutData,
|
||||
layout_chan: Option<&Sender<Msg>>,
|
||||
) {
|
||||
debug_assert!(thread_state::get().is_script());
|
||||
self.style_and_layout_data.set(None);
|
||||
if layout_chan.map_or(false, |chan| {
|
||||
chan.send(Msg::ReapStyleAndLayoutData(data)).is_err()
|
||||
}) {
|
||||
warn!("layout thread unreachable - leaking layout data");
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a new child to the end of this node's list of children.
|
||||
///
|
||||
/// Fails unless `new_child` is disconnected from the tree.
|
||||
|
@ -317,16 +291,11 @@ impl Node {
|
|||
false,
|
||||
);
|
||||
}
|
||||
let window = window_from_node(root);
|
||||
let layout_chan = window.layout_chan();
|
||||
for node in root.traverse_preorder(ShadowIncluding::Yes) {
|
||||
// This needs to be in its own loop, because unbind_from_tree may
|
||||
// rely on the state of IS_IN_DOC of the context node's descendants,
|
||||
// e.g. when removing a <form>.
|
||||
vtable_for(&&*node).unbind_from_tree(&context);
|
||||
if let Some(data) = node.style_and_layout_data.get() {
|
||||
node.dispose(data, Some(layout_chan));
|
||||
}
|
||||
// https://dom.spec.whatwg.org/#concept-node-remove step 14
|
||||
if let Some(element) = node.as_custom_element() {
|
||||
ScriptThread::enqueue_callback_reaction(
|
||||
|
@ -507,15 +476,6 @@ impl<'a> Iterator for QuerySelectorIterator {
|
|||
impl Node {
|
||||
impl_rare_data!(NodeRareData);
|
||||
|
||||
pub(crate) fn teardown(&self, layout_chan: &Sender<Msg>) {
|
||||
if let Some(data) = self.style_and_layout_data.get() {
|
||||
self.dispose(data, Some(layout_chan));
|
||||
}
|
||||
for kid in self.children() {
|
||||
kid.teardown(layout_chan);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this node is before `other` in the same connected DOM
|
||||
/// tree.
|
||||
pub fn is_before(&self, other: &Node) -> bool {
|
||||
|
@ -1322,8 +1282,8 @@ pub trait LayoutNodeHelpers<'dom> {
|
|||
|
||||
fn children_count(self) -> u32;
|
||||
|
||||
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData>;
|
||||
unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData);
|
||||
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 text_content(self) -> Cow<'dom, str>;
|
||||
|
@ -1450,23 +1410,24 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData> {
|
||||
(*self.unsafe_get()).style_and_layout_data.get()
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData> {
|
||||
unsafe { (*self.unsafe_get().style_and_layout_data.get()).as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn init_style_and_layout_data(self, val: OpaqueStyleAndLayoutData) {
|
||||
debug_assert!((*self.unsafe_get()).style_and_layout_data.get().is_none());
|
||||
(*self.unsafe_get()).style_and_layout_data.set(Some(val));
|
||||
let data = &mut *self.unsafe_get().style_and_layout_data.get();
|
||||
debug_assert!(data.is_none());
|
||||
*data = Some(val);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn take_style_and_layout_data(self) -> OpaqueStyleAndLayoutData {
|
||||
let val = (*self.unsafe_get()).style_and_layout_data.get().unwrap();
|
||||
(*self.unsafe_get()).style_and_layout_data.set(None);
|
||||
val
|
||||
(*self.unsafe_get().style_and_layout_data.get())
|
||||
.take()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn text_content(self) -> Cow<'dom, str> {
|
||||
|
@ -1781,7 +1742,7 @@ impl Node {
|
|||
inclusive_descendants_version: Cell::new(0),
|
||||
ranges: WeakRangeVec::new(),
|
||||
|
||||
style_and_layout_data: Cell::new(None),
|
||||
style_and_layout_data: UnsafeCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1399,13 +1399,6 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn clear_js_runtime(&self) {
|
||||
// We tear down the active document, which causes all the attached
|
||||
// nodes to dispose of their layout data. This messages the layout
|
||||
// thread, informing it that it can safely free the memory.
|
||||
self.Document()
|
||||
.upcast::<Node>()
|
||||
.teardown(self.layout_chan());
|
||||
|
||||
// Remove the infra for managing messageports and broadcast channels.
|
||||
self.upcast::<GlobalScope>().remove_web_messaging_infra();
|
||||
|
||||
|
|
|
@ -822,23 +822,6 @@ impl ScriptThreadFactory for ScriptThread {
|
|||
}
|
||||
|
||||
impl ScriptThread {
|
||||
pub(crate) fn get_any_layout_chan() -> Option<Sender<Msg>> {
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
let script_thread = match root.get() {
|
||||
Some(s) => unsafe { &*s },
|
||||
None => return None,
|
||||
};
|
||||
script_thread
|
||||
.documents
|
||||
.borrow()
|
||||
.map
|
||||
.values()
|
||||
.next()
|
||||
.map(|d| d.window().layout_chan())
|
||||
.cloned()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn runtime_handle() -> ParentRuntime {
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
let script_thread = unsafe { &*root.get().unwrap() };
|
||||
|
|
|
@ -26,7 +26,6 @@ use net_traits::image_cache::PendingImageId;
|
|||
use script_traits::UntrustedNodeAddress;
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use std::any::Any;
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::atomic::AtomicIsize;
|
||||
use style::data::ElementData;
|
||||
|
||||
|
@ -51,12 +50,11 @@ impl StyleData {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, MallocSizeOf)]
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct OpaqueStyleAndLayoutData {
|
||||
// NB: We really store a `StyleAndLayoutData` here, so be careful!
|
||||
#[ignore_malloc_size_of = "TODO(#6910) Box value that should be counted but \
|
||||
the type lives in layout"]
|
||||
ptr: NonNull<dyn Any + Send + Sync>,
|
||||
#[ignore_malloc_size_of = "Trait objects are hard"]
|
||||
ptr: Box<dyn Any + Send + Sync>,
|
||||
}
|
||||
|
||||
impl OpaqueStyleAndLayoutData {
|
||||
|
@ -66,23 +64,17 @@ impl OpaqueStyleAndLayoutData {
|
|||
T: Any + Send + Sync,
|
||||
{
|
||||
Self {
|
||||
ptr: Box::into_raw_non_null(Box::new(value) as Box<dyn Any + Send + Sync>),
|
||||
ptr: Box::new(value) as Box<dyn Any + Send + Sync>,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_ptr(&self) -> *mut (dyn Any + Send + Sync) {
|
||||
self.ptr.as_ptr()
|
||||
}
|
||||
|
||||
/// Extremely cursed.
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
pub unsafe fn downcast_ref<'extended, T>(&self) -> Option<&'extended T>
|
||||
pub fn downcast_ref<T>(&self) -> Option<&T>
|
||||
where
|
||||
T: Any + Send + Sync,
|
||||
{
|
||||
(*self.ptr.as_ptr()).downcast_ref()
|
||||
self.ptr.downcast_ref()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::rpc::LayoutRPC;
|
||||
use crate::{OpaqueStyleAndLayoutData, PendingImage, TrustedNodeAddress};
|
||||
use crate::{PendingImage, TrustedNodeAddress};
|
||||
use app_units::Au;
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
use euclid::default::{Point2D, Rect};
|
||||
|
@ -56,11 +56,6 @@ pub enum Msg {
|
|||
/// field is whether animations should be force-ticked.
|
||||
AdvanceClockMs(i32, bool, ImmutableOrigin),
|
||||
|
||||
/// Destroys layout data associated with a DOM node.
|
||||
///
|
||||
/// TODO(pcwalton): Maybe think about batching to avoid message traffic.
|
||||
ReapStyleAndLayoutData(OpaqueStyleAndLayoutData),
|
||||
|
||||
/// Requests that the layout thread measure its memory usage. The resulting reports are sent back
|
||||
/// via the supplied channel.
|
||||
CollectReports(ReportsChan),
|
||||
|
|
|
@ -80,7 +80,7 @@ impl PseudoElementType {
|
|||
|
||||
/// Trait to abstract access to layout data across various data structures.
|
||||
pub trait GetLayoutData<'dom> {
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData>;
|
||||
}
|
||||
|
||||
/// A wrapper so that layout can access only the methods that it should have access to. Layout must
|
||||
|
@ -224,7 +224,7 @@ pub trait ThreadSafeLayoutNode<'dom>:
|
|||
.map_or(PseudoElementType::Normal, |el| el.get_pseudo_element_type())
|
||||
}
|
||||
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;
|
||||
fn get_style_and_layout_data(self) -> Option<&'dom OpaqueStyleAndLayoutData>;
|
||||
|
||||
fn style(&self, context: &SharedStyleContext) -> Arc<ComputedValues> {
|
||||
if let Some(el) = self.as_element() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue