Bug 1771374 - Fix lint warnings. r=gfx-reviewers,aosmond
[gecko.git] / gfx / config / gfxFeature.h
blobdd27f5bbcca9a6a809e36c987ad61b900cdefc33
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 _(HARDWARE_VIDEO_DECODING, Feature, "Hardware video decoding") \
43 _(VIDEO_OVERLAY, Feature, "video overlay") \
44 _(HW_DECODED_VIDEO_ZERO_COPY, Feature, "Hardware decoded video zero copy") \
45 _(VP8_HW_DECODE, Feature, "VP8 hardware decoding") \
46 _(VP9_HW_DECODE, Feature, "VP9 hardware decoding") \
47 _(DMABUF_SURFACE_EXPORT, Feature, "WebGL DMABuf surface export") \
48 _(REUSE_DECODER_DEVICE, Feature, "Reuse decoder device")
49 /* Add new entries above this comment */
51 enum class Feature : uint32_t {
52 #define MAKE_ENUM(name, type, desc) name,
53 GFX_FEATURE_MAP(MAKE_ENUM)
54 #undef MAKE_ENUM
55 NumValues
58 class FeatureState {
59 friend class gfxConfig;
60 friend class GfxConfigManager; // for testing
62 public:
63 FeatureState() { Reset(); }
65 bool IsEnabled() const;
66 FeatureStatus GetValue() const;
68 void EnableByDefault();
69 void DisableByDefault(FeatureStatus aStatus, const char* aMessage,
70 const nsACString& aFailureId);
71 bool SetDefault(bool aEnable, FeatureStatus aDisableStatus,
72 const char* aDisableMessage);
73 bool InitOrUpdate(bool aEnable, FeatureStatus aDisableStatus,
74 const char* aMessage);
75 void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
76 bool aDefaultValue, Maybe<bool> aUserValue);
77 void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
78 bool aDefaultValue);
79 void UserEnable(const char* aMessage);
80 void UserForceEnable(const char* aMessage);
81 void UserDisable(const char* aMessage, const nsACString& aFailureId);
82 void Disable(FeatureStatus aStatus, const char* aMessage,
83 const nsACString& aFailureId);
84 void ForceDisable(FeatureStatus aStatus, const char* aMessage,
85 const nsACString& aFailureId) {
86 SetFailed(aStatus, aMessage, aFailureId);
88 void SetFailed(FeatureStatus aStatus, const char* aMessage,
89 const nsACString& aFailureId);
90 bool MaybeSetFailed(bool aEnable, FeatureStatus aStatus, const char* aMessage,
91 const nsACString& aFailureId);
92 bool MaybeSetFailed(FeatureStatus aStatus, const char* aMessage,
93 const nsACString& aFailureId);
95 // aType is "base", "user", "env", or "runtime".
96 // aMessage may be null.
97 typedef std::function<void(const char* aType, FeatureStatus aStatus,
98 const char* aMessage, const nsCString& aFailureId)>
99 StatusIterCallback;
100 void ForEachStatusChange(const StatusIterCallback& aCallback) const;
102 const char* GetFailureMessage() const;
103 const nsCString& GetFailureId() const;
104 nsCString GetStatusAndFailureIdString() const;
106 bool DisabledByDefault() const;
108 private:
109 void SetUser(FeatureStatus aStatus, const char* aMessage,
110 const nsACString& aFailureId);
111 void SetEnvironment(FeatureStatus aStatus, const char* aMessage,
112 const nsACString& aFailureId);
113 void SetRuntime(FeatureStatus aStatus, const char* aMessage,
114 const nsACString& aFailureId);
115 bool IsForcedOnByUser() const;
116 const char* GetRuntimeMessage() const;
117 bool IsInitialized() const { return mDefault.IsInitialized(); }
119 void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
121 // Clear all state.
122 void Reset();
124 private:
125 struct Instance {
126 char mMessage[64];
127 FeatureStatus mStatus;
128 nsCString mFailureId;
130 void Set(FeatureStatus aStatus);
131 void Set(FeatureStatus aStatus, const char* aMessage,
132 const nsACString& aFailureId);
133 bool IsInitialized() const { return mStatus != FeatureStatus::Unused; }
134 const char* MessageOrNull() const {
135 return mMessage[0] != '\0' ? mMessage : nullptr;
137 const char* Message() const {
138 MOZ_ASSERT(MessageOrNull());
139 return mMessage;
141 const nsCString& FailureId() const { return mFailureId; }
144 // The default state is the state we decide on startup, based on the operating
145 // system or a base preference.
147 // The user state factors in any changes to preferences that the user made.
149 // The environment state factors in any additional decisions made, such as
150 // availability or blocklisting.
152 // The runtime state factors in any problems discovered at runtime.
153 Instance mDefault;
154 Instance mUser;
155 Instance mEnvironment;
156 Instance mRuntime;
159 } // namespace gfx
160 } // namespace mozilla
162 #endif // mozilla_gfx_config_gfxFeature_h