gfxEnv.h (4348B)
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/. */ 5 6 #ifndef GFX_ENV_H 7 #define GFX_ENV_H 8 9 #include "mozilla/Attributes.h" 10 #include "nsDebug.h" 11 #include "prenv.h" 12 13 #include <sstream> 14 #include <string_view> 15 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. 18 // 19 // For example this line in the .h: 20 // DECL_GFX_ENV(MOZ_GL_SPEW); 21 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. 27 28 struct EnvVal { 29 std::string_view as_str; 30 31 static auto From(const char* const raw) { 32 auto ret = EnvVal{}; 33 34 ret.as_str = std::string_view{}; 35 // Empty string counts as missing. 36 if (raw) { 37 ret.as_str = raw; 38 } 39 40 return ret; 41 } 42 43 MOZ_IMPLICIT operator bool() const { 44 return !as_str.empty(); // Warning, this means ENV=0" -> true! 45 } 46 }; 47 48 class gfxEnv final { 49 public: 50 gfxEnv() = delete; 51 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()); 59 } 60 return ret; 61 } 62 63 #define DECL_GFX_ENV(Name) \ 64 static const EnvVal& Name() { \ 65 static const auto cached = Uncached(#Name); \ 66 return cached; \ 67 } 68 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. 73 74 // OpenGL shader debugging in OGLShaderProgram, in DEBUG only 75 DECL_GFX_ENV(MOZ_DEBUG_SHADERS) 76 77 // Disabling the crash guard in DriverCrashGuard 78 DECL_GFX_ENV(MOZ_DISABLE_CRASH_GUARD) 79 DECL_GFX_ENV(MOZ_FORCE_CRASH_GUARD_NIGHTLY) 80 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) 84 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) 92 93 // Dump GLBlitHelper shader source text. 94 DECL_GFX_ENV(MOZ_DUMP_GLBLITHELPER) 95 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) 100 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) 105 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) 112 113 // Count GL extensions 114 DECL_GFX_ENV(MOZ_GL_DUMP_EXTS) 115 116 // Very noisy GLContext and GLContextProviderEGL 117 DECL_GFX_ENV(MOZ_GL_SPEW) 118 119 // Do extra work before and after each GLX call in GLContextProviderGLX 120 DECL_GFX_ENV(MOZ_GLX_DEBUG) 121 122 // GL compositing on Windows 123 DECL_GFX_ENV(MOZ_LAYERS_PREFER_EGL) 124 125 // Offscreen GL context for main layer manager 126 DECL_GFX_ENV(MOZ_LAYERS_PREFER_OFFSCREEN) 127 128 // WebGL workarounds 129 DECL_GFX_ENV(MOZ_WEBGL_WORKAROUND_FIRST_AFFECTS_INSTANCE_ID) 130 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! 135 136 #undef DECL_GFX_ENV 137 }; 138 139 #endif /* GFX_ENV_H */