Skip to content

Commit

Permalink
Bug 978274: Initialize gfxPrefs earlier, rename some methods, delete …
Browse files Browse the repository at this point in the history
…MigratePrefs from gfxPlatform. r=bgirard.
  • Loading branch information
msreckovic committed Mar 4, 2014
1 parent 3427b3b commit 2b8bd73
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 35 deletions.
8 changes: 4 additions & 4 deletions gfx/tests/gtest/TestAsyncPanZoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand Down
67 changes: 67 additions & 0 deletions gfx/tests/gtest/TestGfxPrefs.cpp
Original file line number Diff line number Diff line change
@@ -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());
}

1 change: 1 addition & 0 deletions gfx/tests/gtest/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ UNIFIED_SOURCES += [
'TestAsyncPanZoomController.cpp',
'TestBufferRotation.cpp',
'TestColorNames.cpp',
'TestGfxPrefs.cpp',
'TestLayers.cpp',
'TestRegion.cpp',
'TestSkipChars.cpp',
Expand Down
26 changes: 3 additions & 23 deletions gfx/thebes/gfxPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -506,7 +501,7 @@ gfxPlatform::Shutdown()

delete gGfxPlatformPrefsLock;

gfxPrefs::Destroy();
gfxPrefs::DestroySingleton();

delete gPlatform;
gPlatform = nullptr;
Expand Down Expand Up @@ -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<int32_t>(eCMSMode_All));
}
Preferences::ClearUser(GFX_PREF_CMS_ENABLED_OBSOLETE);
}
}

// default SetupClusterBoundaries, based on Unicode properties;
// platform subclasses may override if they wish
void
Expand Down
4 changes: 2 additions & 2 deletions gfx/thebes/gfxPrefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace mozilla;
gfxPrefs* gfxPrefs::sInstance = nullptr;

void
gfxPrefs::Destroy()
gfxPrefs::DestroySingleton()
{
if (sInstance) {
delete sInstance;
Expand All @@ -22,7 +22,7 @@ gfxPrefs::Destroy()
}

bool
gfxPrefs::Exists()
gfxPrefs::SingletonExists()
{
return sInstance != nullptr;
}
Expand Down
12 changes: 6 additions & 6 deletions gfx/thebes/gfxPrefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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; } \
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions layout/base/nsPresContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "nsRefreshDriver.h"
#include "Layers.h"
#include "nsIDOMEvent.h"
#include "gfxPrefs.h"

#include "nsContentUtils.h"
#include "nsCxPusher.h"
Expand Down Expand Up @@ -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<nsIDocShellTreeItem> docShell(mContainer);
Expand Down

0 comments on commit 2b8bd73

Please sign in to comment.