diff --git a/gfx/tests/gtest/TestAsyncPanZoomController.cpp b/gfx/tests/gtest/TestAsyncPanZoomController.cpp index 840fe44adf2986..cb08cfbaf9d79f 100644 --- a/gfx/tests/gtest/TestAsyncPanZoomController.cpp +++ b/gfx/tests/gtest/TestAsyncPanZoomController.cpp @@ -33,20 +33,20 @@ class Task; class AsyncPanZoomControllerTester : public ::testing::Test { protected: virtual void SetUp() { - gfxPrefs::One(); + gfxPrefs::GetSingleton(); } virtual void TearDown() { - gfxPrefs::Destroy(); + gfxPrefs::DestroySingleton(); } }; class APZCTreeManagerTester : public ::testing::Test { protected: virtual void SetUp() { - gfxPrefs::One(); + gfxPrefs::GetSingleton(); } virtual void TearDown() { - gfxPrefs::Destroy(); + gfxPrefs::DestroySingleton(); } }; diff --git a/gfx/tests/gtest/TestGfxPrefs.cpp b/gfx/tests/gtest/TestGfxPrefs.cpp new file mode 100644 index 00000000000000..05b1fc83aec7e0 --- /dev/null +++ b/gfx/tests/gtest/TestGfxPrefs.cpp @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "gtest/gtest.h" + +#include "gfxPrefs.h" +#ifdef GFX_DECL_PREF +#error "This is not supposed to be defined outside of gfxPrefs.h" +#endif + +// If the default values for any of these preferences change, +// just modify the test to match. We are only testing against +// a particular value to make sure we receive the correct +// result through this API. + +TEST(GfxPrefs, Singleton) { + ASSERT_FALSE(gfxPrefs::SingletonExists()); + gfxPrefs::GetSingleton(); + ASSERT_TRUE(gfxPrefs::SingletonExists()); + gfxPrefs::DestroySingleton(); + ASSERT_FALSE(gfxPrefs::SingletonExists()); +} + +TEST(GfxPrefs, LiveValues) { + ASSERT_FALSE(gfxPrefs::SingletonExists()); + gfxPrefs::GetSingleton(); + ASSERT_TRUE(gfxPrefs::SingletonExists()); + + // Live boolean, default false + ASSERT_FALSE(gfxPrefs::CanvasAzureAccelerated()); + + // Live int32_t, default 23456 + ASSERT_TRUE(gfxPrefs::LayerScopePort() == 23456); + + // Live uint32_t, default 2 + ASSERT_TRUE(gfxPrefs::MSAALevel() == 2); + + gfxPrefs::DestroySingleton(); + ASSERT_FALSE(gfxPrefs::SingletonExists()); +} + +TEST(GfxPrefs, OnceValues) { + ASSERT_FALSE(gfxPrefs::SingletonExists()); + gfxPrefs::GetSingleton(); + ASSERT_TRUE(gfxPrefs::SingletonExists()); + + // Once boolean, default true + ASSERT_TRUE(gfxPrefs::WorkAroundDriverBugs()); + + // Once boolean, default false + ASSERT_FALSE(gfxPrefs::LayersDump()); + + // Once int32_t, default 95 + ASSERT_TRUE(gfxPrefs::CanvasSkiaGLCacheSize() == 96); + + // Once uint32_t, default 5 + ASSERT_TRUE(gfxPrefs::APZMaxVelocityQueueSize() == 5); + + // Once float, default -1 (should be OK with ==) + ASSERT_TRUE(gfxPrefs::APZMaxVelocity() == -1.0f); + + gfxPrefs::DestroySingleton(); + ASSERT_FALSE(gfxPrefs::SingletonExists()); +} + diff --git a/gfx/tests/gtest/moz.build b/gfx/tests/gtest/moz.build index 73b983497eb7c8..35a67fcf6a110b 100644 --- a/gfx/tests/gtest/moz.build +++ b/gfx/tests/gtest/moz.build @@ -13,6 +13,7 @@ UNIFIED_SOURCES += [ 'TestAsyncPanZoomController.cpp', 'TestBufferRotation.cpp', 'TestColorNames.cpp', + 'TestGfxPrefs.cpp', 'TestLayers.cpp', 'TestRegion.cpp', 'TestSkipChars.cpp', diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index c8e24556e551ad..8e483ae73abf7a 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -107,7 +107,6 @@ static eCMSMode gCMSMode = eCMSMode_Off; static int gCMSIntent = -2; static void ShutdownCMS(); -static void MigratePrefs(); #include "mozilla/gfx/2D.h" using namespace mozilla::gfx; @@ -324,12 +323,8 @@ gfxPlatform::Init() } gEverInitialized = true; - /* Pref migration hook. */ - MigratePrefs(); - - // Initialize the preferences by creating the singleton. This should - // be done after the preference migration using MigratePrefs(). - gfxPrefs::One(); + // Initialize the preferences by creating the singleton. + gfxPrefs::GetSingleton(); gGfxPlatformPrefsLock = new Mutex("gfxPlatform::gGfxPlatformPrefsLock"); @@ -506,7 +501,7 @@ gfxPlatform::Shutdown() delete gGfxPlatformPrefsLock; - gfxPrefs::Destroy(); + gfxPrefs::DestroySingleton(); delete gPlatform; gPlatform = nullptr; @@ -1749,21 +1744,6 @@ static void ShutdownCMS() gCMSInitialized = false; } -static void MigratePrefs() -{ - /* Migrate from the boolean color_management.enabled pref - we now use - color_management.mode. These calls should be made before gfxPrefs - is initialized, otherwise we may not pick up the correct values - with the gfxPrefs functions. - */ - if (Preferences::HasUserValue(GFX_PREF_CMS_ENABLED_OBSOLETE)) { - if (Preferences::GetBool(GFX_PREF_CMS_ENABLED_OBSOLETE, false)) { - Preferences::SetInt(GFX_PREF_CMS_MODE, static_cast(eCMSMode_All)); - } - Preferences::ClearUser(GFX_PREF_CMS_ENABLED_OBSOLETE); - } -} - // default SetupClusterBoundaries, based on Unicode properties; // platform subclasses may override if they wish void diff --git a/gfx/thebes/gfxPrefs.cpp b/gfx/thebes/gfxPrefs.cpp index a8f2c4527211cf..ecf08cdd41f489 100644 --- a/gfx/thebes/gfxPrefs.cpp +++ b/gfx/thebes/gfxPrefs.cpp @@ -13,7 +13,7 @@ using namespace mozilla; gfxPrefs* gfxPrefs::sInstance = nullptr; void -gfxPrefs::Destroy() +gfxPrefs::DestroySingleton() { if (sInstance) { delete sInstance; @@ -22,7 +22,7 @@ gfxPrefs::Destroy() } bool -gfxPrefs::Exists() +gfxPrefs::SingletonExists() { return sInstance != nullptr; } diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index be73fbff507911..117704a6767db9 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -10,7 +10,7 @@ #include "mozilla/Assertions.h" #include "mozilla/TypedEnum.h" -// First time gfxPrefs::One() needs to be called on the main thread, +// First time gfxPrefs::GetSingleton() needs to be called on the main thread, // before any of the methods accessing the values are used, but after // the Preferences system has been initialized. @@ -53,7 +53,7 @@ #define DECL_GFX_PREF(Update, Pref, Name, Type, Default) \ public: \ -static Type Name() { MOZ_ASSERT(Exists()); return One().mPref##Name.mValue; } \ +static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \ private: \ static const char* Get##Name##PrefName() { return Pref; } \ static Type Get##Name##PrefDefault() { return Default; } \ @@ -128,7 +128,7 @@ class gfxPrefs MOZ_FINAL DECL_GFX_PREF(Live, "gl.msaa-level", MSAALevel, uint32_t, 2); DECL_GFX_PREF(Once, "layers.acceleration.disabled", LayersAccelerationDisabled, bool, false); - DECL_GFX_PREF(Live, "layers.acceleration.draw-fps", LayersDrawFPS, bool, true); + DECL_GFX_PREF(Live, "layers.acceleration.draw-fps", LayersDrawFPS, bool, false); DECL_GFX_PREF(Once, "layers.acceleration.force-enabled", LayersAccelerationForceEnabled, bool, false); #ifdef XP_WIN // On windows, ignore the preference value, forcing async video to false. @@ -172,15 +172,15 @@ class gfxPrefs MOZ_FINAL public: // Manage the singleton: - static gfxPrefs& One() + static gfxPrefs& GetSingleton() { if (!sInstance) { sInstance = new gfxPrefs; } return *sInstance; } - static void Destroy(); - static bool Exists(); + static void DestroySingleton(); + static bool SingletonExists(); private: static gfxPrefs* sInstance; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index e50eb5161434bc..623da836115f02 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -53,6 +53,7 @@ #include "nsRefreshDriver.h" #include "Layers.h" #include "nsIDOMEvent.h" +#include "gfxPrefs.h" #include "nsContentUtils.h" #include "nsCxPusher.h" @@ -688,6 +689,11 @@ nsPresContext::GetFontPrefsForLang(nsIAtom *aLanguage) const void nsPresContext::GetDocumentColorPreferences() { + // Make sure the preferences are initialized. In the normal run, + // they would already be, because gfxPlatform would have been created, + // but in some reference tests, that is not the case. + gfxPrefs::GetSingleton(); + int32_t useAccessibilityTheme = 0; bool usePrefColors = true; nsCOMPtr docShell(mContainer);