style: Finish removing HasArcFFI

Use the actual Locked<T> types around (via a typedef, just for
convenience).

Differential Revision: https://phabricator.services.mozilla.com/D177824
This commit is contained in:
Emilio Cobos Álvarez 2023-05-12 22:31:38 +00:00 committed by Martin Robinson
parent 3f03650c88
commit e9bf977369
6 changed files with 147 additions and 311 deletions

View file

@ -2,22 +2,12 @@
* 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/. */
//! This file lists all arc FFI types and defines corresponding addref
//! and release functions. This list corresponds to ServoArcTypeList.h
//! file in Gecko.
//! This file lists all arc FFI types and defines corresponding addref and release functions. This
//! list loosely corresponds to ServoLockedArcTypeList.h file in Gecko.
#![allow(non_snake_case, missing_docs)]
use crate::gecko::url::CssUrlData;
use crate::gecko_bindings::structs::{
RawServoContainerRule, RawServoCounterStyleRule, RawServoDeclarationBlock,
RawServoFontFaceRule, RawServoFontFeatureValuesRule, RawServoFontPaletteValuesRule,
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoLayerBlockRule,
RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule, RawServoMozDocumentRule,
RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule, RawServoSupportsRule,
ServoCssRules,
};
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
use crate::media_queries::MediaList;
use crate::properties::animated_properties::AnimationValue;
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
@ -30,81 +20,6 @@ use crate::stylesheets::{
};
use servo_arc::Arc;
macro_rules! impl_arc_ffi {
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
unsafe impl HasArcFFI for $servo_type {
type FFIType = $gecko_type;
}
#[no_mangle]
pub unsafe extern "C" fn $addref(obj: &$gecko_type) {
<$servo_type>::addref(obj);
}
#[no_mangle]
pub unsafe extern "C" fn $release(obj: &$gecko_type) {
<$servo_type>::release(obj);
}
};
}
impl_arc_ffi!(Locked<CssRules> => ServoCssRules
[Servo_CssRules_AddRef, Servo_CssRules_Release]);
impl_arc_ffi!(Locked<PropertyDeclarationBlock> => RawServoDeclarationBlock
[Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);
impl_arc_ffi!(Locked<StyleRule> => RawServoStyleRule
[Servo_StyleRule_AddRef, Servo_StyleRule_Release]);
impl_arc_ffi!(Locked<ImportRule> => RawServoImportRule
[Servo_ImportRule_AddRef, Servo_ImportRule_Release]);
impl_arc_ffi!(Locked<Keyframe> => RawServoKeyframe
[Servo_Keyframe_AddRef, Servo_Keyframe_Release]);
impl_arc_ffi!(Locked<KeyframesRule> => RawServoKeyframesRule
[Servo_KeyframesRule_AddRef, Servo_KeyframesRule_Release]);
impl_arc_ffi!(Locked<LayerBlockRule> => RawServoLayerBlockRule
[Servo_LayerBlockRule_AddRef, Servo_LayerBlockRule_Release]);
impl_arc_ffi!(Locked<LayerStatementRule> => RawServoLayerStatementRule
[Servo_LayerStatementRule_AddRef, Servo_LayerStatementRule_Release]);
impl_arc_ffi!(Locked<MediaList> => RawServoMediaList
[Servo_MediaList_AddRef, Servo_MediaList_Release]);
impl_arc_ffi!(Locked<MediaRule> => RawServoMediaRule
[Servo_MediaRule_AddRef, Servo_MediaRule_Release]);
impl_arc_ffi!(Locked<NamespaceRule> => RawServoNamespaceRule
[Servo_NamespaceRule_AddRef, Servo_NamespaceRule_Release]);
impl_arc_ffi!(Locked<PageRule> => RawServoPageRule
[Servo_PageRule_AddRef, Servo_PageRule_Release]);
impl_arc_ffi!(Locked<SupportsRule> => RawServoSupportsRule
[Servo_SupportsRule_AddRef, Servo_SupportsRule_Release]);
impl_arc_ffi!(Locked<ContainerRule> => RawServoContainerRule
[Servo_ContainerRule_AddRef, Servo_ContainerRule_Release]);
impl_arc_ffi!(Locked<DocumentRule> => RawServoMozDocumentRule
[Servo_DocumentRule_AddRef, Servo_DocumentRule_Release]);
impl_arc_ffi!(Locked<FontFeatureValuesRule> => RawServoFontFeatureValuesRule
[Servo_FontFeatureValuesRule_AddRef, Servo_FontFeatureValuesRule_Release]);
impl_arc_ffi!(Locked<FontPaletteValuesRule> => RawServoFontPaletteValuesRule
[Servo_FontPaletteValuesRule_AddRef, Servo_FontPaletteValuesRule_Release]);
impl_arc_ffi!(Locked<FontFaceRule> => RawServoFontFaceRule
[Servo_FontFaceRule_AddRef, Servo_FontFaceRule_Release]);
impl_arc_ffi!(Locked<CounterStyleRule> => RawServoCounterStyleRule
[Servo_CounterStyleRule_AddRef, Servo_CounterStyleRule_Release]);
macro_rules! impl_simple_arc_ffi {
($ty:ty, $addref:ident, $release:ident) => {
#[no_mangle]
@ -119,6 +34,129 @@ macro_rules! impl_simple_arc_ffi {
};
}
macro_rules! impl_locked_arc_ffi {
($servo_type:ty, $alias:ident, $addref:ident, $release:ident) => {
/// A simple alias for a locked type.
pub type $alias = Locked<$servo_type>;
impl_simple_arc_ffi!($alias, $addref, $release);
};
}
impl_locked_arc_ffi!(
CssRules,
LockedCssRules,
Servo_CssRules_AddRef,
Servo_CssRules_Release
);
impl_locked_arc_ffi!(
PropertyDeclarationBlock,
LockedDeclarationBlock,
Servo_DeclarationBlock_AddRef,
Servo_DeclarationBlock_Release
);
impl_locked_arc_ffi!(
StyleRule,
LockedStyleRule,
Servo_StyleRule_AddRef,
Servo_StyleRule_Release
);
impl_locked_arc_ffi!(
ImportRule,
LockedImportRule,
Servo_ImportRule_AddRef,
Servo_ImportRule_Release
);
impl_locked_arc_ffi!(
Keyframe,
LockedKeyframe,
Servo_Keyframe_AddRef,
Servo_Keyframe_Release
);
impl_locked_arc_ffi!(
KeyframesRule,
LockedKeyframesRule,
Servo_KeyframesRule_AddRef,
Servo_KeyframesRule_Release
);
impl_locked_arc_ffi!(
LayerBlockRule,
LockedLayerBlockRule,
Servo_LayerBlockRule_AddRef,
Servo_LayerBlockRule_Release
);
impl_locked_arc_ffi!(
LayerStatementRule,
LockedLayerStatementRule,
Servo_LayerStatementRule_AddRef,
Servo_LayerStatementRule_Release
);
impl_locked_arc_ffi!(
MediaList,
LockedMediaList,
Servo_MediaList_AddRef,
Servo_MediaList_Release
);
impl_locked_arc_ffi!(
MediaRule,
LockedMediaRule,
Servo_MediaRule_AddRef,
Servo_MediaRule_Release
);
impl_locked_arc_ffi!(
NamespaceRule,
LockedNamespaceRule,
Servo_NamespaceRule_AddRef,
Servo_NamespaceRule_Release
);
impl_locked_arc_ffi!(
PageRule,
LockedPageRule,
Servo_PageRule_AddRef,
Servo_PageRule_Release
);
impl_locked_arc_ffi!(
SupportsRule,
LockedSupportsRule,
Servo_SupportsRule_AddRef,
Servo_SupportsRule_Release
);
impl_locked_arc_ffi!(
ContainerRule,
LockedContainerRule,
Servo_ContainerRule_AddRef,
Servo_ContainerRule_Release
);
impl_locked_arc_ffi!(
DocumentRule,
LockedDocumentRule,
Servo_DocumentRule_AddRef,
Servo_DocumentRule_Release
);
impl_locked_arc_ffi!(
FontFeatureValuesRule,
LockedFontFeatureValuesRule,
Servo_FontFeatureValuesRule_AddRef,
Servo_FontFeatureValuesRule_Release
);
impl_locked_arc_ffi!(
FontPaletteValuesRule,
LockedFontPaletteValuesRule,
Servo_FontPaletteValuesRule_AddRef,
Servo_FontPaletteValuesRule_Release
);
impl_locked_arc_ffi!(
FontFaceRule,
LockedFontFaceRule,
Servo_FontFaceRule_AddRef,
Servo_FontFaceRule_Release
);
impl_locked_arc_ffi!(
CounterStyleRule,
LockedCounterStyleRule,
Servo_CounterStyleRule_AddRef,
Servo_CounterStyleRule_Release
);
impl_simple_arc_ffi!(
StylesheetContents,
Servo_StyleSheetContents_AddRef,

View file

@ -7,12 +7,11 @@
use crate::dom::TElement;
use crate::gecko_bindings::bindings;
use crate::gecko_bindings::structs::{self, ServoStyleSetSizes, StyleSheet as DomStyleSheet, StyleSheetInfo};
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
use crate::invalidation::media_queries::{MediaListKey, ToMediaListKey};
use crate::media_queries::{Device, MediaList};
use crate::properties::ComputedValues;
use crate::selector_parser::SnapshotMap;
use crate::shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards};
use crate::stylesheets::{StylesheetContents, StylesheetInDocument};
use crate::stylist::Stylist;
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
@ -102,15 +101,12 @@ impl Clone for GeckoStyleSheet {
impl StylesheetInDocument for GeckoStyleSheet {
fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> {
use crate::gecko_bindings::structs::mozilla::dom::MediaList as DomMediaList;
use std::mem;
unsafe {
let dom_media_list = self.raw().mMedia.mRawPtr as *const DomMediaList;
if dom_media_list.is_null() {
return None;
}
let raw_list = &*(*dom_media_list).mRawList.mRawPtr;
let list = Locked::<MediaList>::as_arc(mem::transmute(&raw_list));
let list = &*(*dom_media_list).mRawList.mRawPtr;
Some(list.read_with(guard))
}
}

View file

@ -48,7 +48,6 @@ use crate::gecko_bindings::structs::NODE_DESCENDANTS_NEED_FRAMES;
use crate::gecko_bindings::structs::NODE_NEEDS_FRAME;
use crate::gecko_bindings::structs::{nsAtom, nsIContent, nsINode_BooleanFlag};
use crate::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeckoElement};
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
use crate::global_style_data::GLOBAL_STYLE_DATA;
use crate::invalidation::element::restyle_hints::RestyleHint;
use crate::media_queries::Device;
@ -75,7 +74,7 @@ use selectors::matching::VisitedHandlingMode;
use selectors::matching::{ElementSelectorFlags, MatchingContext};
use selectors::sink::Push;
use selectors::{Element, OpaqueElement};
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use servo_arc::{Arc, ArcBorrow};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::mem;
@ -1139,10 +1138,10 @@ impl<'le> TElement for GeckoElement<'le> {
return None;
}
let declarations = unsafe { Gecko_GetStyleAttrDeclarationBlock(self.0).as_ref() };
let declarations: Option<&RawOffsetArc<Locked<PropertyDeclarationBlock>>> =
declarations.and_then(|s| s.as_arc_opt());
declarations.map(|s| s.borrow_arc())
unsafe {
let declarations = Gecko_GetStyleAttrDeclarationBlock(self.0).as_ref()?;
Some(ArcBorrow::from_ref(declarations))
}
}
fn unset_dirty_style_attribute(&self) {
@ -1160,14 +1159,8 @@ impl<'le> TElement for GeckoElement<'le> {
let declaration: &structs::DeclarationBlock =
slots.mSMILOverrideStyleDeclaration.mRawPtr.as_ref()?;
let raw: &structs::RawServoDeclarationBlock = declaration.mRaw.mRawPtr.as_ref()?;
Some(
Locked::<PropertyDeclarationBlock>::as_arc(
&*(&raw as *const &structs::RawServoDeclarationBlock),
)
.borrow_arc(),
)
let raw: &structs::StyleLockedDeclarationBlock = declaration.mRaw.mRawPtr.as_ref()?;
Some(ArcBorrow::from_ref(raw))
}
}
@ -1652,21 +1645,17 @@ impl<'le> TElement for GeckoElement<'le> {
}
let declarations =
unsafe { Gecko_GetHTMLPresentationAttrDeclarationBlock(self.0).as_ref() };
let declarations: Option<&RawOffsetArc<Locked<PropertyDeclarationBlock>>> =
declarations.and_then(|s| s.as_arc_opt());
if let Some(decl) = declarations {
hints.push(ApplicableDeclarationBlock::from_declarations(
decl.clone_arc(),
unsafe { Arc::from_raw_addrefed(decl) },
ServoCascadeLevel::PresHints,
LayerOrder::root(),
));
}
let declarations = unsafe { Gecko_GetExtraContentStyleDeclarations(self.0).as_ref() };
let declarations: Option<&RawOffsetArc<Locked<PropertyDeclarationBlock>>> =
declarations.and_then(|s| s.as_arc_opt());
if let Some(decl) = declarations {
hints.push(ApplicableDeclarationBlock::from_declarations(
decl.clone_arc(),
unsafe { Arc::from_raw_addrefed(decl) },
ServoCascadeLevel::PresHints,
LayerOrder::root(),
));
@ -1690,11 +1679,9 @@ impl<'le> TElement for GeckoElement<'le> {
Gecko_GetVisitedLinkAttrDeclarationBlock(self.0).as_ref()
},
};
let declarations: Option<&RawOffsetArc<Locked<PropertyDeclarationBlock>>> =
declarations.and_then(|s| s.as_arc_opt());
if let Some(decl) = declarations {
hints.push(ApplicableDeclarationBlock::from_declarations(
decl.clone_arc(),
unsafe { Arc::from_raw_addrefed(decl) },
ServoCascadeLevel::PresHints,
LayerOrder::root(),
));
@ -1706,11 +1693,9 @@ impl<'le> TElement for GeckoElement<'le> {
if active {
let declarations =
unsafe { Gecko_GetActiveLinkAttrDeclarationBlock(self.0).as_ref() };
let declarations: Option<&RawOffsetArc<Locked<PropertyDeclarationBlock>>> =
declarations.and_then(|s| s.as_arc_opt());
if let Some(decl) = declarations {
hints.push(ApplicableDeclarationBlock::from_declarations(
decl.clone_arc(),
unsafe { Arc::from_raw_addrefed(decl) },
ServoCascadeLevel::PresHints,
LayerOrder::root(),
));