aboutsummaryrefslogtreecommitdiffstats
path: root/components/script_layout_interface
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-04-04 09:35:34 -0400
committerGitHub <noreply@github.com>2020-04-04 09:35:34 -0400
commitd64f7d427a8dc56bbfc92183f57588e7eb1d56c2 (patch)
tree5f07578a53872c2d23da16f2d052cda7ff4ef1e4 /components/script_layout_interface
parent9972aee81f0e80d34157325a5e13b3b1a7ef417a (diff)
parent185a402d9cc41d3e680b99564f5fc8b519ecf129 (diff)
downloadservo-d64f7d427a8dc56bbfc92183f57588e7eb1d56c2.tar.gz
servo-d64f7d427a8dc56bbfc92183f57588e7eb1d56c2.zip
Auto merge of #26105 - servo:layout-2020-less-opaque, r=emilio
Make DOM own the style and layout data, in an UnsafeCell
Diffstat (limited to 'components/script_layout_interface')
-rw-r--r--components/script_layout_interface/lib.rs31
-rw-r--r--components/script_layout_interface/message.rs7
-rw-r--r--components/script_layout_interface/wrapper_traits.rs4
3 files changed, 29 insertions, 13 deletions
diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs
index ef9382378cb..6fb859aa112 100644
--- a/components/script_layout_interface/lib.rs
+++ b/components/script_layout_interface/lib.rs
@@ -7,6 +7,7 @@
//! to depend on script.
#![deny(unsafe_code)]
+#![feature(box_into_raw_non_null)]
#[macro_use]
extern crate html5ever;
@@ -24,7 +25,7 @@ use libc::c_void;
use net_traits::image_cache::PendingImageId;
use script_traits::UntrustedNodeAddress;
use servo_url::{ImmutableOrigin, ServoUrl};
-use std::ptr::NonNull;
+use std::any::Any;
use std::sync::atomic::AtomicIsize;
use style::data::ElementData;
@@ -49,12 +50,32 @@ 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"]
- pub ptr: NonNull<StyleData>,
+ #[ignore_malloc_size_of = "Trait objects are hard"]
+ ptr: Box<dyn Any + Send + Sync>,
+}
+
+impl OpaqueStyleAndLayoutData {
+ #[inline]
+ pub fn new<T>(value: T) -> Self
+ where
+ T: Any + Send + Sync,
+ {
+ Self {
+ ptr: Box::new(value) as Box<dyn Any + Send + Sync>,
+ }
+ }
+
+ /// Extremely cursed.
+ #[inline]
+ pub fn downcast_ref<T>(&self) -> Option<&T>
+ where
+ T: Any + Send + Sync,
+ {
+ self.ptr.downcast_ref()
+ }
}
#[allow(unsafe_code)]
diff --git a/components/script_layout_interface/message.rs b/components/script_layout_interface/message.rs
index 96c4a132368..48ec7223250 100644
--- a/components/script_layout_interface/message.rs
+++ b/components/script_layout_interface/message.rs
@@ -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),
diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs
index 462d11f2c7e..671dd1c8230 100644
--- a/components/script_layout_interface/wrapper_traits.rs
+++ b/components/script_layout_interface/wrapper_traits.rs
@@ -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() {