stylo: Flatten ServoComputedValues into ServoStyleContext

This patch also removes the duplication of style contexts during the
restyle, because otherwise pointer equality of ServoComputedValues stops
holding (and we assert on that in a few places)
This commit is contained in:
Manish Goregaokar 2017-07-17 11:42:08 -07:00 committed by Manish Goregaokar
parent cfad95bff0
commit ff4bc5a2c6
6 changed files with 82 additions and 45 deletions

View file

@ -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<CssRules> => 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]);

View file

@ -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<RawServoStyleSheetContents>;
pub type RawServoStyleSheetContentsBorrowed<'a> = &'a RawServoStyleSheetContents;
pub type RawServoStyleSheetContentsBorrowedOrNull<'a> = Option<&'a RawServoStyleSheetContents>;
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
pub type RawServoDeclarationBlockStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoDeclarationBlock>;
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);
}

View file

@ -10847,11 +10847,11 @@ pub mod root {
pub struct ServoStyleContext {
pub _base: root::nsStyleContext,
pub mPresContext: *mut root::nsPresContext,
pub mSource: root::RefPtr<root::ServoComputedValues>,
pub mSource: root::ServoComputedValues,
}
#[test]
fn bindgen_test_layout_ServoStyleContext() {
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 56usize ,
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 280usize ,
concat ! (
"Size of: " , stringify ! ( ServoStyleContext ) ));
assert_eq! (::std::mem::align_of::<ServoStyleContext>() , 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.
*
* <div rustbindgen nocopy></div>
*/
#[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::<ServoComputedValuesForgotten>() ,
8usize , concat ! (
"Size of: " , stringify ! ( ServoComputedValuesForgotten )
));
assert_eq! (::std::mem::align_of::<ServoComputedValuesForgotten>() ,
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::<u8>() , 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::<u8>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( u8 )
));

View file

@ -10584,11 +10584,11 @@ pub mod root {
pub struct ServoStyleContext {
pub _base: root::nsStyleContext,
pub mPresContext: *mut root::nsPresContext,
pub mSource: root::RefPtr<root::ServoComputedValues>,
pub mSource: root::ServoComputedValues,
}
#[test]
fn bindgen_test_layout_ServoStyleContext() {
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 56usize ,
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 280usize ,
concat ! (
"Size of: " , stringify ! ( ServoStyleContext ) ));
assert_eq! (::std::mem::align_of::<ServoStyleContext>() , 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.
*
* <div rustbindgen nocopy></div>
*/
#[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::<ServoComputedValuesForgotten>() ,
8usize , concat ! (
"Size of: " , stringify ! ( ServoComputedValuesForgotten )
));
assert_eq! (::std::mem::align_of::<ServoComputedValuesForgotten>() ,
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::<u8>() , 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::<u8>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( u8 )
));

View file

@ -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<Self>, 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<ComputedValues> {
use gecko_bindings::sugar::ownership::FFIArcHelpers;
let arc = unsafe {
let arc: Arc<ComputedValues> = 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
}
}

View file

@ -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,
};