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 _(UseWebRenderDCompWin, bool, false) \
44 _(UseWebRenderDCompWinTripleBuffering, bool, false) \
45 _(UseWebRenderProgramBinary, 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 */)
55 /* Add new entries above this line. */
57 // Some graphics settings are computed on the UI process and must be
58 // communicated to content and GPU processes. gfxVars helps facilitate
59 // this. Its function is similar to gfxPrefs, except rather than hold
60 // user preferences, it holds dynamically computed values.
62 // Each variable in GFX_VARS_LIST exposes the following static methods:
64 // const DataType& CxxName();
65 // void SetCxxName(const DataType& aValue);
67 // Note that the setter may only be called in the UI process; a gfxVar must be
68 // a variable that is determined in the UI process and pushed to child
72 // These values will be used during the Initialize() call if set. Any
73 // updates that come before initialization will get added to this array.
74 static void SetValuesForInitialize(
75 const nsTArray
<GfxVarUpdate
>& aInitUpdates
);
77 static void Initialize();
78 static void Shutdown();
80 static void ApplyUpdate(const GfxVarUpdate
& aUpdate
);
81 static void AddReceiver(gfxVarReceiver
* aReceiver
);
82 static void RemoveReceiver(gfxVarReceiver
* aReceiver
);
84 // Return a list of updates for all variables with non-default values.
85 static nsTArray
<GfxVarUpdate
> FetchNonDefaultVars();
88 // Each variable must expose Set and Get methods for IPDL.
92 virtual void SetValue(const GfxVarValue
& aValue
) = 0;
93 virtual void GetValue(GfxVarValue
* aOutValue
) = 0;
94 virtual bool HasDefaultValue() const = 0;
95 size_t Index() const { return mIndex
; }
102 static StaticAutoPtr
<gfxVars
> sInstance
;
103 static StaticAutoPtr
<nsTArray
<VarBase
*>> sVarList
;
105 template <typename T
, T
Default()>
106 class VarImpl final
: public VarBase
{
108 VarImpl() : mValue(Default()) {}
109 void SetValue(const GfxVarValue
& aValue
) override
{
115 void GetValue(GfxVarValue
* aOutValue
) override
{
116 *aOutValue
= GfxVarValue(mValue
);
118 bool HasDefaultValue() const override
{ return mValue
== Default(); }
119 const T
& Get() const { return mValue
; }
120 // Return true if the value changed, false otherwise.
121 bool Set(const T
& aValue
) {
122 MOZ_ASSERT(XRE_IsParentProcess());
123 if (mValue
== aValue
) {
133 void SetListener(const std::function
<void()>& aListener
) {
134 mListener
= aListener
;
139 std::function
<void()> mListener
;
142 #define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
144 static DataType Get##CxxName##Default() { return DefaultValue; } \
145 VarImpl<DataType, Get##CxxName##Default> mVar##CxxName; \
148 static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
149 static DataType Get##CxxName##OrDefault() { \
151 return DefaultValue; \
153 return sInstance->mVar##CxxName.Get(); \
155 static void Set##CxxName(const DataType& aValue) { \
156 if (sInstance->mVar##CxxName.Set(aValue)) { \
157 sInstance->NotifyReceivers(&sInstance->mVar##CxxName); \
161 static void Set##CxxName##Listener(const std::function<void()>& aListener) { \
162 sInstance->mVar##CxxName.SetListener(aListener); \
165 GFX_VARS_LIST(GFX_VAR_DECL
)
171 void NotifyReceivers(VarBase
* aVar
);
174 nsTArray
<gfxVarReceiver
*> mReceivers
;
180 } // namespace mozilla
182 #endif // mozilla_gfx_config_gfxVars_h