2014-02-13 21:38:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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 "gfxPrefs.h"
|
|
|
|
|
2016-06-25 00:43:41 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2016-06-27 09:33:14 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2016-06-27 09:33:20 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-03-23 23:29:54 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2016-06-27 09:33:18 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2016-06-27 09:33:20 +03:00
|
|
|
#include "mozilla/gfx/GPUChild.h"
|
|
|
|
#include "mozilla/gfx/GPUProcessManager.h"
|
2014-02-13 21:38:40 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2016-06-27 09:33:20 +03:00
|
|
|
nsTArray<gfxPrefs::Pref*>* gfxPrefs::sGfxPrefList = nullptr;
|
2014-02-13 21:38:40 +04:00
|
|
|
gfxPrefs* gfxPrefs::sInstance = nullptr;
|
2014-06-25 18:09:02 +04:00
|
|
|
bool gfxPrefs::sInstanceHasBeenDestroyed = false;
|
2014-02-13 21:38:40 +04:00
|
|
|
|
2017-11-22 05:45:55 +03:00
|
|
|
gfxPrefs&
|
|
|
|
gfxPrefs::CreateAndInitializeSingleton() {
|
|
|
|
MOZ_ASSERT(!sInstanceHasBeenDestroyed,
|
|
|
|
"Should never recreate a gfxPrefs instance!");
|
|
|
|
sGfxPrefList = new nsTArray<Pref*>();
|
|
|
|
sInstance = new gfxPrefs;
|
|
|
|
sInstance->Init();
|
|
|
|
MOZ_ASSERT(SingletonExists());
|
|
|
|
return *sInstance;
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:38:40 +04:00
|
|
|
void
|
2014-03-04 21:26:33 +04:00
|
|
|
gfxPrefs::DestroySingleton()
|
2014-02-13 21:38:40 +04:00
|
|
|
{
|
|
|
|
if (sInstance) {
|
|
|
|
delete sInstance;
|
|
|
|
sInstance = nullptr;
|
2014-06-25 18:09:02 +04:00
|
|
|
sInstanceHasBeenDestroyed = true;
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
2014-06-25 18:09:02 +04:00
|
|
|
MOZ_ASSERT(!SingletonExists());
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-04 21:26:33 +04:00
|
|
|
gfxPrefs::SingletonExists()
|
2014-02-13 21:38:40 +04:00
|
|
|
{
|
|
|
|
return sInstance != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPrefs::gfxPrefs()
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
// UI, content, and plugin processes use XPCOM and should have prefs
|
|
|
|
// ready by the time we initialize gfxPrefs.
|
|
|
|
MOZ_ASSERT_IF(XRE_IsContentProcess() ||
|
|
|
|
XRE_IsParentProcess() ||
|
|
|
|
XRE_GetProcessType() == GeckoProcessType_Plugin,
|
|
|
|
Preferences::IsServiceAvailable());
|
|
|
|
|
2014-07-11 16:25:12 +04:00
|
|
|
gfxPrefs::AssertMainThread();
|
2016-06-27 09:33:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPrefs::Init()
|
|
|
|
{
|
|
|
|
// Set up Moz2D prefs.
|
2016-11-25 09:01:42 +03:00
|
|
|
SetGfxLoggingLevelChangeCallback([](const GfxPrefValue& aValue) -> void {
|
|
|
|
mozilla::gfx::LoggingPrefs::sGfxLogLevel = aValue.get_int32_t();
|
2016-06-27 09:33:18 +03:00
|
|
|
});
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPrefs::~gfxPrefs()
|
|
|
|
{
|
2014-07-11 16:25:12 +04:00
|
|
|
gfxPrefs::AssertMainThread();
|
2016-11-25 09:01:42 +03:00
|
|
|
SetGfxLoggingLevelChangeCallback(nullptr);
|
2016-06-27 09:33:20 +03:00
|
|
|
delete sGfxPrefList;
|
|
|
|
sGfxPrefList = nullptr;
|
2014-07-11 16:25:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::AssertMainThread()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "this code must be run on the main thread");
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
|
|
|
|
2016-06-27 09:33:16 +03:00
|
|
|
void
|
|
|
|
gfxPrefs::Pref::OnChange()
|
2016-06-27 09:33:20 +03:00
|
|
|
{
|
|
|
|
if (auto gpm = gfx::GPUProcessManager::Get()) {
|
|
|
|
if (gfx::GPUChild* gpu = gpm->GetGPUChild()) {
|
|
|
|
GfxPrefValue value;
|
2016-10-25 03:48:28 +03:00
|
|
|
GetLiveValue(&value);
|
2016-06-27 09:33:20 +03:00
|
|
|
Unused << gpu->SendUpdatePref(gfx::GfxPrefSetting(mIndex, value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FireChangeCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPrefs::Pref::FireChangeCallback()
|
2016-06-27 09:33:16 +03:00
|
|
|
{
|
|
|
|
if (mChangeCallback) {
|
2016-11-25 09:01:42 +03:00
|
|
|
GfxPrefValue value;
|
|
|
|
GetLiveValue(&value);
|
|
|
|
mChangeCallback(value);
|
2016-06-27 09:33:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPrefs::Pref::SetChangeCallback(ChangeCallback aCallback)
|
|
|
|
{
|
|
|
|
mChangeCallback = aCallback;
|
|
|
|
|
|
|
|
if (!IsParentProcess() && IsPrefsServiceAvailable()) {
|
|
|
|
// If we're in the parent process, we watch prefs by default so we can
|
|
|
|
// send changes over to the GPU process. Otherwise, we need to add or
|
|
|
|
// remove a watch for the pref now.
|
|
|
|
if (aCallback) {
|
|
|
|
WatchChanges(Name(), this);
|
|
|
|
} else {
|
|
|
|
UnwatchChanges(Name(), this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire the callback once to make initialization easier for the caller.
|
2016-06-27 09:33:20 +03:00
|
|
|
FireChangeCallback();
|
2016-06-27 09:33:16 +03:00
|
|
|
}
|
|
|
|
|
2016-06-27 09:33:14 +03:00
|
|
|
// On lightweight processes such as for GMP and GPU, XPCOM is not initialized,
|
|
|
|
// and therefore we don't have access to Preferences. When XPCOM is not
|
|
|
|
// available we rely on manual synchronization of gfxPrefs values over IPC.
|
|
|
|
/* static */ bool
|
|
|
|
gfxPrefs::IsPrefsServiceAvailable()
|
|
|
|
{
|
|
|
|
return Preferences::IsServiceAvailable();
|
|
|
|
}
|
|
|
|
|
2016-06-27 09:33:16 +03:00
|
|
|
/* static */ bool
|
|
|
|
gfxPrefs::IsParentProcess()
|
|
|
|
{
|
|
|
|
return XRE_IsParentProcess();
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:38:40 +04:00
|
|
|
void gfxPrefs::PrefAddVarCache(bool* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
bool aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-02-13 21:38:40 +04:00
|
|
|
Preferences::AddBoolVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefAddVarCache(int32_t* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
int32_t aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-02-13 21:38:40 +04:00
|
|
|
Preferences::AddIntVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefAddVarCache(uint32_t* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
uint32_t aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-02-13 21:38:40 +04:00
|
|
|
Preferences::AddUintVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
2014-03-03 20:53:21 +04:00
|
|
|
void gfxPrefs::PrefAddVarCache(float* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
float aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-03-03 20:53:21 +04:00
|
|
|
Preferences::AddFloatVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:38:02 +03:00
|
|
|
void gfxPrefs::PrefAddVarCache(std::string* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
std::string aDefault)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
|
|
|
Preferences::SetCString(aPref, aVariable->c_str());
|
|
|
|
}
|
|
|
|
|
2017-11-16 06:02:50 +03:00
|
|
|
void gfxPrefs::PrefAddVarCache(AtomicBool* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
bool aDefault)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
|
|
|
Preferences::AddAtomicBoolVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefAddVarCache(AtomicInt32* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
int32_t aDefault)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
|
|
|
Preferences::AddAtomicIntVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefAddVarCache(AtomicUint32* aVariable,
|
|
|
|
const char* aPref,
|
|
|
|
uint32_t aDefault)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
|
|
|
Preferences::AddAtomicUintVarCache(aVariable, aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:38:40 +04:00
|
|
|
bool gfxPrefs::PrefGet(const char* aPref, bool aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-03-03 20:53:21 +04:00
|
|
|
return Preferences::GetBool(aPref, aDefault);
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t gfxPrefs::PrefGet(const char* aPref, int32_t aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-03-03 20:53:21 +04:00
|
|
|
return Preferences::GetInt(aPref, aDefault);
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t gfxPrefs::PrefGet(const char* aPref, uint32_t aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-03-03 20:53:21 +04:00
|
|
|
return Preferences::GetUint(aPref, aDefault);
|
2014-02-13 21:38:40 +04:00
|
|
|
}
|
2014-03-03 20:53:21 +04:00
|
|
|
|
|
|
|
float gfxPrefs::PrefGet(const char* aPref, float aDefault)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-03-03 20:53:21 +04:00
|
|
|
return Preferences::GetFloat(aPref, aDefault);
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:38:02 +03:00
|
|
|
std::string gfxPrefs::PrefGet(const char* aPref, std::string aDefault)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
|
|
|
|
2017-07-28 04:21:47 +03:00
|
|
|
nsAutoCString result;
|
2017-07-31 03:52:51 +03:00
|
|
|
Preferences::GetCString(aPref, result);
|
2016-11-25 11:23:25 +03:00
|
|
|
|
|
|
|
if (result.IsEmpty()) {
|
|
|
|
return aDefault;
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:38:02 +03:00
|
|
|
return result.get();
|
|
|
|
}
|
|
|
|
|
2014-07-11 16:25:12 +04:00
|
|
|
void gfxPrefs::PrefSet(const char* aPref, bool aValue)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-07-11 16:25:12 +04:00
|
|
|
Preferences::SetBool(aPref, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefSet(const char* aPref, int32_t aValue)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-07-11 16:25:12 +04:00
|
|
|
Preferences::SetInt(aPref, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefSet(const char* aPref, uint32_t aValue)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-07-11 16:25:12 +04:00
|
|
|
Preferences::SetUint(aPref, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::PrefSet(const char* aPref, float aValue)
|
|
|
|
{
|
2016-06-27 09:33:14 +03:00
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2014-07-11 16:25:12 +04:00
|
|
|
Preferences::SetFloat(aPref, aValue);
|
|
|
|
}
|
2014-10-24 21:54:20 +04:00
|
|
|
|
2016-11-23 04:38:02 +03:00
|
|
|
void gfxPrefs::PrefSet(const char* aPref, std::string aValue)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
|
|
|
Preferences::SetCString(aPref, aValue.c_str());
|
|
|
|
}
|
|
|
|
|
2016-06-27 09:33:16 +03:00
|
|
|
static void
|
|
|
|
OnGfxPrefChanged(const char* aPrefname, void* aClosure)
|
|
|
|
{
|
|
|
|
reinterpret_cast<gfxPrefs::Pref*>(aClosure)->OnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::WatchChanges(const char* aPrefname, Pref* aPref)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPrefsServiceAvailable());
|
2017-03-21 21:59:02 +03:00
|
|
|
Preferences::RegisterCallback(OnGfxPrefChanged, aPrefname, aPref);
|
2016-06-27 09:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::UnwatchChanges(const char* aPrefname, Pref* aPref)
|
|
|
|
{
|
|
|
|
// The Preferences service can go offline before gfxPrefs is destroyed.
|
|
|
|
if (IsPrefsServiceAvailable()) {
|
2017-03-21 21:59:02 +03:00
|
|
|
Preferences::UnregisterCallback(OnGfxPrefChanged, aPrefname, aPref);
|
2016-06-27 09:33:16 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-27 09:33:20 +03:00
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const bool* aValue, GfxPrefValue* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = *aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const int32_t* aValue, GfxPrefValue* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = *aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const uint32_t* aValue, GfxPrefValue* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = *aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const float* aValue, GfxPrefValue* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = *aValue;
|
|
|
|
}
|
|
|
|
|
2016-11-23 04:38:02 +03:00
|
|
|
void gfxPrefs::CopyPrefValue(const std::string* aValue, GfxPrefValue* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = nsCString(aValue->c_str());
|
|
|
|
}
|
|
|
|
|
2016-06-27 09:33:20 +03:00
|
|
|
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, bool* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = aValue->get_bool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, int32_t* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = aValue->get_int32_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, uint32_t* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = aValue->get_uint32_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, float* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = aValue->get_float();
|
|
|
|
}
|
2016-11-23 04:38:02 +03:00
|
|
|
|
|
|
|
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, std::string* aOutValue)
|
|
|
|
{
|
|
|
|
*aOutValue = aValue->get_nsCString().get();
|
|
|
|
}
|
2017-03-23 23:29:54 +03:00
|
|
|
|
|
|
|
bool gfxPrefs::OverrideBase_WebRender()
|
|
|
|
{
|
|
|
|
return gfx::gfxVars::UseWebRender();
|
|
|
|
}
|