Bug 1550422 - P17. Convert gfxPrefs::GfxLoggingLevel to StaticPrefs. r?jrmuizel! draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 16 May 2019 13:32:35 +1000
changeset 2008593 ee4d2b82c5c17c8c6711693022cc91efb75532ba
parent 2008592 3e8772162de640369f151f83282f6fa8c2d7401a
child 2008594 87ecbf679a9fe725e20bfb0aded38d9d82170e80
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 - P17. Convert gfxPrefs::GfxLoggingLevel to StaticPrefs. r?jrmuizel! Fly-by fix, we make LoggingPrefs::sGfxLogLevel as it is written on the main thread but read on different threads. Differential Revision: https://phabricator.services.mozilla.com/D31460
gfx/2d/Factory.cpp
gfx/2d/Logging.h
gfx/thebes/gfxPrefs.cpp
gfx/thebes/gfxPrefs.h
modules/libpref/StaticPrefs.h
modules/libpref/init/StaticPrefList.h
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -62,16 +62,18 @@
 
 #include "mozilla/CheckedInt.h"
 
 #ifdef MOZ_ENABLE_FREETYPE
 #  include "ft2build.h"
 #  include FT_FREETYPE_H
 #endif
 #include "MainThreadUtils.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs.h"
 
 #if defined(MOZ_LOGGING)
 GFX2D_API mozilla::LogModule* GetGFX2DLog() {
   static mozilla::LazyLogModule sLog("gfx2d");
   return sLog;
 }
 #endif
 
