Bug 1568876 - Make copyRule in the ChangesView fission compatible. r=rcaliman
[gecko.git] / gfx / config / gfxVars.h
blob24a3196646754057351c283ebeccb414107cae99
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 {
19 namespace gfx {
21 class gfxVarReceiver;
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
73 // processes.
74 class gfxVars final {
75 public:
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();
91 public:
92 // Each variable must expose Set and Get methods for IPDL.
93 class VarBase {
94 public:
95 VarBase();
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; }
101 private:
102 size_t mIndex;
105 private:
106 static StaticAutoPtr<gfxVars> sInstance;
107 static StaticAutoPtr<nsTArray<VarBase*>> sVarList;
109 template <typename T, T Default()>
110 class VarImpl final : public VarBase {
111 public:
112 VarImpl() : mValue(Default()) {}
113 void SetValue(const GfxVarValue& aValue) override {
114 aValue.get(&mValue);
115 if (mListener) {
116 mListener();
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) {
128 return false;
130 mValue = aValue;
131 if (mListener) {
132 mListener();
134 return true;
137 void SetListener(const std::function<void()>& aListener) {
138 mListener = aListener;
141 private:
142 T mValue;
143 std::function<void()> mListener;
146 #define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
147 private: \
148 static DataType Get##CxxName##Default() { return DefaultValue; } \
149 VarImpl<DataType, Get##CxxName##Default> mVar##CxxName; \
151 public: \
152 static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
153 static DataType Get##CxxName##OrDefault() { \
154 if (!sInstance) { \
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)
170 #undef GFX_VAR_DECL
172 private:
173 gfxVars();
175 void NotifyReceivers(VarBase* aVar);
177 private:
178 nsTArray<gfxVarReceiver*> mReceivers;
181 #undef GFX_VARS_LIST
183 } // namespace gfx
184 } // namespace mozilla
186 #endif // mozilla_gfx_config_gfxVars_h