From d7b136975a633db73258c2d510b57f2d946c7e8a Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Fri, 31 Jul 2020 16:21:44 +0000 Subject: [PATCH] Bug 1652561 - Remote Win32k calls in nsLookAndFeel::GetFontImpl() r=emilio,geckoview-reviewers,agi,froydnj Content processes will now receive cached values for GetFontImpl() from the parent process during initialization and whenever the theme changes. This eliminates the use of several Win32k calls in content. Differential Revision: https://phabricator.services.mozilla.com/D83406 --- dom/ipc/ContentChild.cpp | 8 ++-- dom/ipc/ContentChild.h | 13 +++--- dom/ipc/ContentParent.cpp | 3 +- dom/ipc/PContent.ipdl | 6 +-- layout/base/nsPresContext.cpp | 20 ++++---- mfbt/RangedArray.h | 3 ++ widget/LookAndFeel.h | 18 +++++-- widget/WidgetMessageUtils.h | 38 +++++++++++++++ widget/android/nsLookAndFeel.cpp | 15 +++--- widget/android/nsLookAndFeel.h | 5 +- widget/cocoa/nsLookAndFeel.h | 5 +- widget/cocoa/nsLookAndFeel.mm | 18 +++---- widget/gtk/nsLookAndFeel.cpp | 15 +++--- widget/gtk/nsLookAndFeel.h | 5 +- widget/nsXPLookAndFeel.cpp | 19 ++++---- widget/nsXPLookAndFeel.h | 5 +- widget/windows/nsLookAndFeel.cpp | 80 +++++++++++++++++++------------- widget/windows/nsLookAndFeel.h | 19 ++++---- 18 files changed, 176 insertions(+), 119 deletions(-) diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index e680b856ac9e..a1655bbb7b7f 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -605,7 +605,7 @@ NS_INTERFACE_MAP_END mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes( XPCOMInitData&& aXPCOMInit, const StructuredCloneData& aInitialData, - nsTArray&& aLookAndFeelIntCache, + LookAndFeelCache&& aLookAndFeelCache, nsTArray&& aFontList, const Maybe& aSharedUASheetHandle, const uintptr_t& aSharedUASheetAddress, @@ -614,7 +614,7 @@ mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes( return IPC_OK(); } - mLookAndFeelCache = std::move(aLookAndFeelIntCache); + mLookAndFeelCache = std::move(aLookAndFeelCache); mFontList = std::move(aFontList); mSharedFontListBlocks = std::move(aSharedFontListBlocks); #ifdef XP_WIN @@ -2303,8 +2303,8 @@ mozilla::ipc::IPCResult ContentChild::RecvNotifyVisited( } mozilla::ipc::IPCResult ContentChild::RecvThemeChanged( - nsTArray&& aLookAndFeelIntCache) { - LookAndFeel::SetIntCache(aLookAndFeelIntCache); + LookAndFeelCache&& aLookAndFeelCache) { + LookAndFeel::SetCache(aLookAndFeelCache); LookAndFeel::NotifyChangedAllWindows(); return IPC_OK(); } diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index d06439b991d0..f894290e683a 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -14,6 +14,7 @@ #include "mozilla/dom/RemoteType.h" #include "mozilla/ipc/InputStreamUtils.h" #include "mozilla/ipc/ProtocolUtils.h" +#include "mozilla/LookAndFeel.h" #include "mozilla/StaticPtr.h" #include "mozilla/UniquePtr.h" #include "nsClassHashtable.h" @@ -35,7 +36,6 @@ struct SubstitutionMapping; struct OverrideMapping; class nsIDomainPolicy; class nsIURIClassifierCallback; -struct LookAndFeelInt; class nsDocShellLoadState; class nsFrameLoader; class nsIOpenWindowInfo; @@ -308,7 +308,8 @@ class ContentChild final : public PContentChild, const bool& haveBidiKeyboards); mozilla::ipc::IPCResult RecvNotifyVisited(nsTArray&&); - mozilla::ipc::IPCResult RecvThemeChanged(nsTArray&&); + mozilla::ipc::IPCResult RecvThemeChanged( + LookAndFeelCache&& aLookAndFeelCache); mozilla::ipc::IPCResult RecvUpdateSystemParameters( nsTArray&& aUpdates); @@ -542,7 +543,7 @@ class ContentChild final : public PContentChild, mozilla::ipc::IPCResult RecvSetXPCOMProcessAttributes( XPCOMInitData&& aXPCOMInit, const StructuredCloneData& aInitialData, - nsTArray&& aLookAndFeelIntCache, + LookAndFeelCache&& aLookAndFeelCache, nsTArray&& aFontList, const Maybe& aSharedUASheetHandle, const uintptr_t& aSharedUASheetAddress, @@ -607,7 +608,7 @@ class ContentChild final : public PContentChild, bool DeallocPSessionStorageObserverChild( PSessionStorageObserverChild* aActor); - nsTArray& LookAndFeelCache() { return mLookAndFeelCache; } + LookAndFeelCache& BorrowLookAndFeelCache() { return mLookAndFeelCache; } /** * Helper function for protocols that use the GPU process when available. @@ -835,8 +836,8 @@ class ContentChild final : public PContentChild, // parent process and used to initialize gfx in the child. Currently used // only on MacOSX and Linux. nsTArray mFontList; - // Temporary storage for nsXPLookAndFeel flags. - nsTArray mLookAndFeelCache; + // Temporary storage for nsXPLookAndFeel cache info. + LookAndFeelCache mLookAndFeelCache; // Temporary storage for list of shared-fontlist memory blocks. nsTArray mSharedFontListBlocks; diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index af8c80272755..c71db2405641 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2643,7 +2643,8 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) { // at present. nsTArray fontList; gfxPlatform::GetPlatform()->ReadSystemFontList(&fontList); - nsTArray lnfCache = LookAndFeel::GetIntCache(); + + LookAndFeelCache lnfCache = LookAndFeel::GetCache(); // If the shared fontlist is in use, collect its shmem block handles to pass // to the child. diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index f157ebb4156d..b75d7d146581 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -85,7 +85,7 @@ using mozilla::gfx::IntSize from "mozilla/gfx/2D.h"; using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h"; using mozilla::dom::ContentParentId from "mozilla/dom/ipc/IdType.h"; using mozilla::LayoutDeviceIntPoint from "Units.h"; -using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h"; +using struct LookAndFeelCache from "mozilla/widget/WidgetMessageUtils.h"; using class mozilla::dom::MessagePort from "mozilla/dom/MessagePort.h"; using class mozilla::dom::ipc::StructuredCloneData from "mozilla/dom/ipc/StructuredCloneData.h"; using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h"; @@ -560,7 +560,7 @@ child: * Tell the child that the system theme has changed, and that a repaint * is necessary. */ - async ThemeChanged(LookAndFeelInt[] lookAndFeelIntCache); + async ThemeChanged(LookAndFeelCache lookAndFeelCache); async UpdateSystemParameters(SystemParameterKVPair[] aUpdates); @@ -666,7 +666,7 @@ child: async SetXPCOMProcessAttributes(XPCOMInitData xpcomInit, StructuredCloneData initialData, - LookAndFeelInt[] lookAndFeelIntCache, + LookAndFeelCache lookAndFeelCache, /* used on MacOSX/Linux/Android only: */ SystemFontListEntry[] systemFontList, SharedMemoryHandle? sharedUASheetHandle, diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 4da4672c7b14..b872058af7f7 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -523,14 +523,14 @@ void nsPresContext::PreferenceChanged(const char* aPrefName) { if (prefName.EqualsLiteral("font.internaluseonly.changed")) { mChangeHintForPrefChange |= nsChangeHint_ReconstructFrame; } else if (StringBeginsWith(prefName, "font."_ns) || - // Changes to font family preferences don't change anything in the - // computed style data, so the style system won't generate a reflow - // hint for us. We need to do that manually. - prefName.EqualsLiteral("intl.accept_languages") || - // Changes to bidi prefs need to trigger a reflow (see bug 443629) - StringBeginsWith(prefName, "bidi."_ns) || - // Changes to font_rendering prefs need to trigger a reflow - StringBeginsWith(prefName, "gfx.font_rendering."_ns)) { + // Changes to font family preferences don't change anything in the + // computed style data, so the style system won't generate a reflow + // hint for us. We need to do that manually. + prefName.EqualsLiteral("intl.accept_languages") || + // Changes to bidi prefs need to trigger a reflow (see bug 443629) + StringBeginsWith(prefName, "bidi."_ns) || + // Changes to font_rendering prefs need to trigger a reflow + StringBeginsWith(prefName, "gfx.font_rendering."_ns)) { mChangeHintForPrefChange |= NS_STYLE_HINT_REFLOW; } @@ -1345,9 +1345,9 @@ void nsPresContext::ThemeChangedInternal() { if (XRE_IsParentProcess()) { nsTArray cp; ContentParent::GetAll(cp); - auto cache = LookAndFeel::GetIntCache(); + LookAndFeelCache lnfCache = LookAndFeel::GetCache(); for (ContentParent* c : cp) { - Unused << c->SendThemeChanged(cache); + Unused << c->SendThemeChanged(lnfCache); } } } diff --git a/mfbt/RangedArray.h b/mfbt/RangedArray.h index 48b6680c9c16..4417e09e9d3c 100644 --- a/mfbt/RangedArray.h +++ b/mfbt/RangedArray.h @@ -26,6 +26,9 @@ class RangedArray { ArrayType mArr; public: + static size_t length() { return Length; } + static size_t minIndex() { return MinIndex; } + T& operator[](size_t aIndex) { MOZ_ASSERT(aIndex == MinIndex || aIndex > MinIndex); return mArr[aIndex - MinIndex]; diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h index ccd8b1dfaef6..5a83058e3b1f 100644 --- a/widget/LookAndFeel.h +++ b/widget/LookAndFeel.h @@ -17,8 +17,7 @@ struct gfxFontStyle; -struct LookAndFeelInt; -struct LookAndFeelFontInfo; +struct LookAndFeelCache; namespace mozilla { @@ -546,8 +545,8 @@ class LookAndFeel { * If the implementation is caching values, these accessors allow the * cache to be exported and imported. */ - static nsTArray GetIntCache(); - static void SetIntCache(const nsTArray& aLookAndFeelIntCache); + static LookAndFeelCache GetCache(); + static void SetCache(const LookAndFeelCache& aCache); static void NotifyChangedAllWindows(); }; @@ -558,7 +557,7 @@ struct LookAndFeelInt { int32_t value; }; -struct LookAndFeelFontInfo { +struct LookAndFeelFont { bool haveFont; nsString fontName; float pixelHeight; @@ -566,6 +565,15 @@ struct LookAndFeelFontInfo { bool bold; }; +struct LookAndFeelCache { + void Clear() { + mInts.Clear(); + mFonts.Clear(); + } + nsTArray mInts; + nsTArray mFonts; +}; + // On the Mac, GetColor(ColorID::TextSelectForeground, color) returns this // constant to specify that the foreground color should not be changed // (ie. a colored text keeps its colors when selected). diff --git a/widget/WidgetMessageUtils.h b/widget/WidgetMessageUtils.h index 3ca032953624..648f39878483 100644 --- a/widget/WidgetMessageUtils.h +++ b/widget/WidgetMessageUtils.h @@ -32,6 +32,44 @@ struct ParamTraits { } }; +template <> +struct ParamTraits { + typedef LookAndFeelFont paramType; + + static void Write(Message* aMsg, const paramType& aParam) { + WriteParam(aMsg, aParam.haveFont); + WriteParam(aMsg, aParam.fontName); + WriteParam(aMsg, aParam.pixelHeight); + WriteParam(aMsg, aParam.italic); + WriteParam(aMsg, aParam.bold); + } + + static bool Read(const Message* aMsg, PickleIterator* aIter, + paramType* aResult) { + return ReadParam(aMsg, aIter, &aResult->haveFont) && + ReadParam(aMsg, aIter, &aResult->fontName) && + ReadParam(aMsg, aIter, &aResult->pixelHeight) && + ReadParam(aMsg, aIter, &aResult->italic) && + ReadParam(aMsg, aIter, &aResult->bold); + } +}; + +template <> +struct ParamTraits { + typedef LookAndFeelCache paramType; + + static void Write(Message* aMsg, const paramType& aParam) { + WriteParam(aMsg, aParam.mInts); + WriteParam(aMsg, aParam.mFonts); + } + + static bool Read(const Message* aMsg, PickleIterator* aIter, + paramType* aResult) { + return ReadParam(aMsg, aIter, &aResult->mInts) && + ReadParam(aMsg, aIter, &aResult->mFonts); + } +}; + template <> struct ParamTraits : public ContiguousEnumSerializerInclusive nsLookAndFeel::GetIntCacheImpl() { - nsTArray lookAndFeelIntCache = - nsXPLookAndFeel::GetIntCacheImpl(); +LookAndFeelCache nsLookAndFeel::GetCacheImpl() { + LookAndFeelCache cache = nsXPLookAndFeel::GetCacheImpl(); const IntID kIdsToCache[] = {IntID::PrefersReducedMotion, IntID::SystemUsesDarkTheme}; for (IntID id : kIdsToCache) { - lookAndFeelIntCache.AppendElement( - LookAndFeelInt{.id = id, .value = GetInt(id)}); + cache.mInts.AppendElement(LookAndFeelInt{.id = id, .value = GetInt(id)}); } - return lookAndFeelIntCache; + return cache; } -void nsLookAndFeel::SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) { - for (const auto& entry : aLookAndFeelIntCache) { +void nsLookAndFeel::SetCacheImpl(const LookAndFeelCache& aCache) { + for (const auto& entry : aCache.mInts) { switch (entry.id) { case IntID::PrefersReducedMotion: mPrefersReducedMotion = entry.value; diff --git a/widget/android/nsLookAndFeel.h b/widget/android/nsLookAndFeel.h index 4296296fb1ca..2c5d2517c3fc 100644 --- a/widget/android/nsLookAndFeel.h +++ b/widget/android/nsLookAndFeel.h @@ -23,9 +23,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel { virtual bool GetEchoPasswordImpl() override; virtual uint32_t GetPasswordMaskDelayImpl() override; virtual char16_t GetPasswordCharacterImpl() override; - virtual nsTArray GetIntCacheImpl() override; - virtual void SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) override; + LookAndFeelCache GetCacheImpl() override; + void SetCacheImpl(const LookAndFeelCache& aCache) override; protected: bool mInitializedSystemColors = false; diff --git a/widget/cocoa/nsLookAndFeel.h b/widget/cocoa/nsLookAndFeel.h index e591230bedfa..9b87b692e205 100644 --- a/widget/cocoa/nsLookAndFeel.h +++ b/widget/cocoa/nsLookAndFeel.h @@ -27,9 +27,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel { static bool UseOverlayScrollbars(); - virtual nsTArray GetIntCacheImpl() override; - virtual void SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) override; + LookAndFeelCache GetCacheImpl() override; + void SetCacheImpl(const LookAndFeelCache& aCache) override; protected: static bool SystemWantsOverlayScrollbars(); diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index e5105cc5ceb6..34cfaf28226e 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -654,34 +654,34 @@ bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& a NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false); } -nsTArray nsLookAndFeel::GetIntCacheImpl() { - nsTArray lookAndFeelIntCache = nsXPLookAndFeel::GetIntCacheImpl(); +LookAndFeelCache nsLookAndFeel::GetCacheImpl() { + LookAndFeelCache cache = nsXPLookAndFeel::GetCacheImpl(); LookAndFeelInt useOverlayScrollbars; useOverlayScrollbars.id = IntID::UseOverlayScrollbars; useOverlayScrollbars.value = GetInt(IntID::UseOverlayScrollbars); - lookAndFeelIntCache.AppendElement(useOverlayScrollbars); + cache.mInts.AppendElement(useOverlayScrollbars); LookAndFeelInt allowOverlayScrollbarsOverlap; allowOverlayScrollbarsOverlap.id = IntID::AllowOverlayScrollbarsOverlap; allowOverlayScrollbarsOverlap.value = GetInt(IntID::AllowOverlayScrollbarsOverlap); - lookAndFeelIntCache.AppendElement(allowOverlayScrollbarsOverlap); + cache.mInts.AppendElement(allowOverlayScrollbarsOverlap); LookAndFeelInt prefersReducedMotion; prefersReducedMotion.id = IntID::PrefersReducedMotion; prefersReducedMotion.value = GetInt(IntID::PrefersReducedMotion); - lookAndFeelIntCache.AppendElement(prefersReducedMotion); + cache.mInts.AppendElement(prefersReducedMotion); LookAndFeelInt systemUsesDarkTheme; systemUsesDarkTheme.id = IntID::SystemUsesDarkTheme; systemUsesDarkTheme.value = GetInt(IntID::SystemUsesDarkTheme); - lookAndFeelIntCache.AppendElement(systemUsesDarkTheme); + cache.mInts.AppendElement(systemUsesDarkTheme); - return lookAndFeelIntCache; + return cache; } -void nsLookAndFeel::SetIntCacheImpl(const nsTArray& aLookAndFeelIntCache) { - for (auto entry : aLookAndFeelIntCache) { +void nsLookAndFeel::SetCacheImpl(const LookAndFeelCache& aCache) { + for (auto entry : aCache.mInts) { switch (entry.id) { case IntID::UseOverlayScrollbars: mUseOverlayScrollbars = entry.value; diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index c277e43b7b10..7107aab6e2e5 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -271,25 +271,22 @@ void nsLookAndFeel::RefreshImpl() { mInitialized = false; } -nsTArray nsLookAndFeel::GetIntCacheImpl() { - nsTArray lookAndFeelIntCache = - nsXPLookAndFeel::GetIntCacheImpl(); +LookAndFeelCache nsLookAndFeel::GetCacheImpl() { + LookAndFeelCache cache = nsXPLookAndFeel::GetCacheImpl(); const IntID kIdsToCache[] = {IntID::SystemUsesDarkTheme, IntID::PrefersReducedMotion, IntID::UseAccessibilityTheme}; for (IntID id : kIdsToCache) { - lookAndFeelIntCache.AppendElement( - LookAndFeelInt{.id = id, .value = GetInt(id)}); + cache.mInts.AppendElement(LookAndFeelInt{.id = id, .value = GetInt(id)}); } - return lookAndFeelIntCache; + return cache; } -void nsLookAndFeel::SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) { - for (const auto& entry : aLookAndFeelIntCache) { +void nsLookAndFeel::SetCacheImpl(const LookAndFeelCache& aCache) { + for (const auto& entry : aCache.mInts) { switch (entry.id) { case IntID::SystemUsesDarkTheme: mSystemUsesDarkTheme = entry.value; diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h index 91d4d1318f4d..fa3779a60301 100644 --- a/widget/gtk/nsLookAndFeel.h +++ b/widget/gtk/nsLookAndFeel.h @@ -31,9 +31,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel { char16_t GetPasswordCharacterImpl() override; bool GetEchoPasswordImpl() override; - nsTArray GetIntCacheImpl() override; - void SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) override; + LookAndFeelCache GetCacheImpl() override; + void SetCacheImpl(const LookAndFeelCache& aCache) override; bool IsCSDAvailable() const { return mCSDAvailable; } diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index 5fb65c56e23f..bd1829b760c6 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -455,10 +455,10 @@ void nsXPLookAndFeel::Init() { if (XRE_IsContentProcess()) { mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton(); - LookAndFeel::SetIntCache(cc->LookAndFeelCache()); + LookAndFeel::SetCache(cc->BorrowLookAndFeelCache()); // This is only ever used once during initialization, and can be cleared // now. - cc->LookAndFeelCache().Clear(); + cc->BorrowLookAndFeelCache().Clear(); } } @@ -999,9 +999,7 @@ void nsXPLookAndFeel::RefreshImpl() { } } -nsTArray nsXPLookAndFeel::GetIntCacheImpl() { - return nsTArray(); -} +LookAndFeelCache nsXPLookAndFeel::GetCacheImpl() { return LookAndFeelCache{}; } static bool sRecordedLookAndFeelTelemetry = false; @@ -1082,14 +1080,13 @@ void LookAndFeel::Refresh() { nsLookAndFeel::GetInstance()->RefreshImpl(); } void LookAndFeel::NativeInit() { nsLookAndFeel::GetInstance()->NativeInit(); } // static -nsTArray LookAndFeel::GetIntCache() { - return nsLookAndFeel::GetInstance()->GetIntCacheImpl(); +LookAndFeelCache LookAndFeel::GetCache() { + return nsLookAndFeel::GetInstance()->GetCacheImpl(); } // static -void LookAndFeel::SetIntCache( - const nsTArray& aLookAndFeelIntCache) { - return nsLookAndFeel::GetInstance()->SetIntCacheImpl(aLookAndFeelIntCache); +void LookAndFeel::SetCache(const LookAndFeelCache& aCache) { + nsLookAndFeel::GetInstance()->SetCacheImpl(aCache); } -} // namespace mozilla +} // namespace mozilla \ No newline at end of file diff --git a/widget/nsXPLookAndFeel.h b/widget/nsXPLookAndFeel.h index 85ed0e6bfcb3..a1922267aba7 100644 --- a/widget/nsXPLookAndFeel.h +++ b/widget/nsXPLookAndFeel.h @@ -72,9 +72,8 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel { virtual uint32_t GetPasswordMaskDelayImpl() { return 600; } - virtual nsTArray GetIntCacheImpl(); - virtual void SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) {} + virtual LookAndFeelCache GetCacheImpl(); + virtual void SetCacheImpl(const LookAndFeelCache& aCache) {} virtual void NativeInit() = 0; diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 9ba2c7100407..f06bc0f99781 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -630,9 +630,9 @@ nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) { return res; } -LookAndFeelFontInfo nsLookAndFeel::GetLookAndFeelFontInfoInternal( +LookAndFeelFont nsLookAndFeel::GetLookAndFeelFontInternal( const LOGFONTW& aLogFont, bool aUseShellDlg) { - LookAndFeelFontInfo result{}; + LookAndFeelFont result{}; result.haveFont = false; @@ -690,9 +690,12 @@ LookAndFeelFontInfo nsLookAndFeel::GetLookAndFeelFontInfoInternal( return result; } -LookAndFeelFontInfo nsLookAndFeel::GetLookAndFeelFontInfo( - LookAndFeel::FontID anID) { - LookAndFeelFontInfo result{}; +LookAndFeelFont nsLookAndFeel::GetLookAndFeelFont(LookAndFeel::FontID anID) { + if (XRE_IsContentProcess()) { + return mFontCache[size_t(anID)]; + } + + LookAndFeelFont result{}; result.haveFont = false; @@ -701,7 +704,7 @@ LookAndFeelFontInfo nsLookAndFeel::GetLookAndFeelFontInfo( LOGFONTW logFont; if (::SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(logFont), (PVOID)&logFont, 0)) { - result = GetLookAndFeelFontInfoInternal(logFont, false); + result = GetLookAndFeelFontInternal(logFont, false); } return result; } @@ -716,17 +719,17 @@ LookAndFeelFontInfo nsLookAndFeel::GetLookAndFeelFontInfo( switch (anID) { case LookAndFeel::FontID::Menu: case LookAndFeel::FontID::PullDownMenu: - result = GetLookAndFeelFontInfoInternal(ncm.lfMenuFont, false); + result = GetLookAndFeelFontInternal(ncm.lfMenuFont, false); break; case LookAndFeel::FontID::Caption: - result = GetLookAndFeelFontInfoInternal(ncm.lfCaptionFont, false); + result = GetLookAndFeelFontInternal(ncm.lfCaptionFont, false); break; case LookAndFeel::FontID::SmallCaption: - result = GetLookAndFeelFontInfoInternal(ncm.lfSmCaptionFont, false); + result = GetLookAndFeelFontInternal(ncm.lfSmCaptionFont, false); break; case LookAndFeel::FontID::StatusBar: case LookAndFeel::FontID::Tooltips: - result = GetLookAndFeelFontInfoInternal(ncm.lfStatusFont, false); + result = GetLookAndFeelFontInternal(ncm.lfStatusFont, false); break; case LookAndFeel::FontID::Widget: case LookAndFeel::FontID::Dialog: @@ -737,35 +740,34 @@ LookAndFeelFontInfo nsLookAndFeel::GetLookAndFeelFontInfo( // set of LookAndFeel values to map to the dialog font; we may // want to add or remove cases here after reviewing the visual // results under various Windows versions. - result = GetLookAndFeelFontInfoInternal(ncm.lfMessageFont, true); + result = GetLookAndFeelFontInternal(ncm.lfMessageFont, true); break; default: - result = GetLookAndFeelFontInfoInternal(ncm.lfMessageFont, false); + result = GetLookAndFeelFontInternal(ncm.lfMessageFont, false); break; } return result; } -bool nsLookAndFeel::GetSysFontInfo(LookAndFeel::FontID anID, - nsString& aFontName, - gfxFontStyle& aFontStyle) { - LookAndFeelFontInfo fontInfo = GetLookAndFeelFontInfo(anID); +bool nsLookAndFeel::GetSysFont(LookAndFeel::FontID anID, nsString& aFontName, + gfxFontStyle& aFontStyle) { + LookAndFeelFont font = GetLookAndFeelFont(anID); - if (!fontInfo.haveFont) { + if (!font.haveFont) { return false; } - aFontName = std::move(fontInfo.fontName); + aFontName = std::move(font.fontName); - aFontStyle.size = fontInfo.pixelHeight; + aFontStyle.size = font.pixelHeight; // FIXME: What about oblique? aFontStyle.style = - fontInfo.italic ? FontSlantStyle::Italic() : FontSlantStyle::Normal(); + font.italic ? FontSlantStyle::Italic() : FontSlantStyle::Normal(); // FIXME: Other weights? - aFontStyle.weight = fontInfo.bold ? FontWeight::Bold() : FontWeight::Normal(); + aFontStyle.weight = font.bold ? FontWeight::Bold() : FontWeight::Normal(); // FIXME: Set aFontStyle->stretch correctly! aFontStyle.stretch = FontStretch::Normal(); @@ -787,7 +789,7 @@ bool nsLookAndFeel::GetFontImpl(FontID anID, nsString& aFontName, aFontStyle = cacheSlot.mFontStyle; } } else { - status = GetSysFontInfo(anID, aFontName, aFontStyle); + status = GetSysFont(anID, aFontName, aFontStyle); cacheSlot.mCacheValid = true; cacheSlot.mHaveFont = status; @@ -805,29 +807,37 @@ char16_t nsLookAndFeel::GetPasswordCharacterImpl() { return UNICODE_BLACK_CIRCLE_CHAR; } -nsTArray nsLookAndFeel::GetIntCacheImpl() { - nsTArray lookAndFeelIntCache = - nsXPLookAndFeel::GetIntCacheImpl(); +LookAndFeelCache nsLookAndFeel::GetCacheImpl() { + MOZ_ASSERT(XRE_IsParentProcess()); + + LookAndFeelCache cache = nsXPLookAndFeel::GetCacheImpl(); LookAndFeelInt lafInt; lafInt.id = IntID::UseAccessibilityTheme; lafInt.value = GetInt(IntID::UseAccessibilityTheme); - lookAndFeelIntCache.AppendElement(lafInt); + cache.mInts.AppendElement(lafInt); lafInt.id = IntID::WindowsDefaultTheme; lafInt.value = GetInt(IntID::WindowsDefaultTheme); - lookAndFeelIntCache.AppendElement(lafInt); + cache.mInts.AppendElement(lafInt); lafInt.id = IntID::WindowsThemeIdentifier; lafInt.value = GetInt(IntID::WindowsThemeIdentifier); - lookAndFeelIntCache.AppendElement(lafInt); + cache.mInts.AppendElement(lafInt); - return lookAndFeelIntCache; + for (size_t i = size_t(LookAndFeel::FontID::MINIMUM); + i <= size_t(LookAndFeel::FontID::MAXIMUM); ++i) { + cache.mFonts.AppendElement(GetLookAndFeelFont(LookAndFeel::FontID(i))); + } + + return cache; } -void nsLookAndFeel::SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) { - for (auto entry : aLookAndFeelIntCache) { +void nsLookAndFeel::SetCacheImpl(const LookAndFeelCache& aCache) { + MOZ_ASSERT(XRE_IsContentProcess()); + MOZ_RELEASE_ASSERT(aCache.mFonts.Length() == mFontCache.length()); + + for (auto entry : aCache.mInts) { switch (entry.id) { case IntID::UseAccessibilityTheme: mUseAccessibilityTheme = entry.value; @@ -843,6 +853,12 @@ void nsLookAndFeel::SetIntCacheImpl( break; } } + + size_t i = mFontCache.minIndex(); + for (const auto& font : aCache.mFonts) { + mFontCache[i] = font; + ++i; + } } /* static */ diff --git a/widget/windows/nsLookAndFeel.h b/widget/windows/nsLookAndFeel.h index 9b92e4c88f44..fb78b60511f3 100644 --- a/widget/windows/nsLookAndFeel.h +++ b/widget/windows/nsLookAndFeel.h @@ -58,9 +58,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel { gfxFontStyle& aFontStyle) override; char16_t GetPasswordCharacterImpl() override; - nsTArray GetIntCacheImpl() override; - void SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) override; + LookAndFeelCache GetCacheImpl() override; + void SetCacheImpl(const LookAndFeelCache& aCache) override; private: /** @@ -81,13 +80,13 @@ class nsLookAndFeel final : public nsXPLookAndFeel { nscolor GetColorForSysColorIndex(int index); - LookAndFeelFontInfo GetLookAndFeelFontInfoInternal(const LOGFONTW& aLogFont, - bool aUseShellDlg); + LookAndFeelFont GetLookAndFeelFontInternal(const LOGFONTW& aLogFont, + bool aUseShellDlg); - LookAndFeelFontInfo GetLookAndFeelFontInfo(LookAndFeel::FontID anID); + LookAndFeelFont GetLookAndFeelFont(LookAndFeel::FontID anID); - bool GetSysFontInfo(LookAndFeel::FontID anID, nsString& aFontName, - gfxFontStyle& aFontStyle); + bool GetSysFont(LookAndFeel::FontID anID, nsString& aFontName, + gfxFontStyle& aFontStyle); // Content process cached values that get shipped over from the browser // process. @@ -127,6 +126,10 @@ class nsLookAndFeel final : public nsXPLookAndFeel { size_t(FontID::MAXIMUM) + 1 - size_t(FontID::MINIMUM)> mSystemFontCache; + mozilla::RangedArray + mFontCache; + nsCOMPtr mDwmKey; };