Bug 1822393 - Consume GeckoView directly in Android Components for CI builds. r=owlis...
[gecko.git] / gfx / config / gfxVars.h
blobd74255b5db531d1d760c23c7f4e6808d10bb471d
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 _(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) \
102 _(WebglUseHardware, bool, true) \
103 _(WebRenderOverlayVpAutoHDR, bool, false) \
104 _(WebRenderOverlayVpSuperResolution, bool, false)
106 /* Add new entries above this line. */
108 // Some graphics settings are computed on the UI process and must be
109 // communicated to content and GPU processes. gfxVars helps facilitate
110 // this. Its function is similar to StaticPrefs, except rather than hold
111 // user preferences, it holds dynamically computed values.
113 // Each variable in GFX_VARS_LIST exposes the following static methods:
115 // const DataType& CxxName();
116 // void SetCxxName(const DataType& aValue);
118 // Note that the setter may only be called in the UI process; a gfxVar must be
119 // a variable that is determined in the UI process and pushed to child
120 // processes.
121 class gfxVars final {
122 public:
123 // These values will be used during the Initialize() call if set. Any
124 // updates that come before initialization will get added to this array.
125 static void SetValuesForInitialize(
126 const nsTArray<GfxVarUpdate>& aInitUpdates);
128 static void Initialize();
129 static void Shutdown();
131 static void ApplyUpdate(const GfxVarUpdate& aUpdate);
132 static void AddReceiver(gfxVarReceiver* aReceiver);
133 static void RemoveReceiver(gfxVarReceiver* aReceiver);
135 // Return a list of updates for all variables with non-default values.
136 static nsTArray<GfxVarUpdate> FetchNonDefaultVars();
138 private:
139 template <typename U>
140 static U CloneVarValue(const U& aValue) {
141 return aValue;
144 template <typename U>
145 static nsTArray<U> CloneVarValue(const nsTArray<U>& aValue) {
146 return aValue.Clone();
149 public:
150 // Each variable must expose Set and Get methods for IPDL.
151 class VarBase {
152 public:
153 VarBase();
154 virtual void SetValue(const GfxVarValue& aValue) = 0;
155 virtual void GetValue(GfxVarValue* aOutValue) = 0;
156 virtual bool HasDefaultValue() const = 0;
157 size_t Index() const { return mIndex; }
159 private:
160 size_t mIndex;
163 // Whether the gfxVars singleton instance has been initialized. Most gfx code
164 // doesn't need to check this, but code that can potentially run before
165 // gfxPlatform initialization can use this to check whether gfxVars are
166 // available yet.
167 static bool IsInitialized() { return sInstance != nullptr; }
169 private:
170 static StaticAutoPtr<gfxVars> sInstance;
171 static StaticAutoPtr<nsTArray<VarBase*>> sVarList;
173 template <typename T, T Default(), T GetFrom(const GfxVarValue& aValue)>
174 class VarImpl final : public VarBase {
175 public:
176 VarImpl() : mValue(Default()) {}
177 void SetValue(const GfxVarValue& aValue) override {
178 mValue = GetFrom(aValue);
179 if (mListener) {
180 mListener();
183 void GetValue(GfxVarValue* aOutValue) override {
184 *aOutValue = GfxVarValue(mValue);
186 bool HasDefaultValue() const override { return mValue == Default(); }
187 const T& Get() const { return mValue; }
189 // Return true if the value changed, false otherwise.
190 bool Set(const T& aValue) {
191 MOZ_ASSERT(XRE_IsParentProcess());
192 if (mValue == aValue) {
193 return false;
195 mValue = CloneVarValue(aValue);
196 if (mListener) {
197 mListener();
199 return true;
202 void SetListener(const std::function<void()>& aListener) {
203 mListener = aListener;
206 private:
207 T mValue;
208 std::function<void()> mListener;
211 #define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
212 private: \
213 static DataType Get##CxxName##Default() { return DefaultValue; } \
214 static DataType Get##CxxName##From(const GfxVarValue& aValue) { \
215 return CloneVarValue(aValue.get_##DataType()); \
217 VarImpl<DataType, Get##CxxName##Default, Get##CxxName##From> mVar##CxxName; \
219 public: \
220 static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
221 static DataType Get##CxxName##OrDefault() { \
222 if (!sInstance) { \
223 return DefaultValue; \
225 return CloneVarValue(sInstance->mVar##CxxName.Get()); \
227 static void Set##CxxName(const DataType& aValue) { \
228 if (sInstance->mVar##CxxName.Set(aValue)) { \
229 sInstance->NotifyReceivers(&sInstance->mVar##CxxName); \
233 static void Set##CxxName##Listener(const std::function<void()>& aListener) { \
234 sInstance->mVar##CxxName.SetListener(aListener); \
237 using ArrayOfuint64_t = nsTArray<uint64_t>;
239 GFX_VARS_LIST(GFX_VAR_DECL)
240 #undef GFX_VAR_DECL
242 private:
243 gfxVars();
245 void NotifyReceivers(VarBase* aVar);
247 private:
248 nsTArray<gfxVarReceiver*> mReceivers;
251 #undef GFX_VARS_LIST
253 } // namespace mozilla::gfx
255 #endif // mozilla_gfx_config_gfxVars_h