Bug 1919083 - [ci] Enable os-integration variant for more suites, r=jmaher
[gecko.git] / gfx / thebes / gfxEnv.h
bloba75f26aa9795f5031d5ec0eb9877522d65511455
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_ENV_H
7 #define GFX_ENV_H
9 #include "mozilla/Attributes.h"
10 #include "nsDebug.h"
11 #include "prenv.h"
13 #include <sstream>
14 #include <string_view>
16 // To register the check for an environment variable existence (and not empty),
17 // add a line in this file using the DECL_GFX_ENV macro.
19 // For example this line in the .h:
20 // DECL_GFX_ENV(MOZ_GL_SPEW);
22 // means that you can call e.g.
23 // if (gfxEnv::MOZ_GL_SPEW()) { ... }
24 // if (gfxEnv::MOZ_GL_SPEW().as_str == "2") { ... }
25 // and that the value will be checked only once, first time we call it, then
26 // cached.
28 struct EnvVal {
29 std::string_view as_str;
31 static auto From(const char* const raw) {
32 auto ret = EnvVal{};
34 ret.as_str = std::string_view{};
35 // Empty string counts as missing.
36 if (raw) {
37 ret.as_str = raw;
40 return ret;
43 MOZ_IMPLICIT operator bool() const {
44 return !as_str.empty(); // Warning, this means ENV=0" -> true!
48 class gfxEnv final {
49 public:
50 gfxEnv() = delete;
52 static EnvVal Uncached(const char* name) {
53 const auto raw = PR_GetEnv(name);
54 const auto ret = EnvVal::From(raw);
55 if (ret && ret.as_str == "0") {
56 auto msg = std::stringstream{};
57 msg << name << "=" << ret.as_str << " -> true!";
58 NS_WARNING(msg.str().c_str());
60 return ret;
63 #define DECL_GFX_ENV(Name) \
64 static const EnvVal& Name() { \
65 static const auto cached = Uncached(#Name); \
66 return cached; \
69 // This is where DECL_GFX_ENV for each of the environment variables should go.
70 // We will keep these in an alphabetical order by the environment variable,
71 // to make it easier to see if a method accessing an entry already exists.
72 // Just insert yours in the list.
74 // OpenGL shader debugging in OGLShaderProgram, in DEBUG only
75 DECL_GFX_ENV(MOZ_DEBUG_SHADERS)
77 // Disabling the crash guard in DriverCrashGuard
78 DECL_GFX_ENV(MOZ_DISABLE_CRASH_GUARD)
79 DECL_GFX_ENV(MOZ_FORCE_CRASH_GUARD_NIGHTLY)
81 // We force present to work around some Windows bugs - disable that if this
82 // environment variable is set.
83 DECL_GFX_ENV(MOZ_DISABLE_FORCE_PRESENT)
85 // Together with paint dumping, only when MOZ_DUMP_PAINTING is defined.
86 // Dumping compositor textures is broken pretty badly. For example,
87 // on Linux it crashes TextureHost::GetAsSurface() returns null.
88 // Expect to have to fix things like this if you turn it on.
89 // Meanwhile, content-side texture dumping
90 // (conditioned on DebugDumpPainting()) is a good replacement.
91 DECL_GFX_ENV(MOZ_DUMP_COMPOSITOR_TEXTURES)
93 // Dump GLBlitHelper shader source text.
94 DECL_GFX_ENV(MOZ_DUMP_GLBLITHELPER)
96 // Paint dumping, only when MOZ_DUMP_PAINTING is defined.
97 DECL_GFX_ENV(MOZ_DUMP_PAINT)
98 DECL_GFX_ENV(MOZ_DUMP_PAINT_ITEMS)
99 DECL_GFX_ENV(MOZ_DUMP_PAINT_TO_FILE)
101 // Force gfxDevCrash to use MOZ_CRASH in Beta and Release
102 DECL_GFX_ENV(MOZ_GFX_CRASH_MOZ_CRASH)
103 // Force gfxDevCrash to use telemetry in Nightly and Aurora
104 DECL_GFX_ENV(MOZ_GFX_CRASH_TELEMETRY)
106 // Debugging in GLContext
107 DECL_GFX_ENV(MOZ_GL_DEBUG)
108 DECL_GFX_ENV(MOZ_GL_DEBUG_VERBOSE)
109 DECL_GFX_ENV(MOZ_GL_DEBUG_ABORT_ON_ERROR)
110 DECL_GFX_ENV(MOZ_GL_RELEASE_ASSERT_CONTEXT_OWNERSHIP)
111 DECL_GFX_ENV(MOZ_EGL_RELEASE_ASSERT_CONTEXT_OWNERSHIP)
113 // Count GL extensions
114 DECL_GFX_ENV(MOZ_GL_DUMP_EXTS)
116 // Very noisy GLContext and GLContextProviderEGL
117 DECL_GFX_ENV(MOZ_GL_SPEW)
119 // Do extra work before and after each GLX call in GLContextProviderGLX
120 DECL_GFX_ENV(MOZ_GLX_DEBUG)
122 // GL compositing on Windows
123 DECL_GFX_ENV(MOZ_LAYERS_PREFER_EGL)
125 // Offscreen GL context for main layer manager
126 DECL_GFX_ENV(MOZ_LAYERS_PREFER_OFFSCREEN)
128 // WebGL workarounds
129 DECL_GFX_ENV(MOZ_WEBGL_WORKAROUND_FIRST_AFFECTS_INSTANCE_ID)
131 // WARNING:
132 // For readability reasons, please make sure that you've added your new envvar
133 // to the list above in alphabetical order.
134 // Please do not just append it to the end of the list!
136 #undef DECL_GFX_ENV
139 #endif /* GFX_ENV_H */