diff --git a/components/style/gecko/arc_types.rs b/components/style/gecko/arc_types.rs index 990a4511223..41301b8af15 100644 --- a/components/style/gecko/arc_types.rs +++ b/components/style/gecko/arc_types.rs @@ -15,10 +15,10 @@ use gecko_bindings::bindings::{RawServoNamespaceRule, RawServoPageRule}; use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule}; use gecko_bindings::bindings::ServoCssRules; use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock, RawServoStyleRule, RawServoMediaList}; -use gecko_bindings::structs::{RawServoStyleSheetContents, ServoComputedValues, ServoStyleContext}; +use gecko_bindings::structs::{RawServoStyleSheetContents, ServoStyleContext}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI}; use media_queries::MediaList; -use properties::{ComputedValues, ComputedValuesInner, PropertyDeclarationBlock}; +use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::animated_properties::AnimationValue; use rule_tree::StrongRuleNode; use shared_lock::Locked; @@ -52,9 +52,6 @@ impl_arc_ffi!(Locked => ServoCssRules impl_arc_ffi!(StylesheetContents => RawServoStyleSheetContents [Servo_StyleSheetContents_AddRef, Servo_StyleSheetContents_Release]); -impl_arc_ffi!(ComputedValuesInner => ServoComputedValues - [Servo_ComputedValues_AddRef, Servo_ComputedValues_Release]); - impl_arc_ffi!(ComputedValues => ServoStyleContext [Servo_StyleContext_AddRef, Servo_StyleContext_Release]); diff --git a/components/style/gecko/generated/bindings.rs b/components/style/gecko/generated/bindings.rs index 1202c3cd866..4adafbee98f 100644 --- a/components/style/gecko/generated/bindings.rs +++ b/components/style/gecko/generated/bindings.rs @@ -7,6 +7,8 @@ type nsACString_internal = nsACString; type nsAString_internal = nsAString; pub type ServoStyleContextBorrowed<'a> = &'a ServoStyleContext; pub type ServoStyleContextBorrowedOrNull<'a> = Option<&'a ::properties::ComputedValues>; +pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues; +pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>; use gecko_bindings::structs::mozilla::css::GridTemplateAreasValue; use gecko_bindings::structs::mozilla::css::ErrorReporter; use gecko_bindings::structs::mozilla::css::ImageValue; @@ -319,9 +321,6 @@ pub struct ServoCssRules(ServoCssRulesVoid); pub type RawServoStyleSheetContentsStrong = ::gecko_bindings::sugar::ownership::Strong; pub type RawServoStyleSheetContentsBorrowed<'a> = &'a RawServoStyleSheetContents; pub type RawServoStyleSheetContentsBorrowedOrNull<'a> = Option<&'a RawServoStyleSheetContents>; -pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong; -pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues; -pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>; pub type RawServoDeclarationBlockStrong = ::gecko_bindings::sugar::ownership::Strong; pub type RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock; pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclarationBlock>; @@ -402,12 +401,6 @@ extern "C" { pub fn Servo_StyleSheetContents_Release(ptr: RawServoStyleSheetContentsBorrowed); } -extern "C" { - pub fn Servo_ComputedValues_AddRef(ptr: ServoComputedValuesBorrowed); -} -extern "C" { - pub fn Servo_ComputedValues_Release(ptr: ServoComputedValuesBorrowed); -} extern "C" { pub fn Servo_DeclarationBlock_AddRef(ptr: RawServoDeclarationBlockBorrowed); @@ -537,7 +530,7 @@ extern "C" { ServoStyleContextBorrowedOrNull, pres_context: RawGeckoPresContextBorrowed, - values: ServoComputedValuesStrong, + values: ServoComputedValuesBorrowed, pseudo_type: CSSPseudoElementType, pseudo_tag: *mut nsIAtom); } diff --git a/components/style/gecko/generated/structs_debug.rs b/components/style/gecko/generated/structs_debug.rs index e22c8ff0b5f..81f4a89cdaf 100644 --- a/components/style/gecko/generated/structs_debug.rs +++ b/components/style/gecko/generated/structs_debug.rs @@ -10847,11 +10847,11 @@ pub mod root { pub struct ServoStyleContext { pub _base: root::nsStyleContext, pub mPresContext: *mut root::nsPresContext, - pub mSource: root::RefPtr, + pub mSource: root::ServoComputedValues, } #[test] fn bindgen_test_layout_ServoStyleContext() { - assert_eq!(::std::mem::size_of::() , 56usize , + assert_eq!(::std::mem::size_of::() , 280usize , concat ! ( "Size of: " , stringify ! ( ServoStyleContext ) )); assert_eq! (::std::mem::align_of::() , 8usize , @@ -20971,10 +20971,6 @@ pub mod root { * so we define this type on the C++ side and use the bindgenned version * on the Rust side. * - * C++ just sees pointers and opaque types here, so bindgen will attempt to generate a Copy - * impl. This will fail because the bindgenned version contains owned types. Opt out. - * - *
*/ #[repr(C)] #[derive(Debug)] @@ -21174,6 +21170,31 @@ pub mod root { "Alignment of field: " , stringify ! ( ServoComputedValues ) , "::" , stringify ! ( flags ) )); } + #[repr(C)] + #[derive(Debug, Copy)] + pub struct ServoComputedValuesForgotten { + pub mPtr: *const root::ServoComputedValues, + } + #[test] + fn bindgen_test_layout_ServoComputedValuesForgotten() { + assert_eq!(::std::mem::size_of::() , + 8usize , concat ! ( + "Size of: " , stringify ! ( ServoComputedValuesForgotten ) + )); + assert_eq! (::std::mem::align_of::() , + 8usize , concat ! ( + "Alignment of " , stringify ! ( + ServoComputedValuesForgotten ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ServoComputedValuesForgotten ) ) . + mPtr as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + ServoComputedValuesForgotten ) , "::" , stringify ! ( mPtr + ) )); + } + impl Clone for ServoComputedValuesForgotten { + fn clone(&self) -> Self { *self } + } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum WeakMapTraceKind { @@ -38416,13 +38437,15 @@ pub mod root { pub type RawGeckoGfxMatrix4x4 = [root::mozilla::gfx::Float; 16usize]; pub type RawGeckoStyleChildrenIterator = root::mozilla::dom::StyleChildrenIterator; - pub type ServoComputedValuesBorrowed = *const root::ServoComputedValues; pub type RawServoDeclarationBlockBorrowed = *const root::RawServoDeclarationBlock; pub type ServoStyleContextBorrowed = *const root::mozilla::ServoStyleContext; pub type ServoStyleContextBorrowedOrNull = *const root::mozilla::ServoStyleContext; + pub type ServoComputedValuesBorrowed = *const root::ServoComputedValues; + pub type ServoComputedValuesBorrowedOrNull = + *const root::ServoComputedValues; pub type RawServoAnimationValueMapBorrowedMut = *mut root::RawServoAnimationValueMap; pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode; @@ -40091,7 +40114,7 @@ pub mod root { root::nsCharTraits ) )); } #[test] - fn __bindgen_test_layout__bindgen_ty_id_195909_instantiation_33() { + fn __bindgen_test_layout__bindgen_ty_id_195896_instantiation_33() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( u8 ) )); @@ -40100,7 +40123,7 @@ pub mod root { ) )); } #[test] - fn __bindgen_test_layout__bindgen_ty_id_195945_instantiation_34() { + fn __bindgen_test_layout__bindgen_ty_id_195932_instantiation_34() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( u8 ) )); diff --git a/components/style/gecko/generated/structs_release.rs b/components/style/gecko/generated/structs_release.rs index 4b4a33aaf76..3656b9e3b5b 100644 --- a/components/style/gecko/generated/structs_release.rs +++ b/components/style/gecko/generated/structs_release.rs @@ -10584,11 +10584,11 @@ pub mod root { pub struct ServoStyleContext { pub _base: root::nsStyleContext, pub mPresContext: *mut root::nsPresContext, - pub mSource: root::RefPtr, + pub mSource: root::ServoComputedValues, } #[test] fn bindgen_test_layout_ServoStyleContext() { - assert_eq!(::std::mem::size_of::() , 56usize , + assert_eq!(::std::mem::size_of::() , 280usize , concat ! ( "Size of: " , stringify ! ( ServoStyleContext ) )); assert_eq! (::std::mem::align_of::() , 8usize , @@ -20626,10 +20626,6 @@ pub mod root { * so we define this type on the C++ side and use the bindgenned version * on the Rust side. * - * C++ just sees pointers and opaque types here, so bindgen will attempt to generate a Copy - * impl. This will fail because the bindgenned version contains owned types. Opt out. - * - *
*/ #[repr(C)] #[derive(Debug)] @@ -20829,6 +20825,31 @@ pub mod root { "Alignment of field: " , stringify ! ( ServoComputedValues ) , "::" , stringify ! ( flags ) )); } + #[repr(C)] + #[derive(Debug, Copy)] + pub struct ServoComputedValuesForgotten { + pub mPtr: *const root::ServoComputedValues, + } + #[test] + fn bindgen_test_layout_ServoComputedValuesForgotten() { + assert_eq!(::std::mem::size_of::() , + 8usize , concat ! ( + "Size of: " , stringify ! ( ServoComputedValuesForgotten ) + )); + assert_eq! (::std::mem::align_of::() , + 8usize , concat ! ( + "Alignment of " , stringify ! ( + ServoComputedValuesForgotten ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ServoComputedValuesForgotten ) ) . + mPtr as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + ServoComputedValuesForgotten ) , "::" , stringify ! ( mPtr + ) )); + } + impl Clone for ServoComputedValuesForgotten { + fn clone(&self) -> Self { *self } + } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum WeakMapTraceKind { @@ -37764,13 +37785,15 @@ pub mod root { pub type RawGeckoGfxMatrix4x4 = [root::mozilla::gfx::Float; 16usize]; pub type RawGeckoStyleChildrenIterator = root::mozilla::dom::StyleChildrenIterator; - pub type ServoComputedValuesBorrowed = *const root::ServoComputedValues; pub type RawServoDeclarationBlockBorrowed = *const root::RawServoDeclarationBlock; pub type ServoStyleContextBorrowed = *const root::mozilla::ServoStyleContext; pub type ServoStyleContextBorrowedOrNull = *const root::mozilla::ServoStyleContext; + pub type ServoComputedValuesBorrowed = *const root::ServoComputedValues; + pub type ServoComputedValuesBorrowedOrNull = + *const root::ServoComputedValues; pub type RawServoAnimationValueMapBorrowedMut = *mut root::RawServoAnimationValueMap; pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode; @@ -39439,7 +39462,7 @@ pub mod root { root::nsCharTraits ) )); } #[test] - fn __bindgen_test_layout__bindgen_ty_id_193431_instantiation_33() { + fn __bindgen_test_layout__bindgen_ty_id_193418_instantiation_33() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( u8 ) )); @@ -39448,7 +39471,7 @@ pub mod root { ) )); } #[test] - fn __bindgen_test_layout__bindgen_ty_id_193467_instantiation_34() { + fn __bindgen_test_layout__bindgen_ty_id_193454_instantiation_34() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( u8 ) )); diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index bfe1d981d1e..e8c06cc2233 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -160,18 +160,20 @@ impl ComputedValuesInner { (ptr::null_mut(), structs::CSSPseudoElementType::NotPseudo) }; - unsafe { Self::to_outer_from_arc(Arc::new(self), device.pres_context(), parent, ty, tag) } + unsafe { self.to_outer_helper(device.pres_context(), parent, ty, tag) } } - pub unsafe fn to_outer_from_arc(s: Arc, pres_context: bindings::RawGeckoPresContextBorrowed, + pub unsafe fn to_outer_helper(self, pres_context: bindings::RawGeckoPresContextBorrowed, parent: ParentStyleContextInfo, pseudo_ty: structs::CSSPseudoElementType, pseudo_tag: *mut structs::nsIAtom) -> Arc { - use gecko_bindings::sugar::ownership::FFIArcHelpers; let arc = unsafe { let arc: Arc = Arc::new(uninitialized()); bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _, parent, pres_context, - s.into_strong(), pseudo_ty, pseudo_tag); + &self, pseudo_ty, pseudo_tag); + // We're simulating a move by having C++ do a memcpy and then forgetting + // it on this end. + forget(self); arc }; arc @@ -181,13 +183,13 @@ impl ComputedValuesInner { impl ops::Deref for ComputedValues { type Target = ComputedValuesInner; fn deref(&self) -> &ComputedValuesInner { - unsafe { &*self.0.mSource.mRawPtr } + &self.0.mSource } } impl ops::DerefMut for ComputedValues { fn deref_mut(&mut self) -> &mut ComputedValuesInner { - unsafe { &mut *self.0.mSource.mRawPtr } + &mut self.0.mSource } } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 02fff04b346..40d8969f0a2 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1735,7 +1735,7 @@ pub extern "C" fn Servo_ComputedValues_Inherit( #[no_mangle] pub extern "C" fn Servo_ComputedValues_GetVisitedStyle(values: ServoComputedValuesBorrowed) -> ServoStyleContextStrong { - match ComputedValuesInner::as_arc(&values).clone_visited_style() { + match values.clone_visited_style() { Some(v) => v.into_strong(), None => Strong::null(), } @@ -1748,10 +1748,9 @@ pub extern "C" fn Servo_StyleContext_NewContext(values: ServoComputedValuesBorro pseudo_type: CSSPseudoElementType, pseudo_tag: *mut nsIAtom) -> ServoStyleContextStrong { - let arc = ComputedValuesInner::as_arc(&values); unsafe { - ComputedValuesInner::to_outer_from_arc(arc.clone_arc(), pres_context, parent, - pseudo_type, pseudo_tag).into_strong() + (*values).clone().to_outer_helper(pres_context, parent, + pseudo_type, pseudo_tag).into_strong() } } @@ -3386,7 +3385,7 @@ pub extern "C" fn Servo_GetCustomPropertyValue(computed_values: ServoComputedVal #[no_mangle] pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: ServoComputedValuesBorrowed) -> u32 { - match ComputedValuesInner::as_arc(&computed_values).custom_properties() { + match computed_values.custom_properties() { Some(p) => p.len() as u32, None => 0, } @@ -3396,7 +3395,7 @@ pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: ServoComputedV pub extern "C" fn Servo_GetCustomPropertyNameAt(computed_values: ServoComputedValuesBorrowed, index: u32, name: *mut nsAString) -> bool { - let custom_properties = match ComputedValuesInner::as_arc(&computed_values).custom_properties() { + let custom_properties = match computed_values.custom_properties() { Some(p) => p, None => return false, };