Commit f5bb220f by Yuly Novikov Committed by Commit Bot

Restore Default Platform logging to stderr

Was lost in https://chromium-review.googlesource.com/434188 Also, don't reset pre-set Platform to Default, otherwise Chrome's platform gets reset. BUG=angleproject:1660, angleproject:1892 Change-Id: I052c86c513c8d89d2420a4724a8bd0dc7446c7c2 Reviewed-on: https://chromium-review.googlesource.com/444928 Commit-Queue: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent cde4f024
......@@ -117,6 +117,11 @@ ScopedPerfEventHelper::~ScopedPerfEventHelper()
LogMessage::LogMessage(const char *function, int line, LogSeverity severity)
: mFunction(function), mLine(line), mSeverity(severity)
{
// EVENT() does not require additional function(line) info.
if (mSeverity != LOG_EVENT)
{
mStream << mFunction << "(" << mLine << "): ";
}
}
LogMessage::~LogMessage()
......@@ -127,32 +132,24 @@ LogMessage::~LogMessage()
}
else
{
trace();
Trace(getSeverity(), getMessage().c_str());
}
}
void LogMessage::trace() const
void Trace(LogSeverity severity, const char *message)
{
if (!ShouldCreateLogMessage(mSeverity))
if (!ShouldCreateLogMessage(severity))
{
return;
}
std::ostringstream stream;
// EVENT() does not require additional function(line) info.
if (mSeverity != LOG_EVENT)
{
stream << LogSeverityName(mSeverity) << ": " << mFunction << "(" << mLine << "): ";
}
stream << mStream.str();
std::string str(stream.str());
std::string str(message);
if (DebugAnnotationsActive())
{
std::wstring formattedWideMessage(str.begin(), str.end());
switch (mSeverity)
switch (severity)
{
case LOG_EVENT:
g_debugAnnotator->beginEvent(formattedWideMessage.c_str());
......@@ -163,15 +160,15 @@ void LogMessage::trace() const
}
}
if (mSeverity == LOG_ERR)
if (severity == LOG_ERR)
{
std::cerr << str << std::endl;
std::cerr << LogSeverityName(severity) << ": " << str << std::endl;
}
#if defined(ANGLE_PLATFORM_WINDOWS) && \
(defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER) || !defined(NDEBUG))
#if !defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER)
if (mSeverity == LOG_ERR)
if (severity == LOG_ERR)
#endif // !defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER)
{
OutputDebugStringA(str.c_str());
......@@ -180,7 +177,7 @@ void LogMessage::trace() const
#if defined(ANGLE_ENABLE_DEBUG_TRACE)
#if defined(NDEBUG)
if (mSeverity == LOG_EVENT || mSeverity == LOG_WARN)
if (severity == LOG_EVENT || severity == LOG_WARN)
{
return;
}
......@@ -188,7 +185,7 @@ void LogMessage::trace() const
static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app);
if (file)
{
file << str << std::endl;
file << LogSeverityName(severity) << ": " << str << std::endl;
file.flush();
}
#endif // defined(ANGLE_ENABLE_DEBUG_TRACE)
......@@ -201,9 +198,7 @@ LogSeverity LogMessage::getSeverity() const
std::string LogMessage::getMessage() const
{
std::ostringstream stream;
stream << mFunction << "(" << mLine << "): " << mStream.str() << std::endl;
return stream.str();
return mStream.str();
}
#if defined(ANGLE_PLATFORM_WINDOWS)
......
......@@ -42,6 +42,8 @@ constexpr LogSeverity LOG_WARN = 1;
constexpr LogSeverity LOG_ERR = 2;
constexpr LogSeverity LOG_NUM_SEVERITIES = 3;
void Trace(LogSeverity severity, const char *message);
// This class more or less represents a particular log message. You
// create an instance of LogMessage and then stream stuff to it.
// When you finish streaming to it, ~LogMessage is called and the
......@@ -56,7 +58,6 @@ class LogMessage : angle::NonCopyable
LogMessage(const char *function, int line, LogSeverity severity);
~LogMessage();
std::ostream &stream() { return mStream; }
void trace() const;
LogSeverity getSeverity() const;
std::string getMessage() const;
......
......@@ -223,6 +223,37 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap, const D
return impl;
}
void Display_logError(angle::PlatformMethods *platform, const char *errorMessage)
{
gl::Trace(gl::LOG_ERR, errorMessage);
}
void Display_logWarning(angle::PlatformMethods *platform, const char *warningMessage)
{
gl::Trace(gl::LOG_WARN, warningMessage);
}
void Display_logInfo(angle::PlatformMethods *platform, const char *infoMessage)
{
// Uncomment to get info spam
// gl::Trace(gl::LOG_WARN, infoMessage);
}
void ANGLESetDefaultDisplayPlatform(angle::EGLDisplayType display)
{
angle::PlatformMethods *platformMethods = ANGLEPlatformCurrent();
if (platformMethods->logError != angle::ANGLE_logError)
{
// Don't reset pre-set Platform to Default
return;
}
ANGLEResetDisplayPlatform(display);
platformMethods->logError = Display_logError;
platformMethods->logWarning = Display_logWarning;
platformMethods->logInfo = Display_logInfo;
}
} // anonymous namespace
Display *Display::GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay,
......@@ -376,7 +407,7 @@ void Display::setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap
Error Display::initialize()
{
// TODO(jmadill): Store Platform in Display and init here.
ANGLEResetDisplayPlatform(this);
ANGLESetDefaultDisplayPlatform(this);
gl::InitializeDebugAnnotations(&mAnnotator);
......
......@@ -32,7 +32,7 @@ void LoggingAnnotator::logMessage(const gl::LogMessage &msg) const
}
else
{
msg.trace();
gl::Trace(msg.getSeverity(), msg.getMessage().c_str());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment