Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / config / gfxVars.h
blobc23db91cecffeb5d041b633c9287b6526352ea7d
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
9 #include <stdint.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"
15 #include "nsTArray.h"
16 #include "nsXULAppAPI.h"
18 namespace mozilla::gfx {
20 class gfxVarReceiver;
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 _(PrimaryScreenDepth, 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) \
102 _(WebglUseHardware, bool, true) \
103 _(WebRenderOverlayVpAutoHDR, bool, false) \
104 _(WebRenderOverlayVpSuperResolution, bool, false) \
105 _(AllowWebGPUPresentWithoutReadback, bool, false)
107 /* Add new entries above this line. */
109 // Some graphics settings are computed on the UI process and must be
110 // communicated to content and GPU processes. gfxVars helps facilitate
111 // this. Its function is similar to StaticPrefs, except rather than hold
112 // user preferences, it holds dynamically computed values.
114 // Each variable in GFX_VARS_LIST exposes the following static methods:
116 // const DataType& CxxName();
117 // void SetCxxName(const DataType& aValue);
119 // Note that the setter may only be called in the UI process; a gfxVar must be
120 // a variable that is determined in the UI process and pushed to child
121 // processes.
122 class gfxVars final {
123 public:
124 // These values will be used during the Initialize() call if set. Any
125 // updates that come before initialization will get added to this array.
126 static void SetValuesForInitialize(
127 const nsTArray<GfxVarUpdate>& aInitUpdates);
129 static void Initialize();
130 static void Shutdown();
132 static void ApplyUpdate(const GfxVarUpdate& aUpdate);
133 static void AddReceiver(gfxVarReceiver* aReceiver);
134 static void RemoveReceiver(gfxVarReceiver* aReceiver);
136 // Return a list of updates for all variables with non-default values.
137 static nsTArray<GfxVarUpdate> FetchNonDefaultVars();
139 private:
140 template <typename U>
141 static U CloneVarValue(const U& aValue) {
142 return aValue;
145 template <typename U>
146 static nsTArray<U> CloneVarValue(const nsTArray<U>& aValue) {
147 return aValue.Clone();
150 public:
151 // Each variable must expose Set and Get methods for IPDL.
152 class VarBase {
153 public:
154 VarBase();
155 virtual void SetValue(const GfxVarValue& aValue) = 0;
156 virtual void GetValue(GfxVarValue* aOutValue) = 0;
157 virtual bool HasDefaultValue() const = 0;
158 size_t Index() const { return mIndex; }
160 private:
161 size_t mIndex;
164 // Whether the gfxVars singleton instance has been initialized. Most gfx code
165 // doesn't need to check this, but code that can potentially run before
166 // gfxPlatform initialization can use this to check whether gfxVars are
167 // available yet.
168 static bool IsInitialized() { return sInstance != nullptr; }
170 private:
171 static StaticAutoPtr<gfxVars> sInstance;
172 static StaticAutoPtr<nsTArray<VarBase*>> sVarList;
174 template <typename T, T Default(), T GetFrom(const GfxVarValue& aValue)>
175 class VarImpl final : public VarBase {
176 public:
177 VarImpl() : mValue(Default()) {}
178 void SetValue(const GfxVarValue& aValue) override {
179 mValue = GetFrom(aValue);
180 if (mListener) {
181 mListener();
184 void GetValue(GfxVarValue* aOutValue) override {
185 *aOutValue = GfxVarValue(mValue);
187 bool HasDefaultValue() const override { return mValue == Default(); }
188 const T& Get() const { return mValue; }
190 // Return true if the value changed, false otherwise.
191 bool Set(const T& aValue) {
192 MOZ_ASSERT(XRE_IsParentProcess());
193 if (mValue == aValue) {
194 return false;
196 mValue = CloneVarValue(aValue);
197 if (mListener) {
198 mListener();
200 return true;
203 void SetListener(const std::function<void()>& aListener) {
204 mListener = aListener;
207 private:
208 T mValue;
209 std::function<void()> mListener;
212 #define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
213 private: \
214 static DataType Get##CxxName##Default() { return DefaultValue; } \
215 static DataType Get##CxxName##From(const GfxVarValue& aValue) { \
216 return CloneVarValue(aValue.get_##DataType()); \
218 VarImpl<DataType, Get##CxxName##Default, Get##CxxName##From> mVar##CxxName; \
220 public: \
221 static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
222 static DataType Get##CxxName##OrDefault() { \
223 if (!sInstance) { \
224 return DefaultValue; \
226 return CloneVarValue(sInstance->mVar##CxxName.Get()); \
228 static void Set##CxxName(const DataType& aValue) { \
229 if (sInstance->mVar##CxxName.Set(aValue)) { \
230 sInstance->NotifyReceivers(&sInstance->mVar##CxxName); \
234 static void Set##CxxName##Listener(const std::function<void()>& aListener) { \
235 sInstance->mVar##CxxName.SetListener(aListener); \
238 using ArrayOfuint64_t = nsTArray<uint64_t>;
240 GFX_VARS_LIST(GFX_VAR_DECL)
241 #undef GFX_VAR_DECL
243 private:
244 gfxVars();
246 void NotifyReceivers(VarBase* aVar);
248 private:
249 nsTArray<gfxVarReceiver*> mReceivers;
252 #undef GFX_VARS_LIST
254 } // namespace mozilla::gfx
256 #endif // mozilla_gfx_config_gfxVars_h