Bug 1760684 [wpt PR 33213] - Update wpt metadata, a=testonly
[gecko.git] / gfx / config / gfxFeature.h
blob65572e5f20d1cf76e7d3fdcf7f1cbf7df67e1d48
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
9 #include <functional>
10 #include <stdint.h>
11 #include "gfxTelemetry.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/Maybe.h"
14 #include "nsString.h"
16 namespace mozilla {
17 namespace gfx {
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_SHADER_CACHE, Feature, "WebRender shader disk cache") \
33 _(WEBRENDER_OPTIMIZED_SHADERS, Feature, "WebRender optimized shaders") \
34 _(WEBRENDER_ANGLE, Feature, "WebRender ANGLE") \
35 _(WEBRENDER_DCOMP_PRESENT, Feature, "WebRender DirectComposition") \
36 _(WEBRENDER_SOFTWARE, Feature, "WebRender software fallback") \
37 _(OMTP, Feature, "Off Main Thread Painting") \
38 _(WEBGPU, Feature, "WebGPU") \
39 _(X11_EGL, Feature, "X11 EGL") \
40 _(DMABUF, Feature, "DMABUF") \
41 _(WINDOW_OCCLUSION, Feature, "WINDOW_OCCLUSION") \
42 _(VAAPI, Feature, "VA-API video decoding") \
43 _(VIDEO_OVERLAY, Feature, "video overlay") \
44 _(VP8_HW_DECODE, Feature, "VP8 hardware decoding") \
45 _(VP9_HW_DECODE, Feature, "VP9 hardware decoding")
46 /* Add new entries above this comment */
48 enum class Feature : uint32_t {
49 #define MAKE_ENUM(name, type, desc) name,
50 GFX_FEATURE_MAP(MAKE_ENUM)
51 #undef MAKE_ENUM
52 NumValues
55 class FeatureState {
56 friend class gfxConfig;
57 friend class GfxConfigManager; // for testing
59 public:
60 FeatureState() { Reset(); }
62 bool IsEnabled() const;
63 FeatureStatus GetValue() const;
65 void EnableByDefault();
66 void DisableByDefault(FeatureStatus aStatus, const char* aMessage,
67 const nsACString& aFailureId);
68 bool SetDefault(bool aEnable, FeatureStatus aDisableStatus,
69 const char* aDisableMessage);
70 bool InitOrUpdate(bool aEnable, FeatureStatus aDisableStatus,
71 const char* aMessage);
72 void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
73 bool aDefaultValue, Maybe<bool> aUserValue);
74 void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
75 bool aDefaultValue);
76 void UserEnable(const char* aMessage);
77 void UserForceEnable(const char* aMessage);
78 void UserDisable(const char* aMessage, const nsACString& aFailureId);
79 void Disable(FeatureStatus aStatus, const char* aMessage,
80 const nsACString& aFailureId);
81 void ForceDisable(FeatureStatus aStatus, const char* aMessage,
82 const nsACString& aFailureId) {
83 SetFailed(aStatus, aMessage, aFailureId);
85 void SetFailed(FeatureStatus aStatus, const char* aMessage,
86 const nsACString& aFailureId);
87 bool MaybeSetFailed(bool aEnable, FeatureStatus aStatus, const char* aMessage,
88 const nsACString& aFailureId);
89 bool MaybeSetFailed(FeatureStatus aStatus, const char* aMessage,
90 const nsACString& aFailureId);
92 // aType is "base", "user", "env", or "runtime".
93 // aMessage may be null.
94 typedef std::function<void(const char* aType, FeatureStatus aStatus,
95 const char* aMessage, const nsCString& aFailureId)>
96 StatusIterCallback;
97 void ForEachStatusChange(const StatusIterCallback& aCallback) const;
99 const char* GetFailureMessage() const;
100 const nsCString& GetFailureId() const;
101 nsCString GetStatusAndFailureIdString() const;
103 bool DisabledByDefault() const;
105 private:
106 void SetUser(FeatureStatus aStatus, const char* aMessage,
107 const nsACString& aFailureId);
108 void SetEnvironment(FeatureStatus aStatus, const char* aMessage,
109 const nsACString& aFailureId);
110 void SetRuntime(FeatureStatus aStatus, const char* aMessage,
111 const nsACString& aFailureId);
112 bool IsForcedOnByUser() const;
113 const char* GetRuntimeMessage() const;
114 bool IsInitialized() const { return mDefault.IsInitialized(); }
116 void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
118 // Clear all state.
119 void Reset();
121 private:
122 struct Instance {
123 char mMessage[64];
124 FeatureStatus mStatus;
125 nsCString mFailureId;
127 void Set(FeatureStatus aStatus);
128 void Set(FeatureStatus aStatus, const char* aMessage,
129 const nsACString& aFailureId);
130 bool IsInitialized() const { return mStatus != FeatureStatus::Unused; }
131 const char* MessageOrNull() const {
132 return mMessage[0] != '\0' ? mMessage : nullptr;
134 const char* Message() const {
135 MOZ_ASSERT(MessageOrNull());
136 return mMessage;
138 const nsCString& FailureId() const { return mFailureId; }
141 // The default state is the state we decide on startup, based on the operating
142 // system or a base preference.
144 // The user state factors in any changes to preferences that the user made.
146 // The environment state factors in any additional decisions made, such as
147 // availability or blocklisting.
149 // The runtime state factors in any problems discovered at runtime.
150 Instance mDefault;
151 Instance mUser;
152 Instance mEnvironment;
153 Instance mRuntime;
156 } // namespace gfx
157 } // namespace mozilla
159 #endif // mozilla_gfx_config_gfxFeature_h