Bug 1500876 - Remove PContent::GetSystemColors sync IPC. r=snorp,mccr8, a=RyanVM
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 29 Oct 2018 01:35:47 +0000
changeset 500937 f82eaa1ff6a520b47242a776fbcf431b39900ed3
parent 500936 1bef24401c99d6375d189430885044fa77824818
child 500938 fcb8fd2dd657df97912e2d754ed613372456c32e
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, mccr8, RyanVM
bugs1500876
milestone64.0
Bug 1500876 - Remove PContent::GetSystemColors sync IPC. r=snorp,mccr8, a=RyanVM Content process of Android uses sync IPC when initializing LookAndFeel. But current e10s has LookAndFeel cache for start up of content process. So we should use it, then remove sync IPC for start up performance Differential Revision: https://phabricator.services.mozilla.com/D9750
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
ipc/ipdl/sync-messages.ini
widget/LookAndFeel.h
widget/android/nsLookAndFeel.cpp
widget/android/nsLookAndFeel.h
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2929,36 +2929,16 @@ ContentParent::RecvPlayEventSound(const 
   NS_ENSURE_SUCCESS(rv, IPC_OK());
 
   sound->PlayEventSound(aEventId);
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
-ContentParent::RecvGetSystemColors(const uint32_t& colorsCount,
-                                   InfallibleTArray<uint32_t>* colors)
-{
-#ifdef MOZ_WIDGET_ANDROID
-  NS_ASSERTION(AndroidBridge::Bridge() != nullptr, "AndroidBridge is not available");
-  if (AndroidBridge::Bridge() == nullptr) {
-    // Do not fail - the colors won't be right, but it's not critical
-    return IPC_OK();
-  }
-
-  colors->AppendElements(colorsCount);
-
-  // The array elements correspond to the members of AndroidSystemColors structure,
-  // so just pass the pointer to the elements buffer
-  AndroidBridge::Bridge()->GetSystemColors((AndroidSystemColors*)colors->Elements());
-#endif
-  return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
 ContentParent::RecvGetIconForExtension(const nsCString& aFileExt,
                                        const uint32_t& aIconSize,
                                        InfallibleTArray<uint8_t>* bits)
 {
 #ifdef MOZ_WIDGET_ANDROID
   NS_ASSERTION(AndroidBridge::Bridge() != nullptr, "AndroidBridge is not available");
   if (AndroidBridge::Bridge() == nullptr) {
     // Do not fail - just no icon will be shown
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -1028,19 +1028,16 @@ private:
   virtual mozilla::ipc::IPCResult RecvGetExternalClipboardFormats(const int32_t& aWhichClipboard,
                                                                   const bool& aPlainTextOnly,
                                                                   nsTArray<nsCString>* aTypes) override;
 
   virtual mozilla::ipc::IPCResult RecvPlaySound(const URIParams& aURI) override;
   virtual mozilla::ipc::IPCResult RecvBeep() override;
   virtual mozilla::ipc::IPCResult RecvPlayEventSound(const uint32_t& aEventId) override;
 
-  virtual mozilla::ipc::IPCResult RecvGetSystemColors(const uint32_t& colorsCount,
-                                                      InfallibleTArray<uint32_t>* colors) override;
-
   virtual mozilla::ipc::IPCResult RecvGetIconForExtension(const nsCString& aFileExt,
                                                           const uint32_t& aIconSize,
                                                           InfallibleTArray<uint8_t>* bits) override;
 
   virtual mozilla::ipc::IPCResult RecvGetShowPasswordSetting(bool* showPassword) override;
 
   virtual mozilla::ipc::IPCResult RecvStartVisitedQuery(const URIParams& uri) override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -887,19 +887,16 @@ parent:
         returns (bool hasType);
 
     // 'Play', 'Beep' and 'PlayEventSound' are the only nsISound methods used in
     // the content process.
     async PlaySound(URIParams aURL) compress;
     async Beep() compress;
     async PlayEventSound(uint32_t aEventId) compress;
 
-    sync GetSystemColors(uint32_t colorsCount)
-        returns (uint32_t[] colors);
-
     sync GetIconForExtension(nsCString aFileExt, uint32_t aIconSize)
         returns (uint8_t[] bits);
 
     sync GetShowPasswordSetting()
         returns (bool showPassword);
 
     // Notify the parent of the presence or absence of private docshells
     async PrivateDocShellsExist(bool aExist);
--- a/ipc/ipdl/sync-messages.ini
+++ b/ipc/ipdl/sync-messages.ini
@@ -869,18 +869,16 @@ description =
 [PContent::ReadFontList]
 description =
 [PContent::GetClipboard]
 description =
 [PContent::ClipboardHasType]
 description =
 [PContent::GetExternalClipboardFormats]
 description = Retrieve supported clipboard formats synchronously
-[PContent::GetSystemColors]
-description =
 [PContent::GetIconForExtension]
 description =
 [PContent::GetShowPasswordSetting]
 description =
 [PContent::KeywordToURI]
 description =
 [PContent::NotifyKeywordSearchLoading]
 description =
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -14,17 +14,20 @@
 #include "nsColor.h"
 #include "nsTArray.h"
 
 struct gfxFontStyle;
 
 struct LookAndFeelInt
 {
   int32_t id;
-  int32_t value;
+  union {
+    int32_t value;
+    nscolor colorValue;
+  };
 };
 
 namespace mozilla {
 
 class LookAndFeel
 {
 public:
   // When modifying this list, also modify nsXPLookAndFeel::sColorPrefs
--- a/widget/android/nsLookAndFeel.cpp
+++ b/widget/android/nsLookAndFeel.cpp
@@ -49,40 +49,16 @@ nsLookAndFeel::GetSystemColors()
     if (!AndroidBridge::Bridge())
         return NS_ERROR_FAILURE;
 
     AndroidBridge::Bridge()->GetSystemColors(&mSystemColors);
 
     return NS_OK;
 }
 
-nsresult
-nsLookAndFeel::CallRemoteGetSystemColors()
-{
-    // An array has to be used to get data from remote process
-    InfallibleTArray<uint32_t> colors;
-    uint32_t colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor);
-
-    if (!ContentChild::GetSingleton()->SendGetSystemColors(colorsCount, &colors))
-        return NS_ERROR_FAILURE;
-
-    NS_ASSERTION(colors.Length() == colorsCount, "System colors array is incomplete");
-    if (colors.Length() == 0)
-        return NS_ERROR_FAILURE;
-
-    if (colors.Length() < colorsCount)
-        colorsCount = colors.Length();
-
-    // Array elements correspond to the members of mSystemColors structure,
-    // so just copy the memory block
-    memcpy(&mSystemColors, colors.Elements(), sizeof(nscolor) * colorsCount);
-
-    return NS_OK;
-}
-
 void
 nsLookAndFeel::NativeInit()
 {
     EnsureInitSystemColors();
     EnsureInitShowPassword();
 }
 
 /* virtual */
@@ -515,30 +491,109 @@ nsLookAndFeel::GetPasswordCharacterImpl(
   // This value is hard-coded in Android OS's PasswordTransformationMethod.java
   return UNICODE_BULLET;
 }
 
 void
 nsLookAndFeel::EnsureInitSystemColors()
 {
     if (!mInitializedSystemColors) {
-        nsresult rv;
         if (XRE_IsParentProcess()) {
-            rv = GetSystemColors();
-        } else {
-            rv = CallRemoteGetSystemColors();
+            nsresult rv = GetSystemColors();
+            mInitializedSystemColors = NS_SUCCEEDED(rv);
         }
-        mInitializedSystemColors = NS_SUCCEEDED(rv);
+        // Child process will set system color cache from ContentParent.
     }
 }
 
 void
 nsLookAndFeel::EnsureInitShowPassword()
 {
     if (!mInitializedShowPassword) {
         if (XRE_IsParentProcess()) {
             mShowPassword = jni::IsAvailable() && java::GeckoAppShell::GetShowPasswordSetting();
         } else {
             ContentChild::GetSingleton()->SendGetShowPasswordSetting(&mShowPassword);
         }
         mInitializedShowPassword = true;
     }
 }
+
+nsTArray<LookAndFeelInt>
+nsLookAndFeel::GetIntCacheImpl()
+{
+    MOZ_ASSERT(XRE_IsParentProcess());
+    EnsureInitSystemColors();
+    MOZ_ASSERT(mInitializedSystemColors);
+
+    nsTArray<LookAndFeelInt> lookAndFeelCache =
+        nsXPLookAndFeel::GetIntCacheImpl();
+    lookAndFeelCache.SetCapacity(sizeof(AndroidSystemColors) / sizeof(nscolor));
+
+    LookAndFeelInt laf;
+    laf.id = eColorID_WindowForeground;
+    laf.colorValue = mSystemColors.textColorPrimary;
+    lookAndFeelCache.AppendElement(laf);
+
+    laf.id = eColorID_WidgetBackground;
+    laf.colorValue = mSystemColors.colorBackground;
+    lookAndFeelCache.AppendElement(laf);
+
+    laf.id = eColorID_WidgetForeground;
+    laf.colorValue = mSystemColors.colorForeground;
+    lookAndFeelCache.AppendElement(laf);
+
+    laf.id = eColorID_WidgetSelectBackground;
+    laf.colorValue = mSystemColors.textColorHighlight;
+    lookAndFeelCache.AppendElement(laf);
+
+    laf.id = eColorID_WidgetSelectForeground;
+    laf.colorValue = mSystemColors.textColorPrimaryInverse;
+    lookAndFeelCache.AppendElement(laf);
+
+    laf.id = eColorID_inactivecaptiontext;
+    laf.colorValue = mSystemColors.textColorTertiary;
+    lookAndFeelCache.AppendElement(laf);
+
+    laf.id = eColorID_windowtext;
+    laf.colorValue = mSystemColors.textColorPrimary;
+    lookAndFeelCache.AppendElement(laf);
+
+    // XXX The following colors are unused.
+    // - textColorTertiaryInverse
+    // - panelColorForeground
+    // - panelColorBackground
+
+    return lookAndFeelCache;
+}
+
+void
+nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelCache)
+{
+    for (auto entry : aLookAndFeelCache) {
+        switch (entry.id) {
+        case eColorID_WindowForeground:
+            mSystemColors.textColorPrimary = entry.colorValue;
+            break;
+        case eColorID_WidgetBackground:
+            mSystemColors.colorBackground = entry.colorValue;
+            break;
+        case eColorID_WidgetForeground:
+            mSystemColors.colorForeground = entry.colorValue;
+            break;
+        case eColorID_WidgetSelectBackground:
+            mSystemColors.textColorHighlight = entry.colorValue;
+            break;
+        case eColorID_WidgetSelectForeground:
+            mSystemColors.textColorPrimaryInverse = entry.colorValue;
+            break;
+        case eColorID_inactivecaptiontext:
+            mSystemColors.textColorTertiary = entry.colorValue;
+            break;
+        case eColorID_windowtext:
+            mSystemColors.textColorPrimary = entry.colorValue;
+            break;
+        default:
+            MOZ_ASSERT(false);
+        }
+    }
+    mInitializedSystemColors = true;
+}
--- a/widget/android/nsLookAndFeel.h
+++ b/widget/android/nsLookAndFeel.h
@@ -19,16 +19,19 @@ public:
     virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) override;
     virtual nsresult GetIntImpl(IntID aID, int32_t &aResult) override;
     virtual nsresult GetFloatImpl(FloatID aID, float &aResult) override;
     virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle,
                              float aDevPixPerCSSPixel) override;
     virtual bool GetEchoPasswordImpl() override;
     virtual uint32_t GetPasswordMaskDelayImpl() override;
     virtual char16_t GetPasswordCharacterImpl() override;
+    virtual nsTArray<LookAndFeelInt> GetIntCacheImpl() override;
+    virtual void SetIntCacheImpl(
+                   const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override;
 
     void SetPrefersReducedMotionOverrideForTest(bool aValue)
     {
       mIsInPrefersReducedMotionForTest = true;
       mPrefersReducedMotionForTest = aValue;
     }
     void ResetPrefersReducedMotionOverrideForTest()
     {
@@ -40,15 +43,14 @@ protected:
     static bool mInitializedSystemColors;
     static mozilla::AndroidSystemColors mSystemColors;
     static bool mInitializedShowPassword;
     static bool mShowPassword;
     static bool mIsInPrefersReducedMotionForTest;
     static bool mPrefersReducedMotionForTest;
 
     nsresult GetSystemColors();
-    nsresult CallRemoteGetSystemColors();
 
     void EnsureInitSystemColors();
     void EnsureInitShowPassword();
 };
 
 #endif