diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index 0a082ed82289..a0686e6ca9c4 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -132,7 +132,6 @@ using namespace mozilla::system; #include "mozilla/ServoBindings.h" #include "mozilla/StaticPresData.h" #include "mozilla/dom/WebIDLGlobalNameHash.h" -#include "mozilla/URLExtraData.h" using namespace mozilla; using namespace mozilla::net; @@ -313,8 +312,7 @@ nsLayoutStatics::Initialize() mozilla::dom::WebCryptoThreadPool::Initialize(); #ifdef MOZ_STYLO - URLExtraData::InitDummy(); - Servo_Initialize(URLExtraData::Dummy()); + InitializeServo(); #endif #ifndef MOZ_WIDGET_ANDROID @@ -332,7 +330,7 @@ nsLayoutStatics::Shutdown() // memory reporter manager. #ifdef MOZ_STYLO - Servo_Shutdown(); + ShutdownServo(); URLExtraData::ReleaseDummy(); #endif diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index f265b4691ff8..a20d220e843a 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -27,6 +27,7 @@ #include "nsIPresShell.h" #include "nsIPresShellInlines.h" #include "nsIPrincipal.h" +#include "nsFontMetrics.h" #include "nsMappedAttributes.h" #include "nsMediaFeatures.h" #include "nsNameSpaceManager.h" @@ -41,6 +42,7 @@ #include "mozilla/EffectSet.h" #include "mozilla/EventStates.h" #include "mozilla/Keyframe.h" +#include "mozilla/Mutex.h" #include "mozilla/ServoElementSnapshot.h" #include "mozilla/ServoRestyleManager.h" #include "mozilla/StyleAnimationValue.h" @@ -51,6 +53,7 @@ #include "mozilla/dom/HTMLTableCellElement.h" #include "mozilla/dom/HTMLBodyElement.h" #include "mozilla/LookAndFeel.h" +#include "mozilla/URLExtraData.h" using namespace mozilla; using namespace mozilla::dom; @@ -1609,6 +1612,48 @@ Gecko_GetBaseSize(nsIAtom* aLanguage) return sizes; } +static Mutex* sServoFontMetricsLock = nullptr; + +void +InitializeServo() +{ + URLExtraData::InitDummy(); + Servo_Initialize(URLExtraData::Dummy()); + + sServoFontMetricsLock = new Mutex("Gecko_GetFontMetrics"); +} + +void +ShutdownServo() +{ + delete sServoFontMetricsLock; + Servo_Shutdown(); +} + +GeckoFontMetrics +Gecko_GetFontMetrics(RawGeckoPresContextBorrowed aPresContext, + bool aIsVertical, + const nsStyleFont* aFont, + nscoord aFontSize, + bool aUseUserFontSet) +{ + MutexAutoLock lock(*sServoFontMetricsLock); + aPresContext->SetUsesExChUnits(true); + GeckoFontMetrics ret; + // Safe because we are locked, and this function is only + // ever called from Servo parallel traversal + MOZ_ASSERT(ServoStyleSet::IsInServoTraversal()); + nsPresContext* presContext = const_cast(aPresContext); + RefPtr fm = nsRuleNode::GetMetricsFor(presContext, aIsVertical, + aFont, aFontSize, + aUseUserFontSet); + ret.mXSize = fm->XHeight(); + gfxFloat zeroWidth = fm->GetThebesFontGroup()->GetFirstValidFont()-> + GetMetrics(fm->Orientation()).zeroOrAveCharWidth; + ret.mChSize = ceil(aPresContext->AppUnitsPerDevPixel() * zeroWidth); + return ret; +} + void Gecko_LoadStyleSheet(css::Loader* aLoader, ServoStyleSheet* aParent, diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index 66809c19af9c..d5b8becf66f2 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -399,6 +399,20 @@ void Gecko_nsStyleFont_SetLang(nsStyleFont* font, nsIAtom* atom); void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont, const nsStyleFont* aSource); FontSizePrefs Gecko_GetBaseSize(nsIAtom* lang); +struct GeckoFontMetrics +{ + nscoord mChSize; + nscoord mXSize; +}; + +GeckoFontMetrics Gecko_GetFontMetrics(RawGeckoPresContextBorrowed pres_context, + bool is_vertical, + const nsStyleFont* font, + nscoord font_size, + bool use_user_font_set); +void InitializeServo(); +void ShutdownServo(); + const nsMediaFeature* Gecko_GetMediaFeatures(); // Font face rule diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 929a2d84e84f..bef63b9e4adc 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -614,16 +614,16 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue, case eCSSUnit_XHeight: { aPresContext->SetUsesExChUnits(true); RefPtr fm = - GetMetricsFor(aPresContext, aStyleContext, styleFont, - aFontSize, aUseUserFontSet); + nsRuleNode::GetMetricsFor(aPresContext, aStyleContext, styleFont, + aFontSize, aUseUserFontSet); aConditions.SetUncacheable(); return ScaleCoordRound(aValue, float(fm->XHeight())); } case eCSSUnit_Char: { aPresContext->SetUsesExChUnits(true); RefPtr fm = - GetMetricsFor(aPresContext, aStyleContext, styleFont, - aFontSize, aUseUserFontSet); + nsRuleNode::GetMetricsFor(aPresContext, aStyleContext, styleFont, + aFontSize, aUseUserFontSet); gfxFloat zeroWidth = fm->GetThebesFontGroup()->GetFirstValidFont()-> GetMetrics(fm->Orientation()).zeroOrAveCharWidth;