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_gfxFeature_h
7 #define mozilla_gfx_config_gfxFeature_h
11 #include "gfxTelemetry.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/Maybe.h"
19 #define GFX_FEATURE_MAP(_) \
20 /* Name, Type, Description */ \
21 _(HW_COMPOSITING, Feature, "Compositing") \
22 _(D3D11_COMPOSITING, Feature, "Direct3D11 Compositing") \
23 _(OPENGL_COMPOSITING, Feature, "OpenGL Compositing") \
24 _(DIRECT2D, Feature, "Direct2D") \
25 _(D3D11_HW_ANGLE, Feature, "Direct3D11 hardware ANGLE") \
26 _(DIRECT_DRAW, Feature, "DirectDraw") \
27 _(GPU_PROCESS, Feature, "GPU Process") \
28 _(WEBRENDER, Feature, "WebRender") \
29 _(WEBRENDER_QUALIFIED, Feature, "WebRender qualified") \
30 _(WEBRENDER_COMPOSITOR, Feature, "WebRender native compositor") \
31 _(WEBRENDER_PARTIAL, Feature, "WebRender partial present") \
32 _(WEBRENDER_OPTIMIZED_SHADERS, Feature, "WebRender optimized shaders") \
33 _(WEBRENDER_ANGLE, Feature, "WebRender ANGLE") \
34 _(WEBRENDER_DCOMP_PRESENT, Feature, "WebRender DirectComposition") \
35 _(WEBRENDER_SOFTWARE, Feature, "WebRender software fallback") \
36 _(OMTP, Feature, "Off Main Thread Painting") \
37 _(WEBGPU, Feature, "WebGPU") \
38 /* Add new entries above this comment */
40 enum class Feature
: uint32_t {
41 #define MAKE_ENUM(name, type, desc) name,
42 GFX_FEATURE_MAP(MAKE_ENUM
)
48 friend class gfxConfig
;
49 friend class GfxConfigManager
; // for testing
52 FeatureState() { Reset(); }
54 bool IsEnabled() const;
55 FeatureStatus
GetValue() const;
57 void EnableByDefault();
58 void DisableByDefault(FeatureStatus aStatus
, const char* aMessage
,
59 const nsACString
& aFailureId
);
60 bool SetDefault(bool aEnable
, FeatureStatus aDisableStatus
,
61 const char* aDisableMessage
);
62 bool InitOrUpdate(bool aEnable
, FeatureStatus aDisableStatus
,
63 const char* aMessage
);
64 void SetDefaultFromPref(const char* aPrefName
, bool aIsEnablePref
,
65 bool aDefaultValue
, Maybe
<bool> aUserValue
);
66 void SetDefaultFromPref(const char* aPrefName
, bool aIsEnablePref
,
68 void UserEnable(const char* aMessage
);
69 void UserForceEnable(const char* aMessage
);
70 void UserDisable(const char* aMessage
, const nsACString
& aFailureId
);
71 void Disable(FeatureStatus aStatus
, const char* aMessage
,
72 const nsACString
& aFailureId
);
73 void ForceDisable(FeatureStatus aStatus
, const char* aMessage
,
74 const nsACString
& aFailureId
) {
75 SetFailed(aStatus
, aMessage
, aFailureId
);
77 void SetFailed(FeatureStatus aStatus
, const char* aMessage
,
78 const nsACString
& aFailureId
);
79 bool MaybeSetFailed(bool aEnable
, FeatureStatus aStatus
, const char* aMessage
,
80 const nsACString
& aFailureId
);
81 bool MaybeSetFailed(FeatureStatus aStatus
, const char* aMessage
,
82 const nsACString
& aFailureId
);
84 // aType is "base", "user", "env", or "runtime".
85 // aMessage may be null.
86 typedef std::function
<void(const char* aType
, FeatureStatus aStatus
,
87 const char* aMessage
, const nsCString
& aFailureId
)>
89 void ForEachStatusChange(const StatusIterCallback
& aCallback
) const;
91 const char* GetFailureMessage() const;
92 const nsCString
& GetFailureId() const;
93 nsCString
GetStatusAndFailureIdString() const;
95 bool DisabledByDefault() const;
98 void SetUser(FeatureStatus aStatus
, const char* aMessage
,
99 const nsACString
& aFailureId
);
100 void SetEnvironment(FeatureStatus aStatus
, const char* aMessage
,
101 const nsACString
& aFailureId
);
102 void SetRuntime(FeatureStatus aStatus
, const char* aMessage
,
103 const nsACString
& aFailureId
);
104 bool IsForcedOnByUser() const;
105 const char* GetRuntimeMessage() const;
106 bool IsInitialized() const { return mDefault
.IsInitialized(); }
108 void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
116 FeatureStatus mStatus
;
117 nsCString mFailureId
;
119 void Set(FeatureStatus aStatus
);
120 void Set(FeatureStatus aStatus
, const char* aMessage
,
121 const nsACString
& aFailureId
);
122 bool IsInitialized() const { return mStatus
!= FeatureStatus::Unused
; }
123 const char* MessageOrNull() const {
124 return mMessage
[0] != '\0' ? mMessage
: nullptr;
126 const char* Message() const {
127 MOZ_ASSERT(MessageOrNull());
130 const nsCString
& FailureId() const { return mFailureId
; }
133 // The default state is the state we decide on startup, based on the operating
134 // system or a base preference.
136 // The user state factors in any changes to preferences that the user made.
138 // The environment state factors in any additional decisions made, such as
139 // availability or blocklisting.
141 // The runtime state factors in any problems discovered at runtime.
144 Instance mEnvironment
;
149 } // namespace mozilla
151 #endif // mozilla_gfx_config_gfxFeature_h