Bug 1778855 - Use e.g. gfxEnv::MOZ_GL_DEBUG() instead of gfxEnv::GlDebug(). r=gfx-reviewers,jrmuizel

Differential Revision: https://phabricator.services.mozilla.com/D151547
This commit is contained in:
Kelsey Gilbert 2022-07-11 23:59:53 +00:00
Родитель 10d601d798
Коммит 925ea31507
12 изменённых файлов: 107 добавлений и 83 удалений

Просмотреть файл

@ -244,15 +244,15 @@ static bool ParseVersion(const std::string& versionStr,
uint8_t GLContext::ChooseDebugFlags(const CreateContextFlags createFlags) {
uint8_t debugFlags = 0;
#ifdef MOZ_GL_DEBUG
if (gfxEnv::GlDebug()) {
#ifdef MOZ_GL_DEBUG_BUILD
if (gfxEnv::MOZ_GL_DEBUG()) {
debugFlags |= GLContext::DebugFlagEnabled;
}
// Enables extra verbose output, informing of the start and finish of every GL
// call. Useful e.g. to record information to investigate graphics system
// crashes/lockups
if (gfxEnv::GlDebugVerbose()) {
if (gfxEnv::MOZ_GL_DEBUG_VERBOSE()) {
debugFlags |= GLContext::DebugFlagTrace;
}
@ -263,12 +263,8 @@ uint8_t GLContext::ChooseDebugFlags(const CreateContextFlags createFlags) {
if (createFlags & CreateContextFlags::NO_VALIDATION) {
abortOnError = true;
const auto fnStringsMatch = [](const char* a, const char* b) {
return strcmp(a, b) == 0;
};
const char* envAbortOnError = PR_GetEnv("MOZ_GL_DEBUG_ABORT_ON_ERROR");
if (envAbortOnError && fnStringsMatch(envAbortOnError, "0")) {
const auto& env = gfxEnv::MOZ_GL_DEBUG_ABORT_ON_ERROR();
if (env.as_str == "0") {
abortOnError = false;
}
}
@ -298,7 +294,7 @@ GLContext::~GLContext() {
NS_ASSERTION(
IsDestroyed(),
"GLContext implementation must call MarkDestroyed in destructor!");
#ifdef MOZ_GL_DEBUG
#ifdef MOZ_GL_DEBUG_BUILD
if (mSharedContext) {
GLContext* tip = mSharedContext;
while (tip->mSharedContext) tip = tip->mSharedContext;
@ -1866,7 +1862,7 @@ bool GLContext::AssembleOffscreenFBs(const GLuint colorMSRB,
if (!IsFramebufferComplete(drawFB, &status)) {
NS_WARNING("DrawFBO: Incomplete");
#ifdef MOZ_GL_DEBUG
#ifdef MOZ_GL_DEBUG_BUILD
if (ShouldSpew()) {
printf_stderr("Framebuffer status: %X\n", status);
}
@ -1876,7 +1872,7 @@ bool GLContext::AssembleOffscreenFBs(const GLuint colorMSRB,
if (!IsFramebufferComplete(readFB, &status)) {
NS_WARNING("ReadFBO: Incomplete");
#ifdef MOZ_GL_DEBUG
#ifdef MOZ_GL_DEBUG_BUILD
if (ShouldSpew()) {
printf_stderr("Framebuffer status: %X\n", status);
}
@ -1915,7 +1911,7 @@ void GLContext::MarkDestroyed() {
// -
#ifdef MOZ_GL_DEBUG
#ifdef MOZ_GL_DEBUG_BUILD
/* static */
void GLContext::AssertNotPassingStackBufferToTheGL(const void* ptr) {
int somethingOnTheStack;
@ -2093,7 +2089,7 @@ void GLContext::ReportOutstandingNames() {
ReportArrayContents("Outstanding Renderbuffers", mTrackedRenderbuffers);
}
#endif /* DEBUG */
#endif // ifdef MOZ_GL_DEBUG_BUILD
bool GLContext::IsOffscreenSizeAllowed(const IntSize& aSize) const {
int32_t biggerDimension = std::max(aSize.width, aSize.height);
@ -2131,7 +2127,7 @@ void GLContext::FlushIfHeavyGLCallsSinceLastFlush() {
}
/*static*/
bool GLContext::ShouldDumpExts() { return gfxEnv::GlDumpExtensions(); }
bool GLContext::ShouldDumpExts() { return gfxEnv::MOZ_GL_DUMP_EXTS(); }
bool DoesStringMatch(const char* aString, const char* aWantedString) {
if (!aString || !aWantedString) return false;
@ -2152,7 +2148,7 @@ bool DoesStringMatch(const char* aString, const char* aWantedString) {
}
/*static*/
bool GLContext::ShouldSpew() { return gfxEnv::GlSpew(); }
bool GLContext::ShouldSpew() { return gfxEnv::MOZ_GL_SPEW(); }
void SplitByChar(const nsACString& str, const char delim,
std::vector<nsCString>* const out) {

Просмотреть файл

@ -21,10 +21,10 @@
# undef GetClassName
#endif
// Define MOZ_GL_DEBUG unconditionally to enable GL debugging in opt
// Define MOZ_GL_DEBUG_BUILD unconditionally to enable GL debugging in opt
// builds.
#ifdef DEBUG
# define MOZ_GL_DEBUG 1
# define MOZ_GL_DEBUG_BUILD 1
#endif
#include "mozilla/IntegerRange.h"
@ -625,7 +625,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
const GLvoid* userParam);
// -----------------------------------------------------------------------------
// MOZ_GL_DEBUG implementation
// Debugging implementation
private:
#ifndef MOZ_FUNCTION_NAME
# ifdef __GNUC__
@ -693,7 +693,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
static void AssertNotPassingStackBufferToTheGL(const void* ptr);
#ifdef MOZ_GL_DEBUG
#ifdef MOZ_GL_DEBUG_BUILD
# define TRACKING_CONTEXT(a) \
do { \
@ -714,7 +714,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
} \
} while (0)
#else // ifdef MOZ_GL_DEBUG
#else // ifdef MOZ_GL_DEBUG_BUILD
# define TRACKING_CONTEXT(a) \
do { \
@ -726,7 +726,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
do { \
} while (0)
#endif // ifdef MOZ_GL_DEBUG
#endif // ifdef MOZ_GL_DEBUG_BUILD
// Do whatever setup is necessary to draw to our offscreen FBO, if it's
// bound.
@ -3681,7 +3681,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
auto MaxRenderbufferSize() const { return uint32_t(mMaxRenderbufferSize); }
auto MaxTexOrRbSize() const { return mMaxTexOrRbSize; }
#ifdef MOZ_GL_DEBUG
#ifdef MOZ_GL_DEBUG_BUILD
void CreatedProgram(GLContext* aOrigin, GLuint aName);
void CreatedShader(GLContext* aOrigin, GLuint aName);
void CreatedBuffers(GLContext* aOrigin, GLsizei aCount, GLuint* aNames);

Просмотреть файл

@ -100,7 +100,7 @@ bool GLXLibrary::EnsureInitialized(Display* aDisplay) {
reporter.SetSuccessful();
}
if (gfxEnv::GlxDebug()) {
if (gfxEnv::MOZ_GLX_DEBUG()) {
mDebug = true;
}

Просмотреть файл

@ -587,7 +587,7 @@ bool GLLibraryEGL::Init(nsACString* const out_failureId) {
const SymbolLoader pfnLoader(mSymbols.fGetProcAddress);
const auto fnLoadSymbols = [&](const SymLoadStruct* symbols) {
const bool shouldWarn = gfxEnv::GlSpew();
const bool shouldWarn = gfxEnv::MOZ_GL_SPEW();
if (pfnLoader.LoadSymbols(symbols, shouldWarn)) return true;
ClearSymbols(symbols);
@ -1016,7 +1016,7 @@ void EglDisplay::DumpEGLConfigs() const {
}
static bool ShouldTrace() {
static bool ret = gfxEnv::GlDebugVerbose();
static bool ret = gfxEnv::MOZ_GL_DEBUG_VERBOSE();
return ret;
}

Просмотреть файл

@ -200,7 +200,7 @@ already_AddRefed<mozilla::gl::GLContext> CompositorOGL::CreateContext() {
}
#ifdef XP_WIN
if (gfxEnv::LayersPreferEGL()) {
if (gfxEnv::MOZ_LAYERS_PREFER_EGL()) {
printf_stderr("Trying GL layers...\n");
context = gl::GLContextProviderEGL::CreateForCompositorWidget(
mWidget, /* aHardwareWebRender */ false, /* aForceAccelerated */ false);
@ -208,7 +208,7 @@ already_AddRefed<mozilla::gl::GLContext> CompositorOGL::CreateContext() {
#endif
// Allow to create offscreen GL context for main Layer Manager
if (!context && gfxEnv::LayersPreferOffscreen()) {
if (!context && gfxEnv::MOZ_LAYERS_PREFER_OFFSCREEN()) {
nsCString discardFailureId;
context = GLContextProvider::CreateHeadless(
{CreateContextFlags::REQUIRE_COMPAT_PROFILE}, &discardFailureId);
@ -1438,7 +1438,7 @@ void CompositorOGL::EndFrame() {
AUTO_PROFILER_LABEL("CompositorOGL::EndFrame", GRAPHICS);
#ifdef MOZ_DUMP_PAINTING
if (gfxEnv::DumpCompositorTextures()) {
if (gfxEnv::MOZ_DISABLE_FORCE_PRESENT()) {
LayoutDeviceIntSize size;
if (mUseExternalSurfaceSize) {
size = LayoutDeviceIntSize(mSurfaceSize.width, mSurfaceSize.height);

Просмотреть файл

@ -899,7 +899,7 @@ GLint ShaderProgramOGL::CreateShader(GLenum aShaderType,
*/
if (!success
#ifdef DEBUG
|| (len > 10 && gfxEnv::DebugShaders())
|| (len > 10 && gfxEnv::MOZ_DEBUG_SHADERS())
#endif
) {
nsAutoCString log;
@ -954,7 +954,7 @@ bool ShaderProgramOGL::CreateProgram(const char* aVertexShaderString,
*/
if (!success
#ifdef DEBUG
|| (len > 10 && gfxEnv::DebugShaders())
|| (len > 10 && gfxEnv::MOZ_DEBUG_SHADERS())
#endif
) {
nsAutoCString log;

Просмотреть файл

@ -74,11 +74,11 @@ static inline bool AreCrashGuardsEnabled(CrashGuardType aType) {
// We handle the WMFVPXVideo crash guard differently to the other and always
// enable it as it completely breaks playback and there's no way around it.
if (aType != CrashGuardType::WMFVPXVideo) {
return gfxEnv::ForceCrashGuardNightly();
return gfxEnv::MOZ_FORCE_CRASH_GUARD_NIGHTLY();
}
#endif
// Check to see if all guards have been disabled through the environment.
return !gfxEnv::DisableCrashGuard();
return !gfxEnv::MOZ_DISABLE_CRASH_GUARD();
}
void DriverCrashGuard::Initialize() {

Просмотреть файл

@ -6,41 +6,81 @@
#ifndef GFX_ENV_H
#define GFX_ENV_H
#include "mozilla/Attributes.h"
#include "nsDebug.h"
#include "prenv.h"
#include <sstream>
#include <string_view>
// To register the check for an environment variable existence (and not empty),
// add a line in this file using the DECL_GFX_ENV macro.
//
// For example this line in the .h:
// DECL_GFX_ENV("MOZ_DISABLE_CONTEXT_SHARING_GLX",DisableContextSharingGLX);
// means that you can call
// bool var = gfxEnv::DisableContextSharingGLX();
// DECL_GFX_ENV(MOZ_GL_SPEW);
// means that you can call e.g.
// if (gfxEnv::MOZ_GL_SPEW()) { ... }
// if (gfxEnv::MOZ_GL_SPEW().as_str == "2") { ... }
// and that the value will be checked only once, first time we call it, then
// cached.
#define DECL_GFX_ENV(Env, Name) \
static bool Name() { \
static bool isSet = IsEnvSet(Env); \
return isSet; \
struct EnvVal {
std::string_view as_str;
static auto From(const char* const raw) {
auto ret = EnvVal{};
ret.as_str = std::string_view{};
// Empty string counts as missing.
if (raw) {
ret.as_str = raw;
}
return ret;
}
MOZ_IMPLICIT operator bool() const {
return !as_str.empty(); // Warning, this means ENV=0" -> true!
}
};
class gfxEnv final {
public:
gfxEnv() = delete;
static EnvVal Uncached(const char* name) {
const auto raw = PR_GetEnv(name);
const auto ret = EnvVal::From(raw);
if (ret && ret.as_str == "0") {
auto msg = std::stringstream{};
msg << name << "=" << ret.as_str << " -> true!";
NS_WARNING(msg.str().c_str());
}
return ret;
}
#define DECL_GFX_ENV(Name) \
static const EnvVal& Name() { \
static const auto cached = Uncached(#Name); \
return cached; \
}
// This is where DECL_GFX_ENV for each of the environment variables should go.
// We will keep these in an alphabetical order by the environment variable,
// to make it easier to see if a method accessing an entry already exists.
// Just insert yours in the list.
// OpenGL shader debugging in OGLShaderProgram, in DEBUG only
DECL_GFX_ENV("MOZ_DEBUG_SHADERS", DebugShaders);
DECL_GFX_ENV(MOZ_DEBUG_SHADERS)
// Disabling the crash guard in DriverCrashGuard
DECL_GFX_ENV("MOZ_DISABLE_CRASH_GUARD", DisableCrashGuard);
DECL_GFX_ENV("MOZ_FORCE_CRASH_GUARD_NIGHTLY", ForceCrashGuardNightly);
DECL_GFX_ENV(MOZ_DISABLE_CRASH_GUARD)
DECL_GFX_ENV(MOZ_FORCE_CRASH_GUARD_NIGHTLY)
// We force present to work around some Windows bugs - disable that if this
// environment variable is set.
DECL_GFX_ENV("MOZ_DISABLE_FORCE_PRESENT", DisableForcePresent);
DECL_GFX_ENV(MOZ_DISABLE_FORCE_PRESENT)
// Together with paint dumping, only when MOZ_DUMP_PAINTING is defined.
// Dumping compositor textures is broken pretty badly. For example,
@ -48,56 +88,44 @@ class gfxEnv final {
// Expect to have to fix things like this if you turn it on.
// Meanwhile, content-side texture dumping
// (conditioned on DebugDumpPainting()) is a good replacement.
DECL_GFX_ENV("MOZ_DUMP_COMPOSITOR_TEXTURES", DumpCompositorTextures);
DECL_GFX_ENV(MOZ_DUMP_COMPOSITOR_TEXTURES)
// Paint dumping, only when MOZ_DUMP_PAINTING is defined.
DECL_GFX_ENV("MOZ_DUMP_PAINT", DumpPaint);
DECL_GFX_ENV("MOZ_DUMP_PAINT_ITEMS", DumpPaintItems);
DECL_GFX_ENV("MOZ_DUMP_PAINT_TO_FILE", DumpPaintToFile);
DECL_GFX_ENV(MOZ_DUMP_PAINT)
DECL_GFX_ENV(MOZ_DUMP_PAINT_ITEMS)
DECL_GFX_ENV(MOZ_DUMP_PAINT_TO_FILE)
// Force gfxDevCrash to use MOZ_CRASH in Beta and Release
DECL_GFX_ENV("MOZ_GFX_CRASH_MOZ_CRASH", GfxDevCrashMozCrash);
DECL_GFX_ENV(MOZ_GFX_CRASH_MOZ_CRASH)
// Force gfxDevCrash to use telemetry in Nightly and Aurora
DECL_GFX_ENV("MOZ_GFX_CRASH_TELEMETRY", GfxDevCrashTelemetry);
DECL_GFX_ENV(MOZ_GFX_CRASH_TELEMETRY)
// Debugging in GLContext
DECL_GFX_ENV("MOZ_GL_DEBUG", GlDebug);
DECL_GFX_ENV("MOZ_GL_DEBUG_VERBOSE", GlDebugVerbose);
DECL_GFX_ENV(MOZ_GL_DEBUG)
DECL_GFX_ENV(MOZ_GL_DEBUG_VERBOSE)
DECL_GFX_ENV(MOZ_GL_DEBUG_ABORT_ON_ERROR)
// Count GL extensions
DECL_GFX_ENV("MOZ_GL_DUMP_EXTS", GlDumpExtensions);
DECL_GFX_ENV(MOZ_GL_DUMP_EXTS)
// Very noisy GLContext and GLContextProviderEGL
DECL_GFX_ENV("MOZ_GL_SPEW", GlSpew);
DECL_GFX_ENV(MOZ_GL_SPEW)
// Do extra work before and after each GLX call in GLContextProviderGLX
DECL_GFX_ENV("MOZ_GLX_DEBUG", GlxDebug);
DECL_GFX_ENV(MOZ_GLX_DEBUG)
// GL compositing on Windows
DECL_GFX_ENV("MOZ_LAYERS_PREFER_EGL", LayersPreferEGL);
DECL_GFX_ENV(MOZ_LAYERS_PREFER_EGL)
// Offscreen GL context for main layer manager
DECL_GFX_ENV("MOZ_LAYERS_PREFER_OFFSCREEN", LayersPreferOffscreen);
DECL_GFX_ENV(MOZ_LAYERS_PREFER_OFFSCREEN)
// WARNING:
// For readability reasons, please make sure that you've added your new envvar
// to the list above in alphabetical order.
// Please do not just append it to the end of the list!
private:
// Helper function, can be re-used in the other macros
static bool IsEnvSet(const char* aName) {
const char* val = PR_GetEnv(aName);
return (val != 0 && *val != '\0');
}
gfxEnv() = default;
~gfxEnv() = default;
gfxEnv(const gfxEnv&) = delete;
gfxEnv& operator=(const gfxEnv&) = delete;
#undef DECL_GFX_ENV
};
#undef DECL_GFX_ENV
#endif /* GFX_ENV_H */

Просмотреть файл

@ -374,11 +374,11 @@ void CrashStatsLogForwarder::CrashAction(LogReason aReason) {
#ifndef RELEASE_OR_BETA
// Non-release builds crash by default, but will use telemetry
// if this environment variable is present.
static bool useTelemetry = gfxEnv::GfxDevCrashTelemetry();
static bool useTelemetry = gfxEnv::MOZ_GFX_CRASH_TELEMETRY();
#else
// Release builds use telemetry by default, but will crash instead
// if this environment variable is present.
static bool useTelemetry = !gfxEnv::GfxDevCrashMozCrash();
static bool useTelemetry = !gfxEnv::MOZ_GFX_CRASH_MOZ_CRASH();
#endif
if (useTelemetry) {

Просмотреть файл

@ -2997,7 +2997,7 @@ static void DumpBeforePaintDisplayList(UniquePtr<std::stringstream>& aStream,
nsDisplayList* aList,
const nsRect& aVisibleRect) {
#ifdef MOZ_DUMP_PAINTING
if (gfxEnv::DumpPaintToFile()) {
if (gfxEnv::MOZ_DUMP_PAINT_TO_FILE()) {
nsCString string("dump-");
// Include the process ID in the dump file name, to make sure that in an
// e10s setup different processes don't clobber each other's dump files.
@ -3011,7 +3011,7 @@ static void DumpBeforePaintDisplayList(UniquePtr<std::stringstream>& aStream,
} else {
gfxUtils::sDumpPaintFile = stderr;
}
if (gfxEnv::DumpPaintToFile()) {
if (gfxEnv::MOZ_DUMP_PAINT_TO_FILE()) {
*aStream << "<html><head><script>\n"
"var array = {};\n"
"function ViewImage(index) { \n"
@ -3030,9 +3030,9 @@ static void DumpBeforePaintDisplayList(UniquePtr<std::stringstream>& aStream,
aVisibleRect.height)
.get();
nsIFrame::PrintDisplayList(aBuilder, *aList, *aStream,
gfxEnv::DumpPaintToFile());
gfxEnv::MOZ_DUMP_PAINT_TO_FILE());
if (gfxEnv::DumpPaint() || gfxEnv::DumpPaintItems()) {
if (gfxEnv::MOZ_DUMP_PAINT() || gfxEnv::MOZ_DUMP_PAINT_ITEMS()) {
// Flush stream now to avoid reordering dump output relative to
// messages dumped by PaintRoot below.
fprint_stderr(gfxUtils::sDumpPaintFile, *aStream);
@ -3045,15 +3045,15 @@ static void DumpAfterPaintDisplayList(UniquePtr<std::stringstream>& aStream,
nsDisplayList* aList) {
*aStream << "Painting --- after optimization:\n";
nsIFrame::PrintDisplayList(aBuilder, *aList, *aStream,
gfxEnv::DumpPaintToFile());
gfxEnv::MOZ_DUMP_PAINT_TO_FILE());
fprint_stderr(gfxUtils::sDumpPaintFile, *aStream);
#ifdef MOZ_DUMP_PAINTING
if (gfxEnv::DumpPaintToFile()) {
if (gfxEnv::MOZ_DUMP_PAINT_TO_FILE()) {
*aStream << "</body></html>";
}
if (gfxEnv::DumpPaintToFile()) {
if (gfxEnv::MOZ_DUMP_PAINT_TO_FILE()) {
fclose(gfxUtils::sDumpPaintFile);
}
#endif
@ -3414,7 +3414,7 @@ void nsLayoutUtils::PaintFrame(gfxContext* aRenderingContext, nsIFrame* aFrame,
std::move(dlTimerId));
bool consoleNeedsDisplayList =
(gfxUtils::DumpDisplayList() || gfxEnv::DumpPaint()) &&
(gfxUtils::DumpDisplayList() || gfxEnv::MOZ_DUMP_PAINT()) &&
builder->IsInActiveDocShell();
#ifdef MOZ_DUMP_PAINTING
FILE* savedDumpFile = gfxUtils::sDumpPaintFile;

Просмотреть файл

@ -5395,7 +5395,7 @@ bool nsWindow::ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
}
// There is a case that rendered result is not kept. Bug 1237617
if (wParam == TRUE && !gfxEnv::DisableForcePresent() &&
if (wParam == TRUE && !gfxEnv::MOZ_DISABLE_FORCE_PRESENT() &&
gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) {
NS_DispatchToMainThread(NewRunnableMethod(
"nsWindow::ForcePresent", this, &nsWindow::ForcePresent));

Просмотреть файл

@ -325,7 +325,7 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) {
} break;
case LayersBackend::LAYERS_WR: {
result = listener->PaintWindow(this, region);
if (!gfxEnv::DisableForcePresent() &&
if (!gfxEnv::MOZ_DISABLE_FORCE_PRESENT() &&
gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) {
nsCOMPtr<nsIRunnable> event = NewRunnableMethod(
"nsWindow::ForcePresent", this, &nsWindow::ForcePresent);