Bug 1068613 - Part 1: Add gfxCriticalError() log to Moz2D. r=bas

This commit is contained in:
Nicolas Silva 2014-09-17 23:23:02 +02:00
parent 8eab5c164d
commit 4529e9a4ce
3 changed files with 62 additions and 13 deletions

View File

@ -57,6 +57,7 @@ class DataSourceSurface;
class DrawTarget;
class DrawEventRecorder;
class FilterNode;
class LogForwarder;
struct NativeSurface {
NativeSurfaceType mType;
@ -1153,6 +1154,15 @@ public:
static void SetGlobalEventRecorder(DrawEventRecorder *aRecorder);
// This is a little hacky at the moment, but we want to have this data. Bug 1068613.
static void SetLogForwarder(LogForwarder* aLogFwd);
static LogForwarder* GetLogForwarder() { return mLogForwarder; }
private:
static LogForwarder* mLogForwarder;
public:
#ifdef USE_SKIA_GPU
static TemporaryRef<DrawTarget>
CreateDrawTargetSkiaWithGrContext(GrContext* aGrContext,

View File

@ -778,5 +778,24 @@ Factory::SetGlobalEventRecorder(DrawEventRecorder *aRecorder)
mRecorder = aRecorder;
}
LogForwarder* Factory::mLogForwarder = nullptr;
// static
void
Factory::SetLogForwarder(LogForwarder* aLogFwd) {
mLogForwarder = aLogFwd;
}
// static
void
CriticalLogger::OutputMessage(const std::string &aString, int aLevel)
{
if (Factory::GetLogForwarder()) {
Factory::GetLogForwarder()->Log(aString);
}
BasicLogger::OutputMessage(aString, aLevel);
}
}
}

View File

@ -38,6 +38,7 @@ namespace gfx {
const int LOG_DEBUG = 1;
const int LOG_WARNING = 2;
const int LOG_CRITICAL = 3;
#if defined(DEBUG) || defined(PR_LOGGING)
@ -55,21 +56,36 @@ inline PRLogModuleLevel PRLogLevelForLevel(int aLevel) {
extern GFX2D_API int sGfxLogLevel;
static inline void OutputMessage(const std::string &aString, int aLevel) {
struct BasicLogger
{
static void OutputMessage(const std::string &aString, int aLevel) {
#if defined(WIN32) && !defined(PR_LOGGING)
if (aLevel >= sGfxLogLevel) {
::OutputDebugStringA(aString.c_str());
}
if (aLevel >= sGfxLogLevel) {
::OutputDebugStringA(aString.c_str());
}
#elif defined(PR_LOGGING) && !(defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID))
if (PR_LOG_TEST(GetGFX2DLog(), PRLogLevelForLevel(aLevel))) {
PR_LogPrint(aString.c_str());
}
if (PR_LOG_TEST(GetGFX2DLog(), PRLogLevelForLevel(aLevel))) {
PR_LogPrint(aString.c_str());
}
#else
if (aLevel >= sGfxLogLevel) {
printf_stderr("%s", aString.c_str());
}
if (aLevel >= sGfxLogLevel) {
printf_stderr("%s", aString.c_str());
}
#endif
}
}
};
struct CriticalLogger {
static void OutputMessage(const std::string &aString, int aLevel);
};
// Implement this interface and init the Factory with an instance to
// forward critical logs.
class LogForwarder {
public:
virtual ~LogForwarder() {}
virtual void Log(const std::string &aString) = 0;
};
class NoLog
{
@ -85,7 +101,7 @@ MOZ_BEGIN_ENUM_CLASS(LogOptions, int)
NoNewline = 0x01
MOZ_END_ENUM_CLASS(LogOptions)
template<int L>
template<int L, typename Logger = BasicLogger>
class Log
{
public:
@ -134,7 +150,7 @@ public:
private:
void WriteLog(const std::string &aString) {
OutputMessage(aString, L);
Logger::OutputMessage(aString, L);
}
std::stringstream mMessage;
@ -143,6 +159,7 @@ private:
typedef Log<LOG_DEBUG> DebugLog;
typedef Log<LOG_WARNING> WarningLog;
typedef Log<LOG_CRITICAL, CriticalLogger> CriticalLog;
#ifdef GFX_LOG_DEBUG
#define gfxDebug DebugLog
@ -155,6 +172,9 @@ typedef Log<LOG_WARNING> WarningLog;
#define gfxWarning if (1) ; else NoLog
#endif
// This log goes into crash reports, use with care.
#define gfxCriticalError CriticalLog
// See nsDebug.h and the NS_WARN_IF macro
#ifdef __cplusplus