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"
23 // Generator for graphics vars.
24 #define GFX_VARS_LIST(_) \
25 /* C++ Name, Data Type, Default Value */ \
26 _(BrowserTabsRemoteAutostart, bool, false) \
27 _(ContentBackend, BackendType, BackendType::NONE) \
28 _(SoftwareBackend, BackendType, BackendType::NONE) \
29 _(TileSize, IntSize, IntSize(-1, -1)) \
30 _(UseXRender, bool, false) \
31 _(OffscreenFormat, gfxImageFormat, \
32 mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) \
33 _(RequiresAcceleratedGLContextForCompositorOGL, bool, false) \
34 _(CanUseHardwareVideoDecoding, bool, false) \
35 _(PDMWMFDisableD3D11Dlls, nsCString, nsCString()) \
36 _(PDMWMFDisableD3D9Dlls, nsCString, nsCString()) \
37 _(DXInterop2Blocked, bool, false) \
38 _(DXNV12Blocked, bool, false) \
39 _(DXP010Blocked, bool, false) \
40 _(DXP016Blocked, bool, false) \
41 _(UseWebRender, bool, false) \
42 _(UseWebRenderANGLE, bool, false) \
43 _(UseWebRenderFlipSequentialWin, bool, false) \
44 _(UseWebRenderDCompWin, bool, false) \
45 _(UseWebRenderTripleBufferingWin, bool, false) \
46 _(UseWebRenderProgramBinaryDisk, bool, false) \
47 _(WebRenderDebugFlags, int32_t, 0) \
48 _(ScreenDepth, int32_t, 0) \
49 _(GREDirectory, nsString, nsString()) \
50 _(ProfDirectory, nsString, nsString()) \
51 _(UseOMTP, bool, false) \
52 _(AllowD3D11KeyedMutex, bool, false) \
53 _(SystemTextQuality, int32_t, 5 /* CLEARTYPE_QUALITY */) \
54 _(LayersWindowRecordingPath, nsCString, nsCString()) \
55 _(RemoteCanvasEnabled, bool, false) \
56 _(UseDoubleBufferingWithCompositor, bool, false) \
57 _(UseGLSwizzle, bool, true)
59 /* Add new entries above this line. */
61 // Some graphics settings are computed on the UI process and must be
62 // communicated to content and GPU processes. gfxVars helps facilitate
63 // this. Its function is similar to StaticPrefs, except rather than hold
64 // user preferences, it holds dynamically computed values.
66 // Each variable in GFX_VARS_LIST exposes the following static methods:
68 // const DataType& CxxName();
69 // void SetCxxName(const DataType& aValue);
71 // Note that the setter may only be called in the UI process; a gfxVar must be
72 // a variable that is determined in the UI process and pushed to child
76 // These values will be used during the Initialize() call if set. Any
77 // updates that come before initialization will get added to this array.
78 static void SetValuesForInitialize(
79 const nsTArray
<GfxVarUpdate
>& aInitUpdates
);
81 static void Initialize();
82 static void Shutdown();
84 static void ApplyUpdate(const GfxVarUpdate
& aUpdate
);
85 static void AddReceiver(gfxVarReceiver
* aReceiver
);
86 static void RemoveReceiver(gfxVarReceiver
* aReceiver
);
88 // Return a list of updates for all variables with non-default values.
89 static nsTArray
<GfxVarUpdate
> FetchNonDefaultVars();
92 // Each variable must expose Set and Get methods for IPDL.
96 virtual void SetValue(const GfxVarValue
& aValue
) = 0;
97 virtual void GetValue(GfxVarValue
* aOutValue
) = 0;
98 virtual bool HasDefaultValue() const = 0;
99 size_t Index() const { return mIndex
; }
106 static StaticAutoPtr
<gfxVars
> sInstance
;
107 static StaticAutoPtr
<nsTArray
<VarBase
*>> sVarList
;
109 template <typename T
, T
Default()>
110 class VarImpl final
: public VarBase
{
112 VarImpl() : mValue(Default()) {}
113 void SetValue(const GfxVarValue
& aValue
) override
{
119 void GetValue(GfxVarValue
* aOutValue
) override
{
120 *aOutValue
= GfxVarValue(mValue
);
122 bool HasDefaultValue() const override
{ return mValue
== Default(); }
123 const T
& Get() const { return mValue
; }
124 // Return true if the value changed, false otherwise.
125 bool Set(const T
& aValue
) {
126 MOZ_ASSERT(XRE_IsParentProcess());
127 if (mValue
== aValue
) {
137 void SetListener(const std::function
<void()>& aListener
) {
138 mListener
= aListener
;
143 std::function
<void()> mListener
;
146 #define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
148 static DataType Get##CxxName##Default() { return DefaultValue; } \
149 VarImpl<DataType, Get##CxxName##Default> mVar##CxxName; \
152 static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
153 static DataType Get##CxxName##OrDefault() { \
155 return DefaultValue; \
157 return sInstance->mVar##CxxName.Get(); \
159 static void Set##CxxName(const DataType& aValue) { \
160 if (sInstance->mVar##CxxName.Set(aValue)) { \
161 sInstance->NotifyReceivers(&sInstance->mVar##CxxName); \
165 static void Set##CxxName##Listener(const std::function<void()>& aListener) { \
166 sInstance->mVar##CxxName.SetListener(aListener); \
169 GFX_VARS_LIST(GFX_VAR_DECL
)
175 void NotifyReceivers(VarBase
* aVar
);
178 nsTArray
<gfxVarReceiver
*> mReceivers
;
184 } // namespace mozilla
186 #endif // mozilla_gfx_config_gfxVars_h