mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1156742 Part 20: Move Moz2D PreferenceAccess into its own header. r=bas
This is so we can add a new preference in Part 21, which has nothing to do with logging.
This commit is contained in:
parent
5e43b7e89e
commit
a91c187fe1
@ -48,6 +48,7 @@
|
||||
|
||||
#include "DrawEventRecorder.h"
|
||||
|
||||
#include "Preferences.h"
|
||||
#include "Logging.h"
|
||||
|
||||
#include "mozilla/CheckedInt.h"
|
||||
@ -152,31 +153,9 @@ HasCPUIDBit(unsigned int level, CPUIDRegister reg, unsigned int bit)
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
// These values we initialize with should match those in
|
||||
// PreferenceAccess::RegisterAll method.
|
||||
int32_t PreferenceAccess::sGfxLogLevel = LOG_DEFAULT;
|
||||
|
||||
PreferenceAccess* PreferenceAccess::sAccess = nullptr;
|
||||
PreferenceAccess::~PreferenceAccess()
|
||||
{
|
||||
}
|
||||
|
||||
// Just a placeholder, the derived class will set the variable to default
|
||||
// if the preference doesn't exist.
|
||||
void PreferenceAccess::LivePref(const char* aName, int32_t* aVar, int32_t aDef)
|
||||
{
|
||||
*aVar = aDef;
|
||||
}
|
||||
|
||||
// This will be called with the derived class, so we will want to register
|
||||
// the callbacks with it.
|
||||
void PreferenceAccess::SetAccess(PreferenceAccess* aAccess) {
|
||||
sAccess = aAccess;
|
||||
if (sAccess) {
|
||||
RegisterAll();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LoggingPrefs::sGfxLogLevel =
|
||||
PreferenceAccess::RegisterLivePref("gfx.logging.level", &sGfxLogLevel,
|
||||
LOG_DEFAULT);
|
||||
|
||||
#ifdef WIN32
|
||||
ID3D10Device1 *Factory::mD3D10Device;
|
||||
|
@ -63,24 +63,9 @@ inline mozilla::LogLevel PRLogLevelForLevel(int aLevel) {
|
||||
}
|
||||
#endif
|
||||
|
||||
class PreferenceAccess
|
||||
class LoggingPrefs
|
||||
{
|
||||
public:
|
||||
virtual ~PreferenceAccess();
|
||||
|
||||
// This should connect the variable aVar to be updated whenever a preference
|
||||
// aName is modified. aDefault would be used if the preference is undefined,
|
||||
// so that we always get the valid value for aVar.
|
||||
virtual void LivePref(const char* aName, int32_t* aVar, int32_t aDefault);
|
||||
|
||||
public:
|
||||
static void SetAccess(PreferenceAccess* aAccess);
|
||||
|
||||
public:
|
||||
// For each preference that needs to be accessed in Moz2D, add a variable
|
||||
// to hold it, as well as the call to LivePref in the RegisterAll() method
|
||||
// below.
|
||||
|
||||
// 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 adds logging/debug. 4 is used to
|
||||
@ -89,15 +74,6 @@ public:
|
||||
// in addition to setting the value to 4, you will need to set an
|
||||
// environment variable NSPR_LOG_MODULES to gfx:4. See prlog.h for details.
|
||||
static int32_t sGfxLogLevel;
|
||||
|
||||
private:
|
||||
static void RegisterAll() {
|
||||
// The default values (last parameter) should match the initialization
|
||||
// values in Factory.cpp, otherwise the standalone Moz2D will get different
|
||||
// defaults.
|
||||
sAccess->LivePref("gfx.logging.level", &sGfxLogLevel, LOG_DEFAULT);
|
||||
}
|
||||
static PreferenceAccess* sAccess;
|
||||
};
|
||||
|
||||
/// Graphics logging is available in both debug and release builds and is
|
||||
@ -165,7 +141,7 @@ struct BasicLogger
|
||||
// OutputMessage below. If making any changes here, also make it
|
||||
// in the appropriate places in that method.
|
||||
static bool ShouldOutputMessage(int aLevel) {
|
||||
if (PreferenceAccess::sGfxLogLevel >= aLevel) {
|
||||
if (LoggingPrefs::sGfxLogLevel >= aLevel) {
|
||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||
return true;
|
||||
#else
|
||||
@ -174,7 +150,7 @@ struct BasicLogger
|
||||
return true;
|
||||
} else
|
||||
#endif
|
||||
if ((PreferenceAccess::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
|
||||
if ((LoggingPrefs::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
|
||||
(aLevel < LOG_DEBUG)) {
|
||||
return true;
|
||||
}
|
||||
@ -198,7 +174,7 @@ struct BasicLogger
|
||||
// If making any logic changes to this method, you should probably
|
||||
// make the corresponding change in the ShouldOutputMessage method
|
||||
// above.
|
||||
if (PreferenceAccess::sGfxLogLevel >= aLevel) {
|
||||
if (LoggingPrefs::sGfxLogLevel >= aLevel) {
|
||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||
printf_stderr("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
|
||||
#else
|
||||
@ -207,7 +183,7 @@ struct BasicLogger
|
||||
PR_LogPrint("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
|
||||
} else
|
||||
#endif
|
||||
if ((PreferenceAccess::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
|
||||
if ((LoggingPrefs::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
|
||||
(aLevel < LOG_DEBUG)) {
|
||||
printf("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
|
||||
}
|
||||
|
60
gfx/2d/Preferences.cpp
Normal file
60
gfx/2d/Preferences.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "Preferences.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
static PreferenceAccess* sAccess = nullptr;
|
||||
|
||||
struct Int32Pref
|
||||
{
|
||||
const char* name;
|
||||
int32_t* varPtr;
|
||||
};
|
||||
|
||||
static Vector<Int32Pref>& Int32Prefs()
|
||||
{
|
||||
static Vector<Int32Pref>* sInt32Prefs = new Vector<Int32Pref>();
|
||||
return *sInt32Prefs;
|
||||
}
|
||||
|
||||
/* static */
|
||||
int32_t
|
||||
PreferenceAccess::RegisterLivePref(const char* aName, int32_t* aVar,
|
||||
int32_t aDefault)
|
||||
{
|
||||
Int32Prefs().append(Int32Pref{ aName, aVar });
|
||||
return aDefault;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
PreferenceAccess::SetAccess(PreferenceAccess* aAccess)
|
||||
{
|
||||
sAccess = aAccess;
|
||||
if (!sAccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
static uint32_t sProvideAccessCount;
|
||||
MOZ_ASSERT(!sProvideAccessCount++,
|
||||
"ProvideAccess must only be called with non-nullptr once.");
|
||||
#endif
|
||||
|
||||
for (Int32Pref pref : Int32Prefs()) {
|
||||
sAccess->LivePref(pref.name, pref.varPtr, *pref.varPtr);
|
||||
}
|
||||
Int32Prefs().clearAndFree();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
34
gfx/2d/Preferences.h
Normal file
34
gfx/2d/Preferences.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_gfx_Preferences_h
|
||||
#define mozilla_gfx_Preferences_h
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class PreferenceAccess
|
||||
{
|
||||
public:
|
||||
virtual ~PreferenceAccess() {};
|
||||
|
||||
// This will be called with the derived class, so we will can register the
|
||||
// callbacks with it.
|
||||
static void SetAccess(PreferenceAccess* aAccess);
|
||||
|
||||
static int32_t RegisterLivePref(const char* aName, int32_t* aVar,
|
||||
int32_t aDefault);
|
||||
protected:
|
||||
// This should connect the variable aVar to be updated whenever a preference
|
||||
// aName is modified. aDefault would be used if the preference is undefined,
|
||||
// so that we always get the valid value for aVar.
|
||||
virtual void LivePref(const char* aName, int32_t* aVar, int32_t aDefault) = 0;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_gfx_Preferences_h
|
@ -38,6 +38,7 @@ EXPORTS.mozilla.gfx += [
|
||||
'PathHelpers.h',
|
||||
'PatternHelpers.h',
|
||||
'Point.h',
|
||||
'Preferences.h',
|
||||
'Quaternion.h',
|
||||
'RecordedEvent.h',
|
||||
'RecordingTypes.h',
|
||||
@ -151,6 +152,7 @@ UNIFIED_SOURCES += [
|
||||
'PathCairo.cpp',
|
||||
'PathHelpers.cpp',
|
||||
'PathRecording.cpp',
|
||||
'Preferences.cpp',
|
||||
'Quaternion.cpp',
|
||||
'RecordedEvent.cpp',
|
||||
'Scale.cpp',
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "mozilla/gfx/Logging.h"
|
||||
#include "mozilla/gfx/Preferences.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user