mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Remove HasBoxFFI
HasBoxFFI and HasArcFFI aren't great, see bug 1831242 as for examples of why. HasArcFFI requires a bit more care, but HasBoxFFI doesn't give us much benefit. Instead use the same type in the FFI boundary. Differential Revision: https://phabricator.services.mozilla.com/D177252
This commit is contained in:
parent
1a49d8c79f
commit
19e037d921
9 changed files with 10 additions and 180 deletions
|
@ -6,8 +6,6 @@
|
||||||
//! ones used for ShadowRoot.
|
//! ones used for ShadowRoot.
|
||||||
|
|
||||||
use crate::dom::TElement;
|
use crate::dom::TElement;
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
|
||||||
use crate::invalidation::media_queries::ToMediaListKey;
|
use crate::invalidation::media_queries::ToMediaListKey;
|
||||||
use crate::shared_lock::SharedRwLockReadGuard;
|
use crate::shared_lock::SharedRwLockReadGuard;
|
||||||
use crate::stylesheet_set::AuthorStylesheetSet;
|
use crate::stylesheet_set::AuthorStylesheetSet;
|
||||||
|
@ -19,7 +17,7 @@ use servo_arc::Arc;
|
||||||
/// A set of author stylesheets and their computed representation, such as the
|
/// A set of author stylesheets and their computed representation, such as the
|
||||||
/// ones used for ShadowRoot.
|
/// ones used for ShadowRoot.
|
||||||
#[derive(MallocSizeOf)]
|
#[derive(MallocSizeOf)]
|
||||||
pub struct AuthorStyles<S>
|
pub struct GenericAuthorStyles<S>
|
||||||
where
|
where
|
||||||
S: StylesheetInDocument + PartialEq + 'static,
|
S: StylesheetInDocument + PartialEq + 'static,
|
||||||
{
|
{
|
||||||
|
@ -31,11 +29,13 @@ where
|
||||||
pub data: Arc<CascadeData>,
|
pub data: Arc<CascadeData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use self::GenericAuthorStyles as AuthorStyles;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref EMPTY_CASCADE_DATA: Arc<CascadeData> = Arc::new_leaked(CascadeData::new());
|
static ref EMPTY_CASCADE_DATA: Arc<CascadeData> = Arc::new_leaked(CascadeData::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> AuthorStyles<S>
|
impl<S> GenericAuthorStyles<S>
|
||||||
where
|
where
|
||||||
S: StylesheetInDocument + PartialEq + 'static,
|
S: StylesheetInDocument + PartialEq + 'static,
|
||||||
{
|
{
|
||||||
|
@ -68,12 +68,3 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {
|
|
||||||
type FFIType = crate::gecko_bindings::structs::RawServoAuthorStyles;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasSimpleFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasBoxFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {}
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
//! FFI implementations for types listed in ServoBoxedTypeList.h.
|
|
||||||
|
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
|
||||||
use crate::properties::animated_properties::AnimationValueMap;
|
|
||||||
use to_shmem::SharedMemoryBuilder;
|
|
||||||
|
|
||||||
// TODO(heycam): The FFI impls for most of the types in ServoBoxedTypeList.h are spread across
|
|
||||||
// various files at the moment, but should probably all move here, and use macros to define
|
|
||||||
// them more succinctly, like we do in arc_types.rs.
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasFFI for AnimationValueMap {
|
|
||||||
type FFIType = crate::gecko_bindings::bindings::RawServoAnimationValueMap;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasSimpleFFI for AnimationValueMap {}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasBoxFFI for AnimationValueMap {}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasFFI for SharedMemoryBuilder {
|
|
||||||
type FFIType = crate::gecko_bindings::bindings::RawServoSharedMemoryBuilder;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasSimpleFFI for SharedMemoryBuilder {}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasBoxFFI for SharedMemoryBuilder {}
|
|
|
@ -6,9 +6,8 @@
|
||||||
|
|
||||||
use crate::dom::TElement;
|
use crate::dom::TElement;
|
||||||
use crate::gecko_bindings::bindings;
|
use crate::gecko_bindings::bindings;
|
||||||
use crate::gecko_bindings::structs::{self, RawServoStyleSet, ServoStyleSetSizes};
|
use crate::gecko_bindings::structs::{self, ServoStyleSetSizes, StyleSheet as DomStyleSheet, StyleSheetInfo};
|
||||||
use crate::gecko_bindings::structs::{StyleSheet as DomStyleSheet, StyleSheetInfo};
|
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
|
|
||||||
use crate::invalidation::media_queries::{MediaListKey, ToMediaListKey};
|
use crate::invalidation::media_queries::{MediaListKey, ToMediaListKey};
|
||||||
use crate::media_queries::{Device, MediaList};
|
use crate::media_queries::{Device, MediaList};
|
||||||
use crate::properties::ComputedValues;
|
use crate::properties::ComputedValues;
|
||||||
|
@ -201,8 +200,5 @@ impl PerDocumentStyleDataImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasFFI for PerDocumentStyleData {
|
/// The gecko-specific AuthorStyles instantiation.
|
||||||
type FFIType = RawServoStyleSet;
|
pub type AuthorStyles = crate::author_styles::AuthorStyles<GeckoStyleSheet>;
|
||||||
}
|
|
||||||
unsafe impl HasSimpleFFI for PerDocumentStyleData {}
|
|
||||||
unsafe impl HasBoxFFI for PerDocumentStyleData {}
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
mod non_ts_pseudo_class_list;
|
mod non_ts_pseudo_class_list;
|
||||||
|
|
||||||
pub mod arc_types;
|
pub mod arc_types;
|
||||||
pub mod boxed_types;
|
|
||||||
pub mod conversions;
|
pub mod conversions;
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod media_features;
|
pub mod media_features;
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
//! Gecko-specific bits for selector-parsing.
|
//! Gecko-specific bits for selector-parsing.
|
||||||
|
|
||||||
use crate::computed_value_flags::ComputedValueFlags;
|
use crate::computed_value_flags::ComputedValueFlags;
|
||||||
use crate::gecko_bindings::structs::RawServoSelectorList;
|
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
|
||||||
use crate::invalidation::element::document_state::InvalidationMatchingData;
|
use crate::invalidation::element::document_state::InvalidationMatchingData;
|
||||||
use crate::properties::ComputedValues;
|
use crate::properties::ComputedValues;
|
||||||
use crate::selector_parser::{Direction, HorizontalDirection, SelectorParser};
|
use crate::selector_parser::{Direction, HorizontalDirection, SelectorParser};
|
||||||
|
@ -17,7 +15,6 @@ use cssparser::{BasicParseError, BasicParseErrorKind, Parser};
|
||||||
use cssparser::{CowRcStr, SourceLocation, ToCss, Token};
|
use cssparser::{CowRcStr, SourceLocation, ToCss, Token};
|
||||||
use dom::{DocumentState, ElementState};
|
use dom::{DocumentState, ElementState};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use selectors::SelectorList;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss as ToCss_};
|
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss as ToCss_};
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
@ -489,12 +486,6 @@ impl SelectorImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasFFI for SelectorList<SelectorImpl> {
|
|
||||||
type FFIType = RawServoSelectorList;
|
|
||||||
}
|
|
||||||
unsafe impl HasSimpleFFI for SelectorList<SelectorImpl> {}
|
|
||||||
unsafe impl HasBoxFFI for SelectorList<SelectorImpl> {}
|
|
||||||
|
|
||||||
// Selector and component sizes are important for matching performance.
|
// Selector and component sizes are important for matching performance.
|
||||||
size_of_test!(selectors::parser::Selector<SelectorImpl>, 8);
|
size_of_test!(selectors::parser::Selector<SelectorImpl>, 8);
|
||||||
size_of_test!(selectors::parser::Component<SelectorImpl>, 24);
|
size_of_test!(selectors::parser::Component<SelectorImpl>, 24);
|
||||||
|
|
|
@ -15,11 +15,9 @@
|
||||||
//! the separation between the style system implementation and everything else.
|
//! the separation between the style system implementation and everything else.
|
||||||
|
|
||||||
use crate::applicable_declarations::ApplicableDeclarationBlock;
|
use crate::applicable_declarations::ApplicableDeclarationBlock;
|
||||||
use crate::author_styles::AuthorStyles;
|
|
||||||
use crate::context::{PostAnimationTasks, QuirksMode, SharedStyleContext, UpdateAnimationsTasks};
|
use crate::context::{PostAnimationTasks, QuirksMode, SharedStyleContext, UpdateAnimationsTasks};
|
||||||
use crate::data::ElementData;
|
use crate::data::ElementData;
|
||||||
use crate::dom::{LayoutIterator, NodeInfo, OpaqueNode, TDocument, TElement, TNode, TShadowRoot};
|
use crate::dom::{LayoutIterator, NodeInfo, OpaqueNode, TDocument, TElement, TNode, TShadowRoot};
|
||||||
use crate::gecko::data::GeckoStyleSheet;
|
|
||||||
use crate::gecko::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl};
|
use crate::gecko::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl};
|
||||||
use crate::gecko::snapshot_helpers;
|
use crate::gecko::snapshot_helpers;
|
||||||
use crate::gecko_bindings::bindings;
|
use crate::gecko_bindings::bindings;
|
||||||
|
@ -50,7 +48,7 @@ use crate::gecko_bindings::structs::NODE_DESCENDANTS_NEED_FRAMES;
|
||||||
use crate::gecko_bindings::structs::NODE_NEEDS_FRAME;
|
use crate::gecko_bindings::structs::NODE_NEEDS_FRAME;
|
||||||
use crate::gecko_bindings::structs::{nsAtom, nsIContent, nsINode_BooleanFlag};
|
use crate::gecko_bindings::structs::{nsAtom, nsIContent, nsINode_BooleanFlag};
|
||||||
use crate::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeckoElement};
|
use crate::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeckoElement};
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
|
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
|
||||||
use crate::global_style_data::GLOBAL_STYLE_DATA;
|
use crate::global_style_data::GLOBAL_STYLE_DATA;
|
||||||
use crate::invalidation::element::restyle_hints::RestyleHint;
|
use crate::invalidation::element::restyle_hints::RestyleHint;
|
||||||
use crate::media_queries::Device;
|
use crate::media_queries::Device;
|
||||||
|
@ -180,7 +178,6 @@ impl<'lr> TShadowRoot for GeckoShadowRoot<'lr> {
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
let author_styles = unsafe { self.0.mServoStyles.mPtr.as_ref()? };
|
let author_styles = unsafe { self.0.mServoStyles.mPtr.as_ref()? };
|
||||||
let author_styles = AuthorStyles::<GeckoStyleSheet>::from_ffi(author_styles);
|
|
||||||
Some(&author_styles.data)
|
Some(&author_styles.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -925,7 +922,7 @@ fn get_animation_rule(
|
||||||
Gecko_GetAnimationRule(
|
Gecko_GetAnimationRule(
|
||||||
element.0,
|
element.0,
|
||||||
cascade_level,
|
cascade_level,
|
||||||
AnimationValueMap::as_ffi_mut(&mut animation_values),
|
&mut animation_values,
|
||||||
)
|
)
|
||||||
} {
|
} {
|
||||||
let shared_lock = &GLOBAL_STYLE_DATA.shared_lock;
|
let shared_lock = &GLOBAL_STYLE_DATA.shared_lock;
|
||||||
|
|
|
@ -56,26 +56,6 @@ pub unsafe trait HasSimpleFFI: HasFFI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates that the given Servo type is passed over FFI
|
|
||||||
/// as a Box
|
|
||||||
pub unsafe trait HasBoxFFI: HasSimpleFFI {
|
|
||||||
#[inline]
|
|
||||||
/// Converts a borrowed Arc to a borrowed FFI reference.
|
|
||||||
///
|
|
||||||
/// &Arc<ServoType> -> &GeckoType
|
|
||||||
fn into_ffi(self: Box<Self>) -> Owned<Self::FFIType> {
|
|
||||||
unsafe { transmute(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Drops an owned FFI pointer. This conceptually takes the
|
|
||||||
/// Owned<Self::FFIType>, except it's a bit of a paint to do that without
|
|
||||||
/// much benefit.
|
|
||||||
#[inline]
|
|
||||||
unsafe fn drop_ffi(ptr: *mut Self::FFIType) {
|
|
||||||
let _ = Box::from_raw(ptr as *mut Self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
||||||
///
|
///
|
||||||
/// Should be implemented by types which are passed over FFI as Arcs via Strong
|
/// Should be implemented by types which are passed over FFI as Arcs via Strong
|
||||||
|
@ -265,75 +245,6 @@ unsafe impl<T: HasArcFFI> FFIArcHelpers for Arc<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug)]
|
|
||||||
/// Gecko-FFI-safe owned pointer.
|
|
||||||
///
|
|
||||||
/// Cannot be null, and leaks on drop, so needs to be converted into a rust-side
|
|
||||||
/// `Box` before.
|
|
||||||
pub struct Owned<GeckoType> {
|
|
||||||
ptr: *mut GeckoType,
|
|
||||||
_marker: PhantomData<GeckoType>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<GeckoType> Owned<GeckoType> {
|
|
||||||
/// Converts this instance to a (non-null) instance of `OwnedOrNull`.
|
|
||||||
pub fn maybe(self) -> OwnedOrNull<GeckoType> {
|
|
||||||
unsafe { transmute(self) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<GeckoType> Deref for Owned<GeckoType> {
|
|
||||||
type Target = GeckoType;
|
|
||||||
fn deref(&self) -> &GeckoType {
|
|
||||||
unsafe { &*self.ptr }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<GeckoType> DerefMut for Owned<GeckoType> {
|
|
||||||
fn deref_mut(&mut self) -> &mut GeckoType {
|
|
||||||
unsafe { &mut *self.ptr }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
/// Gecko-FFI-safe owned pointer.
|
|
||||||
///
|
|
||||||
/// Can be null, and just as `Owned` leaks on `Drop`.
|
|
||||||
pub struct OwnedOrNull<GeckoType> {
|
|
||||||
ptr: *mut GeckoType,
|
|
||||||
_marker: PhantomData<GeckoType>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<GeckoType> OwnedOrNull<GeckoType> {
|
|
||||||
/// Returns a null pointer.
|
|
||||||
#[inline]
|
|
||||||
pub fn null() -> Self {
|
|
||||||
Self {
|
|
||||||
ptr: ptr::null_mut(),
|
|
||||||
_marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether this pointer is null.
|
|
||||||
#[inline]
|
|
||||||
pub fn is_null(&self) -> bool {
|
|
||||||
self.ptr.is_null()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets a immutable reference to the underlying Gecko type, or `None` if
|
|
||||||
/// null.
|
|
||||||
pub fn borrow(&self) -> Option<&GeckoType> {
|
|
||||||
unsafe { transmute(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets a mutable reference to the underlying Gecko type, or `None` if
|
|
||||||
/// null.
|
|
||||||
pub fn borrow_mut(&self) -> Option<&mut GeckoType> {
|
|
||||||
unsafe { transmute(self) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for CopyablePtr<T> {
|
impl<T> Deref for CopyablePtr<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
//! Various stuff for CSS property use counters.
|
//! Various stuff for CSS property use counters.
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
|
||||||
use crate::properties::{CountedUnknownProperty, COUNTED_UNKNOWN_PROPERTY_COUNT};
|
use crate::properties::{CountedUnknownProperty, COUNTED_UNKNOWN_PROPERTY_COUNT};
|
||||||
use crate::properties::{NonCustomPropertyId, NON_CUSTOM_PROPERTY_ID_COUNT};
|
use crate::properties::{NonCustomPropertyId, NON_CUSTOM_PROPERTY_ID_COUNT};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -96,14 +94,3 @@ impl UseCounters {
|
||||||
.merge(&other.counted_unknown_properties);
|
.merge(&other.counted_unknown_properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasFFI for UseCounters {
|
|
||||||
type FFIType = crate::gecko_bindings::structs::StyleUseCounters;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasSimpleFFI for UseCounters {}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasBoxFFI for UseCounters {}
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
//! https://html.spec.whatwg.org/multipage/#source-size-list
|
//! https://html.spec.whatwg.org/multipage/#source-size-list
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
|
||||||
use crate::media_queries::Device;
|
use crate::media_queries::Device;
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use crate::queries::{FeatureType, QueryCondition};
|
use crate::queries::{FeatureType, QueryCondition};
|
||||||
|
@ -134,12 +132,3 @@ impl SourceSizeList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasFFI for SourceSizeList {
|
|
||||||
type FFIType = crate::gecko_bindings::structs::RawServoSourceSizeList;
|
|
||||||
}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasSimpleFFI for SourceSizeList {}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
unsafe impl HasBoxFFI for SourceSizeList {}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue