зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1074952 - Part 1. Expose the level of logging as a preference. r=bschouten
This commit is contained in:
Родитель
856e7191b0
Коммит
e189fc86de
|
@ -156,8 +156,31 @@ HasCPUIDBit(unsigned int level, CPUIDRegister reg, unsigned int bit)
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
// XXX - Need to define an API to set this.
|
// These values we initialize with should match those in
|
||||||
GFX2D_API int sGfxLogLevel = LOG_DEBUG;
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
ID3D10Device1 *Factory::mD3D10Device;
|
ID3D10Device1 *Factory::mD3D10Device;
|
||||||
|
|
|
@ -44,6 +44,12 @@ const int LOG_DEBUG = 1;
|
||||||
const int LOG_WARNING = 2;
|
const int LOG_WARNING = 2;
|
||||||
const int LOG_CRITICAL = 3;
|
const int LOG_CRITICAL = 3;
|
||||||
|
|
||||||
|
#if defined(DEBUG)
|
||||||
|
const int LOG_DEFAULT = LOG_DEBUG;
|
||||||
|
#else
|
||||||
|
const int LOG_DEFAULT = LOG_CRITICAL;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(PR_LOGGING)
|
#if defined(PR_LOGGING)
|
||||||
|
|
||||||
inline PRLogModuleLevel PRLogLevelForLevel(int aLevel) {
|
inline PRLogModuleLevel PRLogLevelForLevel(int aLevel) {
|
||||||
|
@ -52,19 +58,52 @@ inline PRLogModuleLevel PRLogLevelForLevel(int aLevel) {
|
||||||
return PR_LOG_DEBUG;
|
return PR_LOG_DEBUG;
|
||||||
case LOG_WARNING:
|
case LOG_WARNING:
|
||||||
return PR_LOG_WARNING;
|
return PR_LOG_WARNING;
|
||||||
|
case LOG_CRITICAL:
|
||||||
|
return PR_LOG_ERROR;
|
||||||
}
|
}
|
||||||
return PR_LOG_DEBUG;
|
return PR_LOG_DEBUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern GFX2D_API int sGfxLogLevel;
|
class PreferenceAccess
|
||||||
|
{
|
||||||
|
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 less logging we get. Value of zero will give you all the logging
|
||||||
|
// we have. The default is LOG_DEBUG (1).
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
struct BasicLogger
|
struct BasicLogger
|
||||||
{
|
{
|
||||||
static void OutputMessage(const std::string &aString, int aLevel) {
|
static void OutputMessage(const std::string &aString, int aLevel) {
|
||||||
#if defined(WIN32) && !defined(PR_LOGGING)
|
#if defined(WIN32) && !defined(PR_LOGGING)
|
||||||
if (aLevel >= sGfxLogLevel) {
|
if (aLevel >= PreferenceAccess::sGfxLogLevel) {
|
||||||
::OutputDebugStringA(aString.c_str());
|
::OutputDebugStringA(aString.c_str());
|
||||||
}
|
}
|
||||||
#elif defined(PR_LOGGING) && !(defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID))
|
#elif defined(PR_LOGGING) && !(defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID))
|
||||||
|
@ -72,7 +111,7 @@ struct BasicLogger
|
||||||
PR_LogPrint(aString.c_str());
|
PR_LogPrint(aString.c_str());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (aLevel >= sGfxLogLevel) {
|
if (aLevel >= PreferenceAccess::sGfxLogLevel) {
|
||||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||||
printf_stderr("%s", aString.c_str());
|
printf_stderr("%s", aString.c_str());
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -7,12 +7,31 @@
|
||||||
|
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "MainThreadUtils.h"
|
#include "MainThreadUtils.h"
|
||||||
|
#include "mozilla/gfx/Logging.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
gfxPrefs* gfxPrefs::sInstance = nullptr;
|
gfxPrefs* gfxPrefs::sInstance = nullptr;
|
||||||
bool gfxPrefs::sInstanceHasBeenDestroyed = false;
|
bool gfxPrefs::sInstanceHasBeenDestroyed = false;
|
||||||
|
|
||||||
|
class PreferenceAccessImpl : public mozilla::gfx::PreferenceAccess
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~PreferenceAccessImpl();
|
||||||
|
virtual void LivePref(const char* aName, int32_t* aVar, int32_t aDefault) MOZ_OVERRIDE;
|
||||||
|
};
|
||||||
|
|
||||||
|
PreferenceAccessImpl::~PreferenceAccessImpl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreferenceAccessImpl::LivePref(const char* aName,
|
||||||
|
int32_t* aVar,
|
||||||
|
int32_t aDefault)
|
||||||
|
{
|
||||||
|
Preferences::AddIntVarCache(aVar, aName, aDefault);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gfxPrefs::DestroySingleton()
|
gfxPrefs::DestroySingleton()
|
||||||
{
|
{
|
||||||
|
@ -33,11 +52,19 @@ gfxPrefs::SingletonExists()
|
||||||
gfxPrefs::gfxPrefs()
|
gfxPrefs::gfxPrefs()
|
||||||
{
|
{
|
||||||
gfxPrefs::AssertMainThread();
|
gfxPrefs::AssertMainThread();
|
||||||
|
mMoz2DPrefAccess = new PreferenceAccessImpl;
|
||||||
|
mozilla::gfx::PreferenceAccess::SetAccess(mMoz2DPrefAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfxPrefs::~gfxPrefs()
|
gfxPrefs::~gfxPrefs()
|
||||||
{
|
{
|
||||||
gfxPrefs::AssertMainThread();
|
gfxPrefs::AssertMainThread();
|
||||||
|
|
||||||
|
// gfxPrefs is a singleton, we can reset this to null once
|
||||||
|
// it goes away.
|
||||||
|
mozilla::gfx::PreferenceAccess::SetAccess(nullptr);
|
||||||
|
delete mMoz2DPrefAccess;
|
||||||
|
mMoz2DPrefAccess = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxPrefs::AssertMainThread()
|
void gfxPrefs::AssertMainThread()
|
||||||
|
@ -112,3 +139,4 @@ void gfxPrefs::PrefSet(const char* aPref, float aValue)
|
||||||
{
|
{
|
||||||
Preferences::SetFloat(aPref, aValue);
|
Preferences::SetFloat(aPref, aValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,14 @@ static const char* Get##Name##PrefName() { return Pref; } \
|
||||||
static Type Get##Name##PrefDefault() { return Default; } \
|
static Type Get##Name##PrefDefault() { return Default; } \
|
||||||
PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
|
PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
|
||||||
|
|
||||||
|
class PreferenceAccessImpl;
|
||||||
class gfxPrefs;
|
class gfxPrefs;
|
||||||
class gfxPrefs MOZ_FINAL
|
class gfxPrefs MOZ_FINAL
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
/// See Logging.h. This lets Moz2D access preference values it owns.
|
||||||
|
PreferenceAccessImpl* mMoz2DPrefAccess;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Enums for the update policy.
|
// Enums for the update policy.
|
||||||
MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy)
|
MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче