Bug 1550422 - P18. Convert gfxPrefs::LayoutFrameRate to StaticPrefs. r?jrmuizel! draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 16 May 2019 15:02:46 +1000
changeset 2008594 87ecbf679a9fe725e20bfb0aded38d9d82170e80
parent 2008593 ee4d2b82c5c17c8c6711693022cc91efb75532ba
child 2008595 e918530cf83b5fce77e585bf7ae55edec2c75c74
push id363925
push userjyavenard@mozilla.com
push dateSat, 18 May 2019 07:53:18 +0000
treeherdertry@5082cd581229 [default view] [failures only]
reviewersjrmuizel
bugs1550422
milestone68.0a1
Bug 1550422 - P18. Convert gfxPrefs::LayoutFrameRate to StaticPrefs. r?jrmuizel! Differential Revision: https://phabricator.services.mozilla.com/D31461
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderGLX.cpp
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPrefs.h
modules/libpref/init/StaticPrefList.h
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GLContextProvider.h"
 #include "GLContextCGL.h"
 #include "nsDebug.h"
 #include "nsIWidget.h"
 #include <OpenGL/gl.h>
 #include "gfxFailure.h"
-#include "gfxPrefs.h"
 #include "mozilla/StaticPrefs.h"
 #include "prenv.h"
 #include "GeckoProfiler.h"
 #include "mozilla/gfx/MacIOSurface.h"
 #include "mozilla/layers/CompositorOptions.h"
 #include "mozilla/widget/CompositorWidget.h"
 
 #include <OpenGL/OpenGL.h>
@@ -94,17 +93,17 @@ bool GLContextCGL::MakeCurrentImpl() con
     [mContext makeCurrentContext];
     MOZ_ASSERT(IsCurrentImpl());
     // Use non-blocking swap in "ASAP mode".
     // ASAP mode means that rendering is iterated as fast as possible.
     // ASAP mode is entered when layout.frame_rate=0 (requires restart).
     // If swapInt is 1, then glSwapBuffers will block and wait for a vblank signal.
     // When we're iterating as fast as possible, however, we want a non-blocking
     // glSwapBuffers, which will happen when swapInt==0.
-    GLint swapInt = gfxPrefs::LayoutFrameRate() == 0 ? 0 : 1;
+    GLint swapInt = StaticPrefs::LayoutFrameRate() == 0 ? 0 : 1;
     [mContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
   }
   return true;
 }
 
 bool GLContextCGL::IsCurrentImpl() const { return [NSOpenGLContext currentContext] == mContext; }
 
 GLenum GLContextCGL::GetPreferredARGB32Format() const { return LOCAL_GL_BGRA; }
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -33,17 +33,16 @@
 #include "gfxXlibSurface.h"
 #include "gfxContext.h"
 #include "gfxEnv.h"
 #include "gfxPlatform.h"
 #include "GLContextGLX.h"
 #include "gfxUtils.h"
 #include "gfx2DGlue.h"
 #include "GLScreenBuffer.h"
-#include "gfxPrefs.h"
 
 #include "gfxCrashReporterUtils.h"
 
 #ifdef MOZ_WIDGET_GTK
 #  include "gfxPlatformGtk.h"
 #endif
 
 namespace mozilla {
@@ -593,17 +592,17 @@ bool GLContextGLX::MakeCurrentImpl() con
 
   const bool succeeded = mGLX->fMakeCurrent(mDisplay, mDrawable, mContext);
   NS_ASSERTION(succeeded, "Failed to make GL context current!");
 
   if (!IsOffscreen() && mGLX->SupportsSwapControl()) {
     // Many GLX implementations default to blocking until the next
     // VBlank when calling glXSwapBuffers. We want to run unthrottled
     // in ASAP mode. See bug 1280744.
-    const bool isASAP = (gfxPrefs::LayoutFrameRate() == 0);
+    const bool isASAP = (StaticPrefs::LayoutFrameRate() == 0);
     mGLX->fSwapInterval(mDisplay, mDrawable, isASAP ? 0 : 1);
   }
   return succeeded;
 }
 
 bool GLContextGLX::IsCurrentImpl() const {
   return mGLX->fGetCurrentContext() == mContext;
 }
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -19,17 +19,16 @@
 #include "base/task.h"                // for CancelableTask, etc
 #include "base/thread.h"              // for Thread
 #include "gfxContext.h"               // for gfxContext
 #include "gfxPlatform.h"              // for gfxPlatform
 #include "TreeTraversal.h"            // for ForEachNode
 #ifdef MOZ_WIDGET_GTK
 #  include "gfxPlatformGtk.h"  // for gfxPlatform
 #endif
-#include "gfxPrefs.h"                 // for gfxPrefs
 #include "mozilla/AutoRestore.h"      // for AutoRestore
 #include "mozilla/ClearOnShutdown.h"  // for ClearOnShutdown
 #include "mozilla/DebugOnly.h"        // for DebugOnly
 #include "mozilla/StaticPrefs.h"      // for StaticPrefs
 #include "mozilla/dom/BrowserParent.h"
 #include "mozilla/gfx/2D.h"         // for DrawTarget
 #include "mozilla/gfx/GPUChild.h"   // for GfxPrefValue
 #include "mozilla/gfx/Point.h"      // for IntSize
@@ -293,17 +292,17 @@ void CompositorBridgeParent::FinishShutd
 static int32_t CalculateCompositionFrameRate() {
   // Used when layout.frame_rate is -1. Needs to be kept in sync with
   // DEFAULT_FRAME_RATE in nsRefreshDriver.cpp.
   // TODO: This should actually return the vsync rate.
   const int32_t defaultFrameRate = 60;
   int32_t compositionFrameRatePref = StaticPrefs::LayersCompositionFrameRate();
   if (compositionFrameRatePref < 0) {
     // Use the same frame rate for composition as for layout.
-    int32_t layoutFrameRatePref = gfxPrefs::LayoutFrameRate();
+    int32_t layoutFrameRatePref = StaticPrefs::LayoutFrameRate();
     if (layoutFrameRatePref < 0) {
       // TODO: The main thread frame scheduling code consults the actual
       // monitor refresh rate in this case. We should do the same.
       return defaultFrameRate;
     }
     return layoutFrameRatePref;
   }
   return compositionFrameRatePref;
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -815,16 +815,26 @@ class WrRolloutPrefShutdownSaver : publi
     }
 
     bool defaultValue =
         Preferences::GetBool(WR_ROLLOUT_PREF, false, PrefValueKind::Default);
     Preferences::SetBool(WR_ROLLOUT_PREF_DEFAULT, defaultValue);
   }
 };
 
