2017-10-28 02:10:06 +03:00
|
|
|
/* -*- 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
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_LOGGING_H_
|
|
|
|
#define MOZILLA_GFX_LOGGING_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2011-06-30 02:13:21 +04:00
|
|
|
#include <stdio.h>
|
2015-01-14 05:19:25 +03:00
|
|
|
#include <vector>
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-10-06 20:33:06 +04:00
|
|
|
#ifdef MOZ_LOGGING
|
2015-05-19 21:15:34 +03:00
|
|
|
# include "mozilla/Logging.h"
|
2014-10-06 20:33:06 +04:00
|
|
|
#endif
|
2015-12-30 13:47:00 +03:00
|
|
|
#include "mozilla/Tuple.h"
|
2014-10-06 20:33:06 +04:00
|
|
|
|
2016-10-27 03:17:10 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2014-01-22 05:11:52 +04:00
|
|
|
# include "nsDebug.h"
|
2014-09-23 20:37:22 +04:00
|
|
|
#endif
|
2018-02-06 07:00:45 +03:00
|
|
|
#include "2D.h"
|
2019-05-26 17:30:29 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_gfx.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "Point.h"
|
2014-01-22 03:38:34 +04:00
|
|
|
#include "BaseRect.h"
|
2012-01-05 03:02:59 +04:00
|
|
|
#include "Matrix.h"
|
2016-06-27 09:33:18 +03:00
|
|
|
#include "LoggingConstants.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-09-22 18:39:12 +03:00
|
|
|
#if defined(MOZ_LOGGING)
|
2015-10-30 01:48:20 +03:00
|
|
|
extern GFX2D_API mozilla::LogModule* GetGFX2DLog();
|
2015-09-22 18:39:12 +03:00
|
|
|
#endif
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2015-09-22 18:39:12 +03:00
|
|
|
#if defined(MOZ_LOGGING)
|
2015-06-04 01:25:57 +03:00
|
|
|
inline mozilla::LogLevel PRLogLevelForLevel(int aLevel) {
|
2011-06-24 21:41:16 +04:00
|
|
|
switch (aLevel) {
|
2014-10-24 21:54:20 +04:00
|
|
|
case LOG_CRITICAL:
|
2015-06-04 01:25:57 +03:00
|
|
|
return LogLevel::Error;
|
2014-10-24 21:54:26 +04:00
|
|
|
case LOG_WARNING:
|
2015-06-04 01:25:57 +03:00
|
|
|
return LogLevel::Warning;
|
2014-10-24 21:54:26 +04:00
|
|
|
case LOG_DEBUG:
|
2015-06-04 01:25:57 +03:00
|
|
|
return LogLevel::Debug;
|
2014-10-24 21:54:26 +04:00
|
|
|
case LOG_DEBUG_PRLOG:
|
2015-06-04 01:25:57 +03:00
|
|
|
return LogLevel::Debug;
|
2014-10-24 21:54:26 +04:00
|
|
|
case LOG_EVERYTHING:
|
2015-06-04 01:25:57 +03:00
|
|
|
return LogLevel::Error;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
return LogLevel::Debug;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
2015-09-22 18:39:12 +03:00
|
|
|
#endif
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-12-18 01:54:04 +03:00
|
|
|
/// Graphics logging is available in both debug and release builds and is
|
|
|
|
/// controlled with a gfx.logging.level preference. If not set, the default
|
|
|
|
/// for the preference is 5 in the debug builds, 1 in the release builds.
|
|
|
|
///
|
|
|
|
/// gfxDebug only works in the debug builds, and is used for information
|
|
|
|
/// level messages, helping with debugging. In addition to only working
|
|
|
|
/// in the debug builds, the value of the above preference of 3 or higher
|
|
|
|
/// is required.
|
|
|
|
///
|
|
|
|
/// gfxWarning messages are available in both debug and release builds,
|
|
|
|
/// on by default in the debug builds, and off by default in the release builds.
|
|
|
|
/// Setting the preference gfx.logging.level to a value of 2 or higher will
|
|
|
|
/// show the warnings.
|
|
|
|
///
|
|
|
|
/// gfxCriticalError is available in debug and release builds by default.
|
|
|
|
/// It is only unavailable if gfx.logging.level is set to 0 (or less.)
|
|
|
|
/// It outputs the message to stderr or equivalent, like gfxWarning.
|
|
|
|
/// In the event of a crash, the crash report is annotated with first and
|
|
|
|
/// the last few of these errors, under the key GraphicsCriticalError.
|
|
|
|
/// The total number of errors stored in the crash report is controlled
|
2016-02-11 21:04:20 +03:00
|
|
|
/// by preference gfx.logging.crash.length.
|
2014-12-18 01:54:04 +03:00
|
|
|
///
|
2015-10-30 01:48:20 +03:00
|
|
|
/// On platforms that support MOZ_LOGGING, the story is slightly more involved.
|
2014-12-18 01:54:04 +03:00
|
|
|
/// In that case, unless gfx.logging.level is set to 4 or higher, the output
|
2015-10-30 01:48:20 +03:00
|
|
|
/// is further controlled by the "gfx2d" logging module. However, in the case
|
2014-12-18 01:54:04 +03:00
|
|
|
/// where such module would disable the output, in all but gfxDebug cases,
|
|
|
|
/// we will still send a printf.
|
2015-10-14 09:24:00 +03:00
|
|
|
|
|
|
|
// The range is due to the values set in Histograms.json
|
|
|
|
enum class LogReason : int {
|
|
|
|
MustBeMoreThanThis = -1,
|
|
|
|
// Start. Do not insert, always add at end. If you remove items,
|
|
|
|
// make sure the other items retain their values.
|
2015-10-27 16:11:00 +03:00
|
|
|
D3D11InvalidCallDeviceRemoved = 0,
|
2015-11-09 13:28:00 +03:00
|
|
|
D3D11InvalidCall,
|
|
|
|
D3DLockTimeout,
|
|
|
|
D3D10FinalizeFrame,
|
|
|
|
D3D11FinalizeFrame,
|
|
|
|
D3D10SyncLock,
|
|
|
|
D3D11SyncLock,
|
2015-11-26 10:38:00 +03:00
|
|
|
D2D1NoWriteMap,
|
|
|
|
JobStatusError,
|
|
|
|
FilterInputError,
|
|
|
|
FilterInputData, // 10
|
|
|
|
FilterInputRect,
|
|
|
|
FilterInputSet,
|
|
|
|
FilterInputFormat,
|
|
|
|
FilterNodeD2D1Target,
|
|
|
|
FilterNodeD2D1Backend,
|
|
|
|
SourceSurfaceIncompatible,
|
|
|
|
GlyphAllocFailedCairo,
|
|
|
|
GlyphAllocFailedCG,
|
|
|
|
InvalidRect,
|
2015-12-10 15:01:00 +03:00
|
|
|
CannotDraw3D, // 20
|
2016-02-08 13:56:00 +03:00
|
|
|
IncompatibleBasicTexturedEffect,
|
2016-02-23 20:55:44 +03:00
|
|
|
InvalidFont,
|
2016-03-25 11:36:17 +03:00
|
|
|
PAllocTextureBackendMismatch,
|
2016-04-22 15:23:25 +03:00
|
|
|
GetFontFileDataFailed,
|
2016-04-06 19:03:22 +03:00
|
|
|
MessageChannelCloseFailure,
|
2016-05-11 03:59:15 +03:00
|
|
|
MessageChannelInvalidHandle,
|
2016-04-07 15:35:55 +03:00
|
|
|
TextureAliveAfterShutdown,
|
2016-04-12 22:18:11 +03:00
|
|
|
InvalidContext,
|
2016-04-20 19:11:00 +03:00
|
|
|
InvalidCommandList,
|
2016-05-11 03:59:15 +03:00
|
|
|
AsyncTransactionTimeout, // 30
|
|
|
|
TextureCreation,
|
2016-05-19 08:01:26 +03:00
|
|
|
InvalidCacheSurface,
|
2016-07-20 17:26:02 +03:00
|
|
|
AlphaWithBasicClient,
|
2016-08-24 12:06:45 +03:00
|
|
|
UnbalancedClipStack,
|
2016-09-16 09:55:24 +03:00
|
|
|
ProcessingError,
|
2016-11-15 20:56:16 +03:00
|
|
|
InvalidDrawTarget,
|
2016-12-15 13:55:10 +03:00
|
|
|
NativeFontResourceNotFound,
|
2017-04-14 21:11:00 +03:00
|
|
|
UnscaledFontNotFound,
|
2018-09-06 04:55:53 +03:00
|
|
|
ScaledFontNotFound,
|
2018-12-02 17:17:12 +03:00
|
|
|
InvalidLayerType, // 40
|
|
|
|
PlayEventFailed,
|
2019-08-05 16:08:30 +03:00
|
|
|
InvalidConstrainedValueRead,
|
2015-10-14 09:24:00 +03:00
|
|
|
// End
|
|
|
|
MustBeLessThanThis = 101,
|
|
|
|
};
|
|
|
|
|
2014-09-18 01:23:02 +04:00
|
|
|
struct BasicLogger {
|
2014-10-24 21:54:26 +04:00
|
|
|
// For efficiency, this method exists and copies the logic of the
|
|
|
|
// OutputMessage below. If making any changes here, also make it
|
|
|
|
// in the appropriate places in that method.
|
|
|
|
static bool ShouldOutputMessage(int aLevel) {
|
2019-07-24 03:05:23 +03:00
|
|
|
if (StaticPrefs::gfx_logging_level() >= aLevel) {
|
2016-10-27 03:17:10 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2014-10-24 21:54:26 +04:00
|
|
|
return true;
|
2015-05-09 00:37:01 +03:00
|
|
|
#else
|
2015-09-22 18:39:12 +03:00
|
|
|
# if defined(MOZ_LOGGING)
|
2015-06-04 01:22:28 +03:00
|
|
|
if (MOZ_LOG_TEST(GetGFX2DLog(), PRLogLevelForLevel(aLevel))) {
|
2014-10-24 21:54:26 +04:00
|
|
|
return true;
|
2015-09-22 18:39:12 +03:00
|
|
|
} else
|
|
|
|
# endif
|
2019-07-24 03:05:23 +03:00
|
|
|
if ((StaticPrefs::gfx_logging_level() >= LOG_DEBUG_PRLOG) ||
|
2014-10-24 21:54:26 +04:00
|
|
|
(aLevel < LOG_DEBUG)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-23 20:37:22 +04:00
|
|
|
#endif
|
2014-09-18 01:23:02 +04:00
|
|
|
}
|
2014-10-24 21:54:26 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-14 09:24:00 +03:00
|
|
|
// Only for really critical errors.
|
|
|
|
static void CrashAction(LogReason aReason) {}
|
|
|
|
|
2014-10-24 21:54:26 +04:00
|
|
|
static void OutputMessage(const std::string& aString, int aLevel,
|
|
|
|
bool aNoNewline) {
|
|
|
|
// This behavior (the higher the preference, the more we log)
|
|
|
|
// is consistent with what prlog does in general. Note that if prlog
|
|
|
|
// is in the build, but disabled, we will printf if the preferences
|
2019-07-24 03:05:23 +03:00
|
|
|
// requires us to log something.
|
2014-10-24 21:54:26 +04:00
|
|
|
//
|
|
|
|
// If making any logic changes to this method, you should probably
|
|
|
|
// make the corresponding change in the ShouldOutputMessage method
|
|
|
|
// above.
|
2019-07-24 03:05:23 +03:00
|
|
|
if (StaticPrefs::gfx_logging_level() >= aLevel) {
|
2016-10-27 03:17:10 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2014-10-24 21:54:26 +04:00
|
|
|
printf_stderr("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
|
2015-05-09 00:37:01 +03:00
|
|
|
#else
|
2015-09-22 18:39:12 +03:00
|
|
|
# if defined(MOZ_LOGGING)
|
2015-06-04 01:22:28 +03:00
|
|
|
if (MOZ_LOG_TEST(GetGFX2DLog(), PRLogLevelForLevel(aLevel))) {
|
2017-04-05 00:36:21 +03:00
|
|
|
MOZ_LOG(GetGFX2DLog(), PRLogLevelForLevel(aLevel),
|
|
|
|
("%s%s", aString.c_str(), aNoNewline ? "" : "\n"));
|
2015-09-22 18:39:12 +03:00
|
|
|
} else
|
|
|
|
# endif
|
2019-07-24 03:05:23 +03:00
|
|
|
if ((StaticPrefs::gfx_logging_level() >= LOG_DEBUG_PRLOG) ||
|
2014-10-24 21:54:26 +04:00
|
|
|
(aLevel < LOG_DEBUG)) {
|
|
|
|
printf("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
|
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
#endif
|
2014-10-24 21:54:26 +04:00
|
|
|
}
|
2014-09-18 01:23:02 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CriticalLogger {
|
2014-10-24 21:54:26 +04:00
|
|
|
static void OutputMessage(const std::string& aString, int aLevel,
|
|
|
|
bool aNoNewline);
|
2015-10-14 09:24:00 +03:00
|
|
|
static void CrashAction(LogReason aReason);
|
2014-09-18 01:23:02 +04:00
|
|
|
};
|
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
// The int is the index of the Log call; if the number of logs exceeds some
|
|
|
|
// preset capacity we may not get all of them, so the indices help figure out
|
|
|
|
// which ones we did save. The double is expected to be the "TimeDuration",
|
2015-12-30 13:47:00 +03:00
|
|
|
// time in seconds since the process creation.
|
|
|
|
typedef mozilla::Tuple<int32_t, std::string, double> LoggingRecordEntry;
|
|
|
|
|
2014-09-18 01:23:02 +04:00
|
|
|
// Implement this interface and init the Factory with an instance to
|
|
|
|
// forward critical logs.
|
2015-12-30 13:47:00 +03:00
|
|
|
typedef std::vector<LoggingRecordEntry> LoggingRecord;
|
2014-09-18 01:23:02 +04:00
|
|
|
class LogForwarder {
|
|
|
|
public:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~LogForwarder() = default;
|
2014-09-18 01:23:02 +04:00
|
|
|
virtual void Log(const std::string& aString) = 0;
|
2015-10-14 09:24:00 +03:00
|
|
|
virtual void CrashAction(LogReason aReason) = 0;
|
2016-02-17 02:07:37 +03:00
|
|
|
virtual bool UpdateStringsVector(const std::string& aString) = 0;
|
2015-01-14 05:19:25 +03:00
|
|
|
|
2015-12-30 13:47:00 +03:00
|
|
|
// Provide a copy of the logs to the caller.
|
|
|
|
virtual LoggingRecord LoggingRecordCopy() = 0;
|
2014-09-18 01:23:02 +04:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
class NoLog {
|
|
|
|
public:
|
|
|
|
NoLog() {}
|
|
|
|
~NoLog() {}
|
|
|
|
|
2015-04-27 21:44:13 +03:00
|
|
|
// No-op
|
|
|
|
MOZ_IMPLICIT NoLog(const NoLog&) {}
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
template <typename T>
|
|
|
|
NoLog& operator<<(const T& aLogText) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class LogOptions : int {
|
2014-10-24 21:54:26 +04:00
|
|
|
NoNewline = 0x01,
|
2014-12-18 01:54:04 +03:00
|
|
|
AutoPrefix = 0x02,
|
2015-10-14 09:24:00 +03:00
|
|
|
AssertOnCall = 0x04,
|
|
|
|
CrashAction = 0x08,
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-01-22 03:59:17 +04:00
|
|
|
|
2014-09-23 19:35:39 +04:00
|
|
|
template <typename T>
|
|
|
|
struct Hexa {
|
2014-09-24 17:16:53 +04:00
|
|
|
explicit Hexa(T aVal) : mVal(aVal) {}
|
2014-09-23 19:35:39 +04:00
|
|
|
T mVal;
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
Hexa<T> hexa(T val) {
|
|
|
|
return Hexa<T>(val);
|
|
|
|
}
|
|
|
|
|
2018-12-12 01:16:21 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
void LogWStr(const wchar_t* aStr, std::stringstream& aOut);
|
|
|
|
#endif
|
|
|
|
|
2014-09-18 01:23:02 +04:00
|
|
|
template <int L, typename Logger = BasicLogger>
|
2019-04-11 15:36:51 +03:00
|
|
|
class Log final {
|
2011-06-24 21:41:16 +04:00
|
|
|
public:
|
2014-12-18 01:54:04 +03:00
|
|
|
// The default is to have the prefix, have the new line, and for critical
|
|
|
|
// logs assert on each call.
|
|
|
|
static int DefaultOptions(bool aWithAssert = true) {
|
|
|
|
return (int(LogOptions::AutoPrefix) |
|
|
|
|
(aWithAssert ? int(LogOptions::AssertOnCall) : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we're calling BasicLogger::ShouldOutputMessage, rather than
|
|
|
|
// Logger::ShouldOutputMessage. Since we currently don't have a different
|
|
|
|
// version of that method for different loggers, this is OK. Once we do,
|
|
|
|
// change BasicLogger::ShouldOutputMessage to Logger::ShouldOutputMessage.
|
2015-10-14 09:24:00 +03:00
|
|
|
explicit Log(int aOptions = Log::DefaultOptions(L == LOG_CRITICAL),
|
2016-01-12 21:16:59 +03:00
|
|
|
LogReason aReason = LogReason::MustBeMoreThanThis)
|
2018-04-13 16:01:28 +03:00
|
|
|
: mOptions(0), mLogIt(false) {
|
2015-10-14 09:24:00 +03:00
|
|
|
Init(aOptions, BasicLogger::ShouldOutputMessage(L), aReason);
|
2014-10-24 21:54:26 +04:00
|
|
|
}
|
2015-04-27 21:44:13 +03:00
|
|
|
|
2014-01-22 05:14:47 +04:00
|
|
|
~Log() { Flush(); }
|
|
|
|
|
|
|
|
void Flush() {
|
2014-10-24 21:54:26 +04:00
|
|
|
if (MOZ_LIKELY(!LogIt())) return;
|
|
|
|
|
2014-01-22 05:14:47 +04:00
|
|
|
std::string str = mMessage.str();
|
|
|
|
if (!str.empty()) {
|
|
|
|
WriteLog(str);
|
|
|
|
}
|
2015-05-16 16:11:04 +03:00
|
|
|
mMessage.str("");
|
2014-01-22 03:59:17 +04:00
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-10-24 21:54:26 +04:00
|
|
|
Log& operator<<(char aChar) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aChar;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2018-04-13 16:01:28 +03:00
|
|
|
Log& operator<<(const std::string& aLogText) {
|
2014-10-24 21:54:26 +04:00
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aLogText;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const char aStr[]) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << static_cast<const char*>(aStr);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2018-12-11 23:58:02 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
Log& operator<<(const wchar_t aWStr[]) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
2018-12-12 01:16:21 +03:00
|
|
|
LogWStr(aWStr, mMessage);
|
2018-12-11 23:58:02 +03:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-24 21:54:26 +04:00
|
|
|
Log& operator<<(bool aBool) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << (aBool ? "true" : "false");
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(int aInt) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aInt;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(unsigned int aInt) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aInt;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(long aLong) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aLong;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(unsigned long aLong) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aLong;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(long long aLong) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aLong;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(unsigned long long aLong) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aLong;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(Float aFloat) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aFloat;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(double aDouble) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << aDouble;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2018-02-06 07:00:45 +03:00
|
|
|
Log& operator<<(const Color& aColor) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Color(" << aColor.r << ", " << aColor.g << ", " << aColor.b
|
|
|
|
<< ", " << aColor.a << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2014-09-23 00:53:04 +04:00
|
|
|
template <typename T, typename Sub, typename Coord>
|
2014-10-24 21:54:26 +04:00
|
|
|
Log& operator<<(const BasePoint<T, Sub, Coord>& aPoint) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Point" << aPoint;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2014-01-22 03:38:34 +04:00
|
|
|
template <typename T, typename Sub>
|
2014-10-24 21:54:26 +04:00
|
|
|
Log& operator<<(const BaseSize<T, Sub>& aSize) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Size(" << aSize.width << "," << aSize.height << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2014-01-22 03:38:34 +04:00
|
|
|
template <typename T, typename Sub, typename Point, typename SizeT,
|
|
|
|
typename Margin>
|
2014-10-24 21:54:26 +04:00
|
|
|
Log& operator<<(const BaseRect<T, Sub, Point, SizeT, Margin>& aRect) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Rect" << aRect;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const Matrix& aMatrix) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Matrix(" << aMatrix._11 << " " << aMatrix._12 << " ; "
|
|
|
|
<< aMatrix._21 << " " << aMatrix._22 << " ; " << aMatrix._31
|
|
|
|
<< " " << aMatrix._32 << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2014-09-23 19:35:39 +04:00
|
|
|
template <typename T>
|
2014-10-24 21:54:26 +04:00
|
|
|
Log& operator<<(Hexa<T> aHex) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
2016-01-18 14:03:15 +03:00
|
|
|
mMessage << std::showbase << std::hex << aHex.mVal << std::noshowbase
|
|
|
|
<< std::dec;
|
2014-10-24 21:54:26 +04:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-06 07:00:45 +03:00
|
|
|
Log& operator<<(const SourceSurface* aSurface) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "SourceSurface(" << (void*)(aSurface) << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const Path* aPath) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Path(" << (void*)(aPath) << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const Pattern* aPattern) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "Pattern(" << (void*)(aPattern) << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const ScaledFont* aFont) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "ScaledFont(" << (void*)(aFont) << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const FilterNode* aFilter) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "FilterNode(" << (void*)(aFilter) << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const DrawOptions& aOptions) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "DrawOptions(" << aOptions.mAlpha << ", ";
|
|
|
|
(*this) << aOptions.mCompositionOp;
|
|
|
|
mMessage << ", ";
|
|
|
|
(*this) << aOptions.mAntialiasMode;
|
|
|
|
mMessage << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(const DrawSurfaceOptions& aOptions) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
mMessage << "DrawSurfaceOptions(";
|
|
|
|
(*this) << aOptions.mSamplingFilter;
|
|
|
|
mMessage << ", ";
|
|
|
|
(*this) << aOptions.mSamplingBounds;
|
|
|
|
mMessage << ")";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log& operator<<(SamplingBounds aBounds) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
switch (aBounds) {
|
|
|
|
case SamplingBounds::UNBOUNDED:
|
|
|
|
mMessage << "SamplingBounds::UNBOUNDED";
|
|
|
|
break;
|
|
|
|
case SamplingBounds::BOUNDED:
|
|
|
|
mMessage << "SamplingBounds::BOUNDED";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mMessage << "Invalid SamplingBounds (" << (int)aBounds << ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(SamplingFilter aFilter) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
switch (aFilter) {
|
|
|
|
case SamplingFilter::GOOD:
|
|
|
|
mMessage << "SamplingFilter::GOOD";
|
|
|
|
break;
|
|
|
|
case SamplingFilter::LINEAR:
|
|
|
|
mMessage << "SamplingFilter::LINEAR";
|
|
|
|
break;
|
|
|
|
case SamplingFilter::POINT:
|
|
|
|
mMessage << "SamplingFilter::POINT";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mMessage << "Invalid SamplingFilter (" << (int)aFilter << ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(AntialiasMode aMode) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
switch (aMode) {
|
|
|
|
case AntialiasMode::NONE:
|
|
|
|
mMessage << "AntialiasMode::NONE";
|
|
|
|
break;
|
|
|
|
case AntialiasMode::GRAY:
|
|
|
|
mMessage << "AntialiasMode::GRAY";
|
|
|
|
break;
|
|
|
|
case AntialiasMode::SUBPIXEL:
|
|
|
|
mMessage << "AntialiasMode::SUBPIXEL";
|
|
|
|
break;
|
|
|
|
case AntialiasMode::DEFAULT:
|
|
|
|
mMessage << "AntialiasMode::DEFAULT";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mMessage << "Invalid AntialiasMode (" << (int)aMode << ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Log& operator<<(CompositionOp aOp) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
switch (aOp) {
|
|
|
|
case CompositionOp::OP_OVER:
|
|
|
|
mMessage << "CompositionOp::OP_OVER";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_ADD:
|
|
|
|
mMessage << "CompositionOp::OP_ADD";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_ATOP:
|
|
|
|
mMessage << "CompositionOp::OP_ATOP";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_OUT:
|
|
|
|
mMessage << "CompositionOp::OP_OUT";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_IN:
|
|
|
|
mMessage << "CompositionOp::OP_IN";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_SOURCE:
|
|
|
|
mMessage << "CompositionOp::OP_SOURCE";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_DEST_IN:
|
|
|
|
mMessage << "CompositionOp::OP_DEST_IN";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_DEST_OUT:
|
|
|
|
mMessage << "CompositionOp::OP_DEST_OUT";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_DEST_OVER:
|
|
|
|
mMessage << "CompositionOp::OP_DEST_OVER";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_DEST_ATOP:
|
|
|
|
mMessage << "CompositionOp::OP_DEST_ATOP";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_XOR:
|
|
|
|
mMessage << "CompositionOp::OP_XOR";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_MULTIPLY:
|
|
|
|
mMessage << "CompositionOp::OP_MULTIPLY";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_SCREEN:
|
|
|
|
mMessage << "CompositionOp::OP_SCREEN";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_OVERLAY:
|
|
|
|
mMessage << "CompositionOp::OP_OVERLAY";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_DARKEN:
|
|
|
|
mMessage << "CompositionOp::OP_DARKEN";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_LIGHTEN:
|
|
|
|
mMessage << "CompositionOp::OP_LIGHTEN";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_COLOR_DODGE:
|
|
|
|
mMessage << "CompositionOp::OP_COLOR_DODGE";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_COLOR_BURN:
|
|
|
|
mMessage << "CompositionOp::OP_COLOR_BURN";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_HARD_LIGHT:
|
|
|
|
mMessage << "CompositionOp::OP_HARD_LIGHT";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_SOFT_LIGHT:
|
|
|
|
mMessage << "CompositionOp::OP_SOFT_LIGHT";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_DIFFERENCE:
|
|
|
|
mMessage << "CompositionOp::OP_DIFFERENCE";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_EXCLUSION:
|
|
|
|
mMessage << "CompositionOp::OP_EXCLUSION";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_HUE:
|
|
|
|
mMessage << "CompositionOp::OP_HUE";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_SATURATION:
|
|
|
|
mMessage << "CompositionOp::OP_SATURATION";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_COLOR:
|
|
|
|
mMessage << "CompositionOp::OP_COLOR";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_LUMINOSITY:
|
|
|
|
mMessage << "CompositionOp::OP_LUMINOSITY";
|
|
|
|
break;
|
|
|
|
case CompositionOp::OP_COUNT:
|
|
|
|
mMessage << "CompositionOp::OP_COUNT";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mMessage << "Invalid CompositionOp (" << (int)aOp << ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2014-11-12 00:09:35 +03:00
|
|
|
Log& operator<<(SurfaceFormat aFormat) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
switch (aFormat) {
|
|
|
|
case SurfaceFormat::B8G8R8A8:
|
|
|
|
mMessage << "SurfaceFormat::B8G8R8A8";
|
|
|
|
break;
|
|
|
|
case SurfaceFormat::B8G8R8X8:
|
|
|
|
mMessage << "SurfaceFormat::B8G8R8X8";
|
|
|
|
break;
|
|
|
|
case SurfaceFormat::R8G8B8A8:
|
|
|
|
mMessage << "SurfaceFormat::R8G8B8A8";
|
|
|
|
break;
|
|
|
|
case SurfaceFormat::R8G8B8X8:
|
|
|
|
mMessage << "SurfaceFormat::R8G8B8X8";
|
|
|
|
break;
|
2015-10-23 09:01:31 +03:00
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
|
|
|
mMessage << "SurfaceFormat::R5G6B5_UINT16";
|
2014-11-12 00:09:35 +03:00
|
|
|
break;
|
|
|
|
case SurfaceFormat::A8:
|
|
|
|
mMessage << "SurfaceFormat::A8";
|
|
|
|
break;
|
|
|
|
case SurfaceFormat::YUV:
|
|
|
|
mMessage << "SurfaceFormat::YUV";
|
|
|
|
break;
|
|
|
|
case SurfaceFormat::UNKNOWN:
|
|
|
|
mMessage << "SurfaceFormat::UNKNOWN";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mMessage << "Invalid SurfaceFormat (" << (int)aFormat << ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log& operator<<(SurfaceType aType) {
|
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
switch (aType) {
|
|
|
|
case SurfaceType::DATA:
|
|
|
|
mMessage << "SurfaceType::DATA";
|
|
|
|
break;
|
|
|
|
case SurfaceType::D2D1_BITMAP:
|
|
|
|
mMessage << "SurfaceType::D2D1_BITMAP";
|
|
|
|
break;
|
|
|
|
case SurfaceType::D2D1_DRAWTARGET:
|
|
|
|
mMessage << "SurfaceType::D2D1_DRAWTARGET";
|
|
|
|
break;
|
|
|
|
case SurfaceType::CAIRO:
|
|
|
|
mMessage << "SurfaceType::CAIRO";
|
|
|
|
break;
|
|
|
|
case SurfaceType::CAIRO_IMAGE:
|
|
|
|
mMessage << "SurfaceType::CAIRO_IMAGE";
|
|
|
|
break;
|
|
|
|
case SurfaceType::COREGRAPHICS_IMAGE:
|
|
|
|
mMessage << "SurfaceType::COREGRAPHICS_IMAGE";
|
|
|
|
break;
|
|
|
|
case SurfaceType::COREGRAPHICS_CGCONTEXT:
|
|
|
|
mMessage << "SurfaceType::COREGRAPHICS_CGCONTEXT";
|
|
|
|
break;
|
|
|
|
case SurfaceType::SKIA:
|
|
|
|
mMessage << "SurfaceType::SKIA";
|
|
|
|
break;
|
|
|
|
case SurfaceType::DUAL_DT:
|
|
|
|
mMessage << "SurfaceType::DUAL_DT";
|
|
|
|
break;
|
|
|
|
case SurfaceType::D2D1_1_IMAGE:
|
|
|
|
mMessage << "SurfaceType::D2D1_1_IMAGE";
|
|
|
|
break;
|
|
|
|
case SurfaceType::RECORDING:
|
|
|
|
mMessage << "SurfaceType::RECORDING";
|
|
|
|
break;
|
|
|
|
case SurfaceType::TILED:
|
|
|
|
mMessage << "SurfaceType::TILED";
|
|
|
|
break;
|
2017-01-18 18:12:32 +03:00
|
|
|
case SurfaceType::DATA_SHARED:
|
|
|
|
mMessage << "SurfaceType::DATA_SHARED";
|
|
|
|
break;
|
2014-11-12 00:09:35 +03:00
|
|
|
default:
|
|
|
|
mMessage << "Invalid SurfaceType (" << (int)aType << ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-10-24 21:54:26 +04:00
|
|
|
inline bool LogIt() const { return mLogIt; }
|
|
|
|
inline bool NoNewline() const {
|
|
|
|
return mOptions & int(LogOptions::NoNewline);
|
|
|
|
}
|
|
|
|
inline bool AutoPrefix() const {
|
|
|
|
return mOptions & int(LogOptions::AutoPrefix);
|
|
|
|
}
|
2015-10-14 09:24:00 +03:00
|
|
|
inline bool ValidReason() const {
|
|
|
|
return (int)mReason > (int)LogReason::MustBeMoreThanThis &&
|
|
|
|
(int)mReason < (int)LogReason::MustBeLessThanThis;
|
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-04-27 21:44:13 +03:00
|
|
|
// We do not want this version to do any work, and stringstream can't be
|
|
|
|
// copied anyway. It does come in handy for the "Once" macro defined below.
|
2015-10-14 09:24:00 +03:00
|
|
|
MOZ_IMPLICIT Log(const Log& log) { Init(log.mOptions, false, log.mReason); }
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-10-24 21:54:26 +04:00
|
|
|
private:
|
2015-04-27 21:44:13 +03:00
|
|
|
// Initialization common to two constructors
|
2015-10-14 09:24:00 +03:00
|
|
|
void Init(int aOptions, bool aLogIt, LogReason aReason) {
|
2015-04-27 21:44:13 +03:00
|
|
|
mOptions = aOptions;
|
2015-10-14 09:24:00 +03:00
|
|
|
mReason = aReason;
|
2015-04-27 21:44:13 +03:00
|
|
|
mLogIt = aLogIt;
|
2015-10-14 09:24:00 +03:00
|
|
|
if (mLogIt) {
|
|
|
|
if (AutoPrefix()) {
|
|
|
|
if (mOptions & int(LogOptions::AssertOnCall)) {
|
|
|
|
mMessage << "[GFX" << L;
|
|
|
|
} else {
|
|
|
|
mMessage << "[GFX" << L << "-";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((mOptions & int(LogOptions::CrashAction)) && ValidReason()) {
|
|
|
|
mMessage << " " << (int)mReason;
|
2015-04-27 21:44:13 +03:00
|
|
|
}
|
2016-09-08 20:41:43 +03:00
|
|
|
if (AutoPrefix()) {
|
|
|
|
mMessage << "]: ";
|
|
|
|
}
|
2015-04-27 21:44:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
void WriteLog(const std::string& aString) {
|
2014-10-24 21:54:26 +04:00
|
|
|
if (MOZ_UNLIKELY(LogIt())) {
|
|
|
|
Logger::OutputMessage(aString, L, NoNewline());
|
2016-07-18 23:35:35 +03:00
|
|
|
// Assert if required. We don't have a three parameter MOZ_ASSERT
|
|
|
|
// so use the underlying functions instead (see bug 1281702):
|
|
|
|
#ifdef DEBUG
|
2014-12-18 01:54:04 +03:00
|
|
|
if (mOptions & int(LogOptions::AssertOnCall)) {
|
2016-07-18 23:35:35 +03:00
|
|
|
MOZ_ReportAssertionFailure(aString.c_str(), __FILE__, __LINE__);
|
|
|
|
MOZ_CRASH("GFX: An assert from the graphics logger");
|
2014-12-18 01:54:04 +03:00
|
|
|
}
|
2016-07-18 23:35:35 +03:00
|
|
|
#endif
|
2015-10-14 09:24:00 +03:00
|
|
|
if ((mOptions & int(LogOptions::CrashAction)) && ValidReason()) {
|
|
|
|
Logger::CrashAction(mReason);
|
|
|
|
}
|
2014-10-24 21:54:26 +04:00
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream mMessage;
|
2014-10-24 21:54:26 +04:00
|
|
|
int mOptions;
|
2015-10-14 09:24:00 +03:00
|
|
|
LogReason mReason;
|
2014-10-24 21:54:26 +04:00
|
|
|
bool mLogIt;
|
2011-06-24 21:41:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef Log<LOG_DEBUG> DebugLog;
|
|
|
|
typedef Log<LOG_WARNING> WarningLog;
|
2014-09-18 01:23:02 +04:00
|
|
|
typedef Log<LOG_CRITICAL, CriticalLogger> CriticalLog;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-04-27 21:44:13 +03:00
|
|
|
// Macro to glue names to get us less chance of name clashing.
|
|
|
|
#if defined GFX_LOGGING_GLUE1 || defined GFX_LOGGING_GLUE
|
|
|
|
# error "Clash of the macro GFX_LOGGING_GLUE1 or GFX_LOGGING_GLUE"
|
|
|
|
#endif
|
|
|
|
#define GFX_LOGGING_GLUE1(x, y) x##y
|
|
|
|
#define GFX_LOGGING_GLUE(x, y) GFX_LOGGING_GLUE1(x, y)
|
|
|
|
|
|
|
|
// This log goes into crash reports, use with care.
|
|
|
|
#define gfxCriticalError mozilla::gfx::CriticalLog
|
|
|
|
#define gfxCriticalErrorOnce \
|
|
|
|
static gfxCriticalError GFX_LOGGING_GLUE(sOnceAtLine, __LINE__) = \
|
|
|
|
gfxCriticalError
|
|
|
|
|
2015-06-18 13:59:00 +03:00
|
|
|
// This is a shortcut for errors we want logged in crash reports/about support
|
|
|
|
// but we do not want asserting. These are available in all builds, so it is
|
2018-11-28 03:54:56 +03:00
|
|
|
// not worth trying to do magic to avoid matching the syntax of
|
|
|
|
// gfxCriticalError.
|
2015-06-18 13:59:00 +03:00
|
|
|
// So, this one is used as
|
|
|
|
// gfxCriticalNote << "Something to report and not assert";
|
|
|
|
// while the critical error is
|
|
|
|
// gfxCriticalError() << "Something to report and assert";
|
|
|
|
#define gfxCriticalNote \
|
|
|
|
gfxCriticalError(gfxCriticalError::DefaultOptions(false))
|
2016-03-15 06:59:02 +03:00
|
|
|
#define gfxCriticalNoteOnce \
|
|
|
|
static gfxCriticalError GFX_LOGGING_GLUE(sOnceAtLine, __LINE__) = \
|
|
|
|
gfxCriticalNote
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-27 21:44:13 +03:00
|
|
|
// The "once" versions will only trigger the first time through. You can do
|
|
|
|
// this: gfxCriticalErrorOnce() << "This message only shows up once; instead of
|
|
|
|
// the usual: static bool firstTime = true; if (firstTime) {
|
|
|
|
// firstTime = false;
|
|
|
|
// gfxCriticalError() << "This message only shows up once;
|
|
|
|
// }
|
2015-10-23 15:08:00 +03:00
|
|
|
#if defined(DEBUG)
|
2014-11-18 18:51:39 +03:00
|
|
|
# define gfxDebug mozilla::gfx::DebugLog
|
2015-04-27 21:44:13 +03:00
|
|
|
# define gfxDebugOnce \
|
|
|
|
static gfxDebug GFX_LOGGING_GLUE(sOnceAtLine, __LINE__) = gfxDebug
|
2011-06-24 21:41:16 +04:00
|
|
|
#else
|
2014-11-18 18:51:39 +03:00
|
|
|
# define gfxDebug \
|
|
|
|
if (1) \
|
|
|
|
; \
|
|
|
|
else \
|
|
|
|
mozilla::gfx::NoLog
|
2015-04-27 21:44:13 +03:00
|
|
|
# define gfxDebugOnce \
|
|
|
|
if (1) \
|
|
|
|
; \
|
|
|
|
else \
|
|
|
|
mozilla::gfx::NoLog
|
2011-06-24 21:41:16 +04:00
|
|
|
#endif
|
2015-10-23 15:08:00 +03:00
|
|
|
|
|
|
|
// Have gfxWarning available (behind a runtime preference)
|
2014-11-18 18:51:39 +03:00
|
|
|
#define gfxWarning mozilla::gfx::WarningLog
|
2015-04-27 21:44:13 +03:00
|
|
|
#define gfxWarningOnce \
|
|
|
|
static gfxWarning GFX_LOGGING_GLUE(sOnceAtLine, __LINE__) = gfxWarning
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-10-14 09:24:00 +03:00
|
|
|
// In the debug build, this is equivalent to the default gfxCriticalError.
|
|
|
|
// In the non-debug build, on nightly and dev edition, it will MOZ_CRASH.
|
|
|
|
// On beta and release versions, it will telemetry count, but proceed.
|
|
|
|
//
|
|
|
|
// You should create a (new) enum in the LogReason and use it for the reason
|
|
|
|
// parameter to ensure uniqueness.
|
2015-11-09 13:28:00 +03:00
|
|
|
#define gfxDevCrash(reason) \
|
|
|
|
gfxCriticalError(int(gfx::LogOptions::AutoPrefix) | \
|
|
|
|
int(gfx::LogOptions::AssertOnCall) | \
|
|
|
|
int(gfx::LogOptions::CrashAction), \
|
|
|
|
(reason))
|
2015-10-14 09:24:00 +03:00
|
|
|
|
2014-08-27 19:57:43 +04:00
|
|
|
// See nsDebug.h and the NS_WARN_IF macro
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2014-12-12 23:35:48 +03:00
|
|
|
// For now, have MOZ2D_ERROR_IF available in debug and non-debug builds
|
|
|
|
inline bool MOZ2D_error_if_impl(bool aCondition, const char* aExpr,
|
|
|
|
const char* aFile, int32_t aLine) {
|
|
|
|
if (MOZ_UNLIKELY(aCondition)) {
|
|
|
|
gfxCriticalError() << aExpr << " at " << aFile << ":" << aLine;
|
|
|
|
}
|
|
|
|
return aCondition;
|
|
|
|
}
|
|
|
|
# define MOZ2D_ERROR_IF(condition) \
|
|
|
|
MOZ2D_error_if_impl(condition, #condition, __FILE__, __LINE__)
|
|
|
|
|
2014-08-27 19:57:43 +04:00
|
|
|
# ifdef DEBUG
|
|
|
|
inline bool MOZ2D_warn_if_impl(bool aCondition, const char* aExpr,
|
|
|
|
const char* aFile, int32_t aLine) {
|
|
|
|
if (MOZ_UNLIKELY(aCondition)) {
|
|
|
|
gfxWarning() << aExpr << " at " << aFile << ":" << aLine;
|
|
|
|
}
|
|
|
|
return aCondition;
|
|
|
|
}
|
|
|
|
# define MOZ2D_WARN_IF(condition) \
|
|
|
|
MOZ2D_warn_if_impl(condition, #condition, __FILE__, __LINE__)
|
|
|
|
# else
|
|
|
|
# define MOZ2D_WARN_IF(condition) (bool)(condition)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2014-01-22 05:14:47 +04:00
|
|
|
const int INDENT_PER_LEVEL = 2;
|
|
|
|
|
2019-03-30 09:41:48 +03:00
|
|
|
template <int Level = LOG_DEBUG>
|
2014-01-22 05:14:47 +04:00
|
|
|
class TreeLog {
|
|
|
|
public:
|
2014-08-06 01:58:40 +04:00
|
|
|
explicit TreeLog(const std::string& aPrefix = "")
|
2014-10-24 21:54:26 +04:00
|
|
|
: mLog(int(LogOptions::NoNewline)),
|
2014-01-22 05:14:47 +04:00
|
|
|
mPrefix(aPrefix),
|
|
|
|
mDepth(0),
|
2014-01-23 00:19:01 +04:00
|
|
|
mStartOfLine(true),
|
|
|
|
mConditionedOnPref(false),
|
2014-06-25 19:12:32 +04:00
|
|
|
mPrefFunction(nullptr) {}
|
2014-01-22 05:14:47 +04:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
TreeLog& operator<<(const T& aObject) {
|
2014-06-25 19:12:32 +04:00
|
|
|
if (mConditionedOnPref && !mPrefFunction()) {
|
2014-01-23 00:19:01 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2014-01-22 05:14:47 +04:00
|
|
|
if (mStartOfLine) {
|
2018-02-06 07:00:45 +03:00
|
|
|
if (!mPrefix.empty()) {
|
|
|
|
mLog << '[' << mPrefix << "] ";
|
|
|
|
}
|
|
|
|
mLog << std::string(mDepth * INDENT_PER_LEVEL, ' ');
|
2014-01-22 05:14:47 +04:00
|
|
|
mStartOfLine = false;
|
|
|
|
}
|
|
|
|
mLog << aObject;
|
|
|
|
if (EndsInNewline(aObject)) {
|
|
|
|
// Don't indent right here as the user may change the indent
|
|
|
|
// between now and the first output to the next line.
|
|
|
|
mLog.Flush();
|
|
|
|
mStartOfLine = true;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncreaseIndent() { ++mDepth; }
|
2016-09-22 19:31:26 +03:00
|
|
|
void DecreaseIndent() {
|
|
|
|
MOZ_ASSERT(mDepth > 0);
|
|
|
|
--mDepth;
|
|
|
|
}
|
2014-01-23 00:19:01 +04:00
|
|
|
|
2014-06-25 19:12:32 +04:00
|
|
|
void ConditionOnPrefFunction(bool (*aPrefFunction)()) {
|
2014-01-23 00:19:01 +04:00
|
|
|
mConditionedOnPref = true;
|
2014-06-25 19:12:32 +04:00
|
|
|
mPrefFunction = aPrefFunction;
|
2014-01-23 00:19:01 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-01-22 05:14:47 +04:00
|
|
|
private:
|
2019-03-18 21:42:04 +03:00
|
|
|
Log<Level> mLog;
|
2014-01-22 05:14:47 +04:00
|
|
|
std::string mPrefix;
|
|
|
|
uint32_t mDepth;
|
|
|
|
bool mStartOfLine;
|
2014-01-23 00:19:01 +04:00
|
|
|
bool mConditionedOnPref;
|
2014-06-25 19:12:32 +04:00
|
|
|
bool (*mPrefFunction)();
|
2014-01-22 05:14:47 +04:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static bool EndsInNewline(const T& aObject) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool EndsInNewline(const std::string& aString) {
|
|
|
|
return !aString.empty() && aString[aString.length() - 1] == '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool EndsInNewline(char aChar) { return aChar == '\n'; }
|
|
|
|
|
|
|
|
static bool EndsInNewline(const char* aString) {
|
|
|
|
return EndsInNewline(std::string(aString));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-30 09:41:48 +03:00
|
|
|
template <int Level = LOG_DEBUG>
|
2019-04-11 15:36:51 +03:00
|
|
|
class TreeAutoIndent final {
|
2014-01-22 05:14:47 +04:00
|
|
|
public:
|
2019-03-18 21:42:04 +03:00
|
|
|
explicit TreeAutoIndent(TreeLog<Level>& aTreeLog) : mTreeLog(aTreeLog) {
|
2014-01-22 05:14:47 +04:00
|
|
|
mTreeLog.IncreaseIndent();
|
|
|
|
}
|
2016-09-22 19:31:26 +03:00
|
|
|
|
|
|
|
TreeAutoIndent(const TreeAutoIndent& aTreeAutoIndent)
|
2017-06-05 19:42:28 +03:00
|
|
|
: mTreeLog(aTreeAutoIndent.mTreeLog) {
|
2016-09-22 19:31:26 +03:00
|
|
|
mTreeLog.IncreaseIndent();
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeAutoIndent& operator=(const TreeAutoIndent& aTreeAutoIndent) = delete;
|
|
|
|
|
2014-01-22 05:14:47 +04:00
|
|
|
~TreeAutoIndent() { mTreeLog.DecreaseIndent(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-01-22 05:14:47 +04:00
|
|
|
private:
|
2019-03-18 21:42:04 +03:00
|
|
|
TreeLog<Level>& mTreeLog;
|
2014-01-22 05:14:47 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_LOGGING_H_ */
|