@@ -183,18 +185,19 @@ void mozilla_UnlockFTLibrary(FT_Library 
   mozilla::gfx::Factory::UnlockFTLibrary(aFTLibrary);
 }
 }
 #endif
 
 namespace mozilla {
 namespace gfx {
 
-// In Gecko, this value is managed by gfx.logging.level in gfxPrefs.
-int32_t LoggingPrefs::sGfxLogLevel = LOG_DEFAULT;
+// In Gecko, this value is managed by gfx.logging.level and gets updated when
+// the pref change.
+Atomic<int32_t> LoggingPrefs::sGfxLogLevel(LOG_DEFAULT);
 
 #ifdef MOZ_ENABLE_FREETYPE
 FT_Library Factory::mFTLibrary = nullptr;
 StaticMutex Factory::mFTLock;
 #endif
 
 #ifdef WIN32
 // Note: mDeviceLock must be held when mutating these values.
@@ -209,19 +212,28 @@ StaticRefPtr<IDWriteFontCollection> Fact
 StaticMutex Factory::mDeviceLock;
 StaticMutex Factory::mDTDependencyLock;
 #endif
 
 DrawEventRecorder* Factory::mRecorder;
 
 mozilla::gfx::Config* Factory::sConfig = nullptr;
 
+static void PrefChanged(const char* aPref, void*) {
+  mozilla::gfx::LoggingPrefs::sGfxLogLevel =
+      Preferences::GetInt(StaticPrefs::GetGfxLoggingLevelPrefName(),
+                          StaticPrefs::GetGfxLoggingLevelPrefDefault());
+}
+
 void Factory::Init(const Config& aConfig) {
   MOZ_ASSERT(!sConfig);
   sConfig = new Config(aConfig);
+  Preferences::RegisterCallback(
+      PrefChanged,
+      nsDependentCString(StaticPrefs::GetGfxLoggingLevelPrefName()));
 }
 
 void Factory::ShutDown() {
   if (sConfig) {
     delete sConfig->mLogForwarder;
     delete sConfig;
     sConfig = nullptr;
   }
--- a/gfx/2d/Logging.h
+++ b/gfx/2d/Logging.h
@@ -16,16 +16,17 @@
 #  include "mozilla/Logging.h"
 #endif
 #include "mozilla/Tuple.h"
 
 #if defined(MOZ_WIDGET_ANDROID)
 #  include "nsDebug.h"
 #endif
 #include "2D.h"
+#include "mozilla/Atomics.h"
 #include "Point.h"
 #include "BaseRect.h"
 #include "Matrix.h"
 #include "LoggingConstants.h"
 
 #if defined(MOZ_LOGGING)
 extern GFX2D_API mozilla::LogModule* GetGFX2DLog();
 #endif
@@ -53,17 +54,17 @@ inline mozilla::LogLevel PRLogLevelForLe
 
 class LoggingPrefs {
  public:
   // Used to choose the level of logging we get.  The higher the number,
   // the more logging we get.  Value of zero will give you no logging,
   // 1 just errors, 2 adds warnings and 3 or 4 add debug logging.
   // In addition to setting the value to 4, you will need to set the
   // environment variable MOZ_LOG to gfx:4. See mozilla/Logging.h for details.
-  static int32_t sGfxLogLevel;
+  static Atomic<int32_t> sGfxLogLevel;
 };
 
 /// Graphics logging is available in both debug and release builds and is
 /// controlled with a gfx.logging.level preference. If not set, the default
 /// for the preference is 5 in the debug builds, 1 in the release builds.
 ///
 /// gfxDebug only works in the debug builds, and is used for information
 /// level messages, helping with debugging.  In addition to only working
--- a/gfx/thebes/gfxPrefs.cpp
+++ b/gfx/thebes/gfxPrefs.cpp
@@ -49,25 +49,20 @@ gfxPrefs::gfxPrefs() {
   MOZ_ASSERT_IF(XRE_IsContentProcess() || XRE_IsParentProcess() ||
                     XRE_GetProcessType() == GeckoProcessType_Plugin,
                 Preferences::IsServiceAvailable());
 
   gfxPrefs::AssertMainThread();
 }
 
 void gfxPrefs::Init() {
-  // Set up Moz2D prefs.
-  SetGfxLoggingLevelChangeCallback([](const GfxPrefValue& aValue) -> void {
-    mozilla::gfx::LoggingPrefs::sGfxLogLevel = aValue.get_int32_t();
-  });
 }
 
 gfxPrefs::~gfxPrefs() {
   gfxPrefs::AssertMainThread();
-  SetGfxLoggingLevelChangeCallback(nullptr);
   delete sGfxPrefList;
   sGfxPrefList = nullptr;
 }
 
 void gfxPrefs::AssertMainThread() {
   MOZ_ASSERT(NS_IsMainThread(), "this code must be run on the main thread");
 }
 
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -284,18 +284,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.
 
-  // Note that        "gfx.logging.level" is defined in Logging.h.
-  DECL_GFX_PREF(Live, "gfx.logging.level",                     GfxLoggingLevel, int32_t, mozilla::gfx::LOG_DEFAULT);
   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.
--- a/modules/libpref/StaticPrefs.h
+++ b/modules/libpref/StaticPrefs.h
@@ -6,16 +6,17 @@
 
 #ifndef mozilla_StaticPrefs_h
 #define mozilla_StaticPrefs_h
 
 #include "gfxPlatform.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/TypeTraits.h"
+#include "mozilla/gfx/LoggingConstants.h"
 #include "MainThreadUtils.h"
 #include <atomic>
 #include <cmath>  // for M_PI
 
 namespace mozilla {
 
 // These typedefs are for use within StaticPrefList.h.
 
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -3388,16 +3388,18 @@ VARCACHE_PREF(Once, "gfx.direct3d11.slee
 VARCACHE_PREF(Live, "gfx.downloadable_fonts.keep_color_bitmaps", KeepColorBitmaps, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "gfx.downloadable_fonts.validate_variation_tables", ValidateVariationTables, RelaxedAtomicBool, true);
 VARCACHE_PREF(Live, "gfx.downloadable_fonts.otl_validation", ValidateOTLTables, RelaxedAtomicBool, true);
 VARCACHE_PREF(Live, "gfx.draw-color-bars",                   CompositorDrawColorBars, RelaxedAtomicBool, false);
 VARCACHE_PREF(Once, "gfx.e10s.hide-plugins-for-scroll",      HidePluginsForScroll, RelaxedAtomicBool, true);
 VARCACHE_PREF(Once, "gfx.e10s.font-list.shared",             SharedFontList, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "gfx.layerscope.enabled",                LayerScopeEnabled, RelaxedAtomicBool, false);
 VARCACHE_PREF(Live, "gfx.layerscope.port",                   LayerScopePort, RelaxedAtomicInt32, 23456);
+// Note that        "gfx.logging.level" is defined in Logging.h.
+VARCACHE_PREF(Live, "gfx.logging.level",                     GfxLoggingLevel, RelaxedAtomicInt32, mozilla::gfx::LOG_DEFAULT);
 VARCACHE_PREF(Once, "gfx.logging.crash.length",              GfxLoggingCrashLength, RelaxedAtomicUint32, 16);
 VARCACHE_PREF(Live, "gfx.logging.painted-pixel-count.enabled",GfxLoggingPaintedPixelCountEnabled, RelaxedAtomicBool, false);
 // The maximums here are quite conservative, we can tighten them if problems show up.
 VARCACHE_PREF(Once, "gfx.logging.texture-usage.enabled",     GfxLoggingTextureUsageEnabled, RelaxedAtomicBool, false);
 VARCACHE_PREF(Once, "gfx.logging.peak-texture-usage.enabled",GfxLoggingPeakTextureUsageEnabled, RelaxedAtomicBool, false);
 VARCACHE_PREF(Once, "gfx.logging.slow-frames.enabled",       LoggingSlowFramesEnabled, RelaxedAtomicBool, false);
 // Use gfxPlatform::MaxAllocSize instead of the pref directly
 VARCACHE_PREF(Once, "gfx.max-alloc-size",                    MaxAllocSizeDoNotUseDirectly, RelaxedAtomicInt32, (int32_t)500000000);