mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01: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
|
@ -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