+static void FrameRatePrefChanged(const char* aPref, void*) {
+  int32_t newRate = gfxPlatform::ForceSoftwareVsync()
+                        ? gfxPlatform::GetSoftwareVsyncRate()
+                        : -1;
+  if (newRate != gLastUsedFrameRate) {
+    gLastUsedFrameRate = newRate;
+    gfxPlatform::ReInitFrameRate();
+  }
+}
+
 NS_IMPL_ISUPPORTS(WrRolloutPrefShutdownSaver, nsIObserver)
 
 void gfxPlatform::Init() {
   MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
   MOZ_RELEASE_ASSERT(!XRE_IsRDDProcess(), "GFX: Not allowed in RDD process.");
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "GFX: Not in main thread.");
 
   if (gEverInitialized) {
@@ -959,24 +969,19 @@ void gfxPlatform::Init() {
   gPlatform->InitOMTPConfig();
 
   if (gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
     GPUProcessManager* gpu = GPUProcessManager::Get();
     gpu->LaunchGPUProcess();
   }
 
   gLastUsedFrameRate = ForceSoftwareVsync() ? GetSoftwareVsyncRate() : -1;
-  auto updateFrameRateCallback = [](const GfxPrefValue& aValue) -> void {
-    int32_t newRate = ForceSoftwareVsync() ? GetSoftwareVsyncRate() : -1;
-    if (newRate != gLastUsedFrameRate) {
-      gLastUsedFrameRate = newRate;
-      ReInitFrameRate();
-    }
-  };
-  gfxPrefs::SetLayoutFrameRateChangeCallback(updateFrameRateCallback);
+  Preferences::RegisterCallback(
+      FrameRatePrefChanged,
+      nsDependentCString(StaticPrefs::GetLayoutFrameRatePrefName()));
   // Set up the vsync source for the parent process.
   ReInitFrameRate();
 
 #ifdef USE_SKIA
   SkGraphics::Init();
 #  ifdef MOZ_ENABLE_FREETYPE
   SkInitCairoFT(gPlatform->FontHintingEnabled());
 #  endif
@@ -3045,28 +3050,28 @@ gfxPlatform::CreateHardwareVsyncSource()
 
 /* static */
 bool gfxPlatform::IsInLayoutAsapMode() {
   // There are 2 modes of ASAP mode.
   // 1 is that the refresh driver and compositor are in lock step
   // the second is that the compositor goes ASAP and the refresh driver
   // goes at whatever the configurated rate is. This only checks the version
   // talos uses, which is the refresh driver and compositor are in lockstep.
-  return gfxPrefs::LayoutFrameRate() == 0;
+  return StaticPrefs::LayoutFrameRate() == 0;
 }
 
 /* static */
 bool gfxPlatform::ForceSoftwareVsync() {
-  return gfxPrefs::LayoutFrameRate() > 0 ||
+  return StaticPrefs::LayoutFrameRate() > 0 ||
          recordreplay::IsRecordingOrReplaying();
 }
 
 /* static */
 int gfxPlatform::GetSoftwareVsyncRate() {
-  int preferenceRate = gfxPrefs::LayoutFrameRate();
+  int preferenceRate = StaticPrefs::LayoutFrameRate();
   if (preferenceRate <= 0) {
     return gfxPlatform::GetDefaultFrameRate();
   }
   return preferenceRate;
 }
 
 /* static */
 int gfxPlatform::GetDefaultFrameRate() { return 60; }
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -286,18 +286,16 @@ class gfxPrefs final {
   // clang-format off
 
   // This is where DECL_GFX_PREF for each of the preferences should go.  We
   // will keep these in an alphabetical order to make it easier to see if a
   // method accessing a pref already exists. Just add yours in the list.
 
   DECL_GFX_PREF(Once, "layers.windowrecording.path",           LayersWindowRecordingPath, std::string, std::string());
 
-  DECL_GFX_PREF(Live, "layout.frame_rate",                     LayoutFrameRate, int32_t, -1);
-
   // WARNING:
   // Please make sure that you've added your new preference to the list above
   // in alphabetical order.
   // Please do not just append it to the end of the list.
 
   // clang-format on
 
  public:
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -3605,16 +3605,17 @@ VARCACHE_PREF(Live, "layout.display-list
 VARCACHE_PREF(Live, "layout.display-list.retain.verify.order", LayoutVerifyRetainDisplayListOrder, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "layout.display-list.rebuild-frame-limit", LayoutRebuildFrameLimit, RelaxedAtomicUint32, 500);
 VARCACHE_PREF(Live, "layout.display-list.dump",              LayoutDumpDisplayList, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "layout.display-list.dump-content",      LayoutDumpDisplayListContent, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "layout.display-list.dump-parent",       LayoutDumpDisplayListParent, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "layout.display-list.show-rebuild-area", LayoutDisplayListShowArea, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "layout.display-list.flatten-transform", LayoutFlattenTransform, RelaxedAtomicBool, true);
 
+VARCACHE_PREF(Live, "layout.frame_rate",                     LayoutFrameRate, RelaxedAtomicInt32, -1);
 VARCACHE_PREF(Live, "layout.min-active-layer-size",          LayoutMinActiveLayerSize, int, 64);
 VARCACHE_PREF(Once, "layout.paint_rects_separately",         LayoutPaintRectsSeparately, RelaxedAtomicBool, true);
 
 // This and code dependent on it should be removed once containerless scrolling looks stable.
 VARCACHE_PREF(Live, "layout.scroll.root-frame-containers",   LayoutUseContainersForRootFrames,RelaxedAtomicBool, false);
 // This pref is to be set by test code only.
 VARCACHE_PREF(Live, "layout.scrollbars.always-layerize-track", AlwaysLayerizeScrollbarTrackTestOnly, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "layout.smaller-painted-layers",         LayoutSmallerPaintedLayers, RelaxedAtomicBool, false);