1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_gfx_config_gfxVars_h
7 #define mozilla_gfx_config_gfxVars_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/StaticPtr.h"
12 #include "mozilla/gfx/GraphicsMessages.h"
13 #include "mozilla/gfx/Point.h"
14 #include "mozilla/gfx/Types.h"
16 #include "nsXULAppAPI.h"
18 namespace mozilla::gfx
{
22 // Generator for graphics vars.
23 #define GFX_VARS_LIST(_) \
24 /* C++ Name, Data Type, Default Value */ \
25 _(AllowEglRbab, bool, true) \
26 _(AllowWebgl2, bool, true) \
27 _(AllowWebglAccelAngle, bool, true) \
28 _(AllowWebglOop, bool, true) \
29 _(BrowserTabsRemoteAutostart, bool, false) \
30 _(ContentBackend, BackendType, BackendType::NONE) \
31 _(SoftwareBackend, BackendType, BackendType::NONE) \
32 _(OffscreenFormat, gfxImageFormat, \
33 mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) \
34 _(RequiresAcceleratedGLContextForCompositorOGL, bool, false) \
35 _(CanUseHardwareVideoDecoding, bool, false) \
36 _(DXInterop2Blocked, bool, false) \
37 _(DXNV12Blocked, bool, false) \
38 _(DXP010Blocked, bool, false) \
39 _(DXP016Blocked, bool, false) \
40 _(UseWebRenderANGLE, bool, false) \
41 _(UseWebRenderFlipSequentialWin, bool, false) \
42 _(UseWebRenderDCompWin, bool, false) \
43 _(UseWebRenderDCompVideoHwOverlayWin, bool, false) \
44 _(UseWebRenderDCompVideoSwOverlayWin, bool, false) \
45 _(UseWebRenderTripleBufferingWin, bool, false) \
46 _(UseWebRenderCompositor, bool, false) \
47 _(UseWebRenderProgramBinaryDisk, bool, false) \
48 _(UseWebRenderOptimizedShaders, bool, false) \
49 _(UseWebRenderScissoredCacheClears, bool, true) \
50 _(WebRenderProfilerUI, nsCString, nsCString()) \
51 _(WebglAllowCoreProfile, bool, true) \
52 _(WebglAllowWindowsNativeGl, bool, false) \
53 _(WebRenderMaxPartialPresentRects, int32_t, 0) \
54 _(WebRenderDebugFlags, int32_t, 0) \
55 _(WebRenderBoolParameters, int32_t, 0) \
56 _(WebRenderBatchingLookback, int32_t, 10) \
57 _(WebRenderBlobTileSize, int32_t, 256) \
58 _(WebRenderBatchedUploadThreshold, int32_t, 512 * 512) \
59 _(UseSoftwareWebRender, bool, false) \
60 _(AllowSoftwareWebRenderD3D11, bool, false) \
61 _(ScreenDepth, int32_t, 0) \
62 _(GREDirectory, nsString, nsString()) \
63 _(ProfDirectory, nsString, nsString()) \
64 _(AllowD3D11KeyedMutex, bool, false) \
65 _(SwapIntervalGLX, bool, false) \
66 _(SwapIntervalEGL, bool, false) \
67 _(SystemTextQuality, int32_t, 5 /* CLEARTYPE_QUALITY */) \
68 _(SystemTextClearTypeLevel, float, 1.0f) \
69 _(SystemTextEnhancedContrast, float, 1.0f) \
70 _(SystemTextGamma, float, 2.2f) \
71 _(SystemTextPixelGeometry, int32_t, 1 /* pixel geometry RGB */) \
72 _(SystemTextRenderingMode, int32_t, 0) \
73 _(SystemGDIGamma, float, 1.4f) \
74 _(LayersWindowRecordingPath, nsCString, nsCString()) \
75 _(RemoteCanvasEnabled, bool, false) \
76 _(UseDoubleBufferingWithCompositor, bool, false) \
77 _(UseGLSwizzle, bool, true) \
78 _(ForceSubpixelAAWherePossible, bool, false) \
79 _(FxREmbedded, bool, false) \
80 _(UseAHardwareBufferSharedSurfaceWebglOop, bool, false) \
81 _(UseEGL, bool, false) \
82 _(DrmRenderDevice, nsCString, nsCString()) \
83 _(UseDMABuf, bool, false) \
84 _(DMABufModifiersXRGB, ArrayOfuint64_t, nsTArray<uint64_t>()) \
85 _(DMABufModifiersARGB, ArrayOfuint64_t, nsTArray<uint64_t>()) \
86 _(CodecSupportInfo, nsCString, nsCString()) \
87 _(WebRenderRequiresHardwareDriver, bool, false) \
88 _(SupportsThreadsafeGL, bool, false) \
89 _(AllowWebGPU, bool, false) \
90 _(UseVP8HwDecode, bool, false) \
91 _(UseVP9HwDecode, bool, false) \
92 _(UseAV1HwDecode, bool, false) \
93 _(UseH264HwDecode, bool, false) \
94 _(HwDecodedVideoZeroCopy, bool, false) \
95 _(UseDMABufSurfaceExport, bool, true) \
96 _(ReuseDecoderDevice, bool, false) \
97 _(UseCanvasRenderThread, bool, false) \
98 _(AllowBackdropFilter, bool, true) \
99 _(WebglOopAsyncPresentForceSync, bool, true) \
100 _(UseAcceleratedCanvas2D, bool, false) \
101 _(AllowSoftwareWebRenderOGL, bool, false)
103 /* Add new entries above this line. */
105 // Some graphics settings are computed on the UI process and must be
106 // communicated to content and GPU processes. gfxVars helps facilitate
107 // this. Its function is similar to StaticPrefs, except rather than hold
108 // user preferences, it holds dynamically computed values.
110 // Each variable in GFX_VARS_LIST exposes the following static methods:
112 // const DataType& CxxName();
113 // void SetCxxName(const DataType& aValue);
115 // Note that the setter may only be called in the UI process; a gfxVar must be
116 // a variable that is determined in the UI process and pushed to child
118 class gfxVars final
{
120 // These values will be used during the Initialize() call if set. Any
121 // updates that come before initialization will get added to this array.
122 static void SetValuesForInitialize(
123 const nsTArray
<GfxVarUpdate
>& aInitUpdates
);
125 static void Initialize();
126 static void Shutdown();
128 static void ApplyUpdate(const GfxVarUpdate
& aUpdate
);
129 static void AddReceiver(gfxVarReceiver
* aReceiver
);
130 static void RemoveReceiver(gfxVarReceiver
* aReceiver
);
132 // Return a list of updates for all variables with non-default values.
133 static nsTArray
<GfxVarUpdate
> FetchNonDefaultVars();
136 template <typename U
>
137 static U
CloneVarValue(const U
& aValue
) {
141 template <typename U
>
142 static nsTArray
<U
> CloneVarValue(const nsTArray
<U
>& aValue
) {
143 return aValue
.Clone();
147 // Each variable must expose Set and Get methods for IPDL.
151 virtual void SetValue(const GfxVarValue
& aValue
) = 0;
152 virtual void GetValue(GfxVarValue
* aOutValue
) = 0;
153 virtual bool HasDefaultValue() const = 0;
154 size_t Index() const { return mIndex
; }
160 // Whether the gfxVars singleton instance has been initialized. Most gfx code
161 // doesn't need to check this, but code that can potentially run before
162 // gfxPlatform initialization can use this to check whether gfxVars are
164 static bool IsInitialized() { return sInstance
!= nullptr; }
167 static StaticAutoPtr
<gfxVars
> sInstance
;
168 static StaticAutoPtr
<nsTArray
<VarBase
*>> sVarList
;
170 template <typename T
, T
Default(), T
GetFrom(const GfxVarValue
& aValue
)>
171 class VarImpl final
: public VarBase
{
173 VarImpl() : mValue(Default()) {}
174 void SetValue(const GfxVarValue
& aValue
) override
{
175 mValue
= GetFrom(aValue
);
180 void GetValue(GfxVarValue
* aOutValue
) override
{
181 *aOutValue
= GfxVarValue(mValue
);
183 bool HasDefaultValue() const override
{ return mValue
== Default(); }
184 const T
& Get() const { return mValue
; }
186 // Return true if the value changed, false otherwise.
187 bool Set(const T
& aValue
) {
188 MOZ_ASSERT(XRE_IsParentProcess());
189 if (mValue
== aValue
) {
192 mValue
= CloneVarValue(aValue
);
199 void SetListener(const std::function
<void()>& aListener
) {
200 mListener
= aListener
;
205 std::function
<void()> mListener
;
208 #define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
210 static DataType Get##CxxName##Default() { return DefaultValue; } \
211 static DataType Get##CxxName##From(const GfxVarValue& aValue) { \
212 return CloneVarValue(aValue.get_##DataType()); \
214 VarImpl<DataType, Get##CxxName##Default, Get##CxxName##From> mVar##CxxName; \
217 static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
218 static DataType Get##CxxName##OrDefault() { \
220 return DefaultValue; \
222 return CloneVarValue(sInstance->mVar##CxxName.Get()); \
224 static void Set##CxxName(const DataType& aValue) { \
225 if (sInstance->mVar##CxxName.Set(aValue)) { \
226 sInstance->NotifyReceivers(&sInstance->mVar##CxxName); \
230 static void Set##CxxName##Listener(const std::function<void()>& aListener) { \
231 sInstance->mVar##CxxName.SetListener(aListener); \
234 using ArrayOfuint64_t
= nsTArray
<uint64_t>;
236 GFX_VARS_LIST(GFX_VAR_DECL
)
242 void NotifyReceivers(VarBase
* aVar
);
245 nsTArray
<gfxVarReceiver
*> mReceivers
;
250 } // namespace mozilla::gfx
252 #endif // mozilla_gfx_config_gfxVars_h