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"
18 #define GFX_FEATURE_MAP(_) \
19 /* Name, Type, Description */ \
20 _(HW_COMPOSITING, Feature, "Compositing") \
21 _(D3D11_COMPOSITING, Feature, "Direct3D11 Compositing") \
22 _(OPENGL_COMPOSITING, Feature, "OpenGL Compositing") \
23 _(DIRECT2D, Feature, "Direct2D") \
24 _(D3D11_HW_ANGLE, Feature, "Direct3D11 hardware ANGLE") \
25 _(DIRECT_DRAW, Feature, "DirectDraw") \
26 _(GPU_PROCESS, Feature, "GPU Process") \
27 _(WEBRENDER, Feature, "WebRender") \
28 _(WEBRENDER_QUALIFIED, Feature, "WebRender qualified") \
29 _(OMTP, Feature, "Off Main Thread Painting") \
30 _(ADVANCED_LAYERS, Feature, "Advanced Layers") \
31 _(WEBGPU, Feature, "WebGPU") \
32 /* Add new entries above this comment */
34 enum class Feature
: uint32_t {
35 #define MAKE_ENUM(name, type, desc) name,
36 GFX_FEATURE_MAP(MAKE_ENUM
)
42 friend class gfxConfig
;
45 bool IsEnabled() const;
46 FeatureStatus
GetValue() const;
48 void EnableByDefault();
49 void DisableByDefault(FeatureStatus aStatus
, const char* aMessage
,
50 const nsACString
& aFailureId
);
51 bool SetDefault(bool aEnable
, FeatureStatus aDisableStatus
,
52 const char* aDisableMessage
);
53 bool InitOrUpdate(bool aEnable
, FeatureStatus aDisableStatus
,
54 const char* aMessage
);
55 void SetDefaultFromPref(const char* aPrefName
, bool aIsEnablePref
,
57 void UserEnable(const char* aMessage
);
58 void UserForceEnable(const char* aMessage
);
59 void UserDisable(const char* aMessage
, const nsACString
& aFailureId
);
60 void Disable(FeatureStatus aStatus
, const char* aMessage
,
61 const nsACString
& aFailureId
);
62 void ForceDisable(FeatureStatus aStatus
, const char* aMessage
,
63 const nsACString
& aFailureId
) {
64 SetFailed(aStatus
, aMessage
, aFailureId
);
66 void SetFailed(FeatureStatus aStatus
, const char* aMessage
,
67 const nsACString
& aFailureId
);
68 bool MaybeSetFailed(bool aEnable
, FeatureStatus aStatus
, const char* aMessage
,
69 const nsACString
& aFailureId
);
70 bool MaybeSetFailed(FeatureStatus aStatus
, const char* aMessage
,
71 const nsACString
& aFailureId
);
73 // aType is "base", "user", "env", or "runtime".
74 // aMessage may be null.
75 typedef std::function
<void(const char* aType
, FeatureStatus aStatus
,
76 const char* aMessage
)>
78 void ForEachStatusChange(const StatusIterCallback
& aCallback
) const;
80 const char* GetFailureMessage() const;
81 const nsCString
& GetFailureId() const;
83 bool DisabledByDefault() const;
86 void SetUser(FeatureStatus aStatus
, const char* aMessage
);
87 void SetEnvironment(FeatureStatus aStatus
, const char* aMessage
);
88 void SetRuntime(FeatureStatus aStatus
, const char* aMessage
);
89 bool IsForcedOnByUser() const;
90 const char* GetRuntimeMessage() const;
91 bool IsInitialized() const { return mDefault
.IsInitialized(); }
93 void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
99 void SetFailureId(const nsACString
& aFailureId
);
103 FeatureStatus mStatus
;
105 void Set(FeatureStatus aStatus
, const char* aMessage
= nullptr);
106 bool IsInitialized() const { return mStatus
!= FeatureStatus::Unused
; }
107 const char* MessageOrNull() const {
108 return mMessage
[0] != '\0' ? mMessage
: nullptr;
110 const char* Message() const {
111 MOZ_ASSERT(MessageOrNull());
116 // The default state is the state we decide on startup, based on the operating
117 // system or a base preference.
119 // The user state factors in any changes to preferences that the user made.
121 // The environment state factors in any additional decisions made, such as
122 // availability or blacklisting.
124 // The runtime state factors in any problems discovered at runtime.
127 Instance mEnvironment
;
130 // Store the first reported failureId for now but we might want to track this
131 // by instance later if we need a specific breakdown.
132 nsCString mFailureId
;
136 } // namespace mozilla
138 #endif // mozilla_gfx_config_gfxFeature_h