From 2ea8d61fbf0c2d9142a6db875e9eeb4343b0bab1 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 4 Apr 2017 11:11:27 -0700 Subject: [PATCH] stylo: Bypass cache when fetching font size prefs from Stylo --- components/style/build_gecko.rs | 2 + components/style/gecko_bindings/bindings.rs | 8 +-- .../style/gecko_bindings/structs_debug.rs | 61 +++++++++++++++++++ .../style/gecko_bindings/structs_release.rs | 61 +++++++++++++++++++ .../style/properties/longhand/font.mako.rs | 17 ++++-- .../style/properties/properties.mako.rs | 1 + 6 files changed, 142 insertions(+), 8 deletions(-) diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index deffa87ce96..78280299aa0 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -338,6 +338,7 @@ mod bindings { "FontFamilyListRefCnt", "FontFamilyName", "FontFamilyType", + "FontSizePrefs", "FragmentOrURL", "FrameRequestCallback", "GeckoParserExtraData", @@ -623,6 +624,7 @@ mod bindings { "ComputedTimingFunction_BeforeFlag", "FontFamilyList", "FontFamilyType", + "FontSizePrefs", "Keyframe", "ServoBundledURI", "ServoElementSnapshot", diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 2420617ab34..ffec9f8c804 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -27,6 +27,7 @@ use gecko_bindings::structs::TraversalRootBehavior; use gecko_bindings::structs::ComputedTimingFunction_BeforeFlag; use gecko_bindings::structs::FontFamilyList; use gecko_bindings::structs::FontFamilyType; +use gecko_bindings::structs::FontSizePrefs; use gecko_bindings::structs::Keyframe; use gecko_bindings::structs::ServoBundledURI; use gecko_bindings::structs::ServoElementSnapshot; @@ -1062,10 +1063,9 @@ extern "C" { aSource: *const nsStyleFont); } extern "C" { - pub fn Gecko_nsStyleFont_GetBaseSize(font: *const nsStyleFont, - pres_context: - RawGeckoPresContextBorrowed) - -> nscoord; + pub fn Gecko_GetBaseSize(lang: *mut nsIAtom, + pres_context: RawGeckoPresContextBorrowed) + -> FontSizePrefs; } extern "C" { pub fn Gecko_GetMediaFeatures() -> *const nsMediaFeature; diff --git a/components/style/gecko_bindings/structs_debug.rs b/components/style/gecko_bindings/structs_debug.rs index 65a0dc3adf8..92a983b4ecd 100644 --- a/components/style/gecko_bindings/structs_debug.rs +++ b/components/style/gecko_bindings/structs_debug.rs @@ -27150,6 +27150,67 @@ pub mod root { fn clone(&self) -> Self { *self } } #[repr(C)] + #[derive(Debug, Copy)] + pub struct FontSizePrefs { + pub mDefaultVariableSize: root::nscoord, + pub mDefaultFixedSize: root::nscoord, + pub mDefaultSerifSize: root::nscoord, + pub mDefaultSansSerifSize: root::nscoord, + pub mDefaultMonospaceSize: root::nscoord, + pub mDefaultCursiveSize: root::nscoord, + pub mDefaultFantasySize: root::nscoord, + } + #[test] + fn bindgen_test_layout_FontSizePrefs() { + assert_eq!(::std::mem::size_of::() , 28usize , concat ! + ( "Size of: " , stringify ! ( FontSizePrefs ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat + ! ( "Alignment of " , stringify ! ( FontSizePrefs ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultVariableSize as * const _ as usize } , 0usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultVariableSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . mDefaultFixedSize + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultFixedSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . mDefaultSerifSize + as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultSerifSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultSansSerifSize as * const _ as usize } , 12usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultSansSerifSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultMonospaceSize as * const _ as usize } , 16usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultMonospaceSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultCursiveSize as * const _ as usize } , 20usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultCursiveSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultFantasySize as * const _ as usize } , 24usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultFantasySize ) )); + } + impl Clone for FontSizePrefs { + fn clone(&self) -> Self { *self } + } + #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsROCSSPrimitiveValue([u8; 0]); #[repr(C)] diff --git a/components/style/gecko_bindings/structs_release.rs b/components/style/gecko_bindings/structs_release.rs index 9d00e454f34..f7fc2d3072b 100644 --- a/components/style/gecko_bindings/structs_release.rs +++ b/components/style/gecko_bindings/structs_release.rs @@ -26491,6 +26491,67 @@ pub mod root { fn clone(&self) -> Self { *self } } #[repr(C)] + #[derive(Debug, Copy)] + pub struct FontSizePrefs { + pub mDefaultVariableSize: root::nscoord, + pub mDefaultFixedSize: root::nscoord, + pub mDefaultSerifSize: root::nscoord, + pub mDefaultSansSerifSize: root::nscoord, + pub mDefaultMonospaceSize: root::nscoord, + pub mDefaultCursiveSize: root::nscoord, + pub mDefaultFantasySize: root::nscoord, + } + #[test] + fn bindgen_test_layout_FontSizePrefs() { + assert_eq!(::std::mem::size_of::() , 28usize , concat ! + ( "Size of: " , stringify ! ( FontSizePrefs ) )); + assert_eq! (::std::mem::align_of::() , 4usize , concat + ! ( "Alignment of " , stringify ! ( FontSizePrefs ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultVariableSize as * const _ as usize } , 0usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultVariableSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . mDefaultFixedSize + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultFixedSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . mDefaultSerifSize + as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultSerifSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultSansSerifSize as * const _ as usize } , 12usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultSansSerifSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultMonospaceSize as * const _ as usize } , 16usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultMonospaceSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultCursiveSize as * const _ as usize } , 20usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultCursiveSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FontSizePrefs ) ) . + mDefaultFantasySize as * const _ as usize } , 24usize , + concat ! ( + "Alignment of field: " , stringify ! ( FontSizePrefs ) , + "::" , stringify ! ( mDefaultFantasySize ) )); + } + impl Clone for FontSizePrefs { + fn clone(&self) -> Self { *self } + } + #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsROCSSPrimitiveValue([u8; 0]); #[repr(C)] diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index b7ef293239c..81b10bdc48b 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -536,7 +536,8 @@ ${helpers.single_keyword("font-variant-caps", type ComputedValue = Au; #[inline] fn to_computed_value(&self, cx: &Context) -> computed_value::T { - use gecko_bindings::bindings::Gecko_nsStyleFont_GetBaseSize; + use gecko_bindings::bindings::Gecko_GetBaseSize; + use gecko_bindings::structs; use values::specified::length::au_to_int_px; // Data from nsRuleNode.cpp in Gecko // Mapping from base size and HTML size to pixels @@ -561,10 +562,18 @@ ${helpers.single_keyword("font-variant-caps", // XXXManishearth handle quirks mode - let base_size = unsafe { - Gecko_nsStyleFont_GetBaseSize(cx.style().get_font().gecko(), - &*cx.device.pres_context) + let base_sizes = unsafe { + Gecko_GetBaseSize(cx.style().get_font().gecko().mLanguage.raw()) }; + let base_size = match cx.style().get_font().gecko().mGenericID { + structs::kGenericFont_serif => base_sizes.mDefaultSerifSize, + structs::kGenericFont_sans_serif => base_sizes.mDefaultSansSerifSize, + structs::kGenericFont_monospace => base_sizes.mDefaultMonospaceSize, + structs::kGenericFont_cursive => base_sizes.mDefaultCursiveSize, + structs::kGenericFont_fantasy => base_sizes.mDefaultFantasySize, + x => unreachable!("Unknown generic ID {}", x), + }; + let base_size_px = au_to_int_px(base_size as f32); let html_size = *self as usize; if base_size_px >= 9 && base_size_px <= 16 { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 88121aa32f3..9a44935ef28 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2109,6 +2109,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device, | LonghandId::TextOrientation | LonghandId::AnimationName | LonghandId::TransitionProperty + | LonghandId::XLang % endif ); if