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_COMPOSITOR, Feature, "WebRender native compositor") \
30 _(WEBRENDER_PARTIAL, Feature, "WebRender partial present") \
31 _(WEBRENDER_SHADER_CACHE, Feature, "WebRender shader disk cache") \
32 _(WEBRENDER_OPTIMIZED_SHADERS, Feature, "WebRender optimized shaders") \
33 _(WEBRENDER_ANGLE, Feature, "WebRender ANGLE") \
34 _(WEBRENDER_DCOMP_PRESENT, Feature, "WebRender DirectComposition") \
35 _(WEBRENDER_SCISSORED_CACHE_CLEARS, Feature, \
36 "WebRender scissored cache clears") \
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 _(BACKDROP_FILTER, Feature, "Backdrop filter") \
50 _(CANVAS_RENDERER_THREAD, Feature, "canvas renderer thread") \
51 _(ACCELERATED_CANVAS2D, Feature, "Accelerated Canvas2D") \
52 _(H264_HW_DECODE, Feature, "H.264 hardware decoding") \
53 _(AV1_HW_DECODE, Feature, "AV1 hardware decoding") \
54 /* Add new entries above this comment */
56 enum class Feature
: uint32_t {
57 #define MAKE_ENUM(name, type, desc) name,
58 GFX_FEATURE_MAP(MAKE_ENUM
)
64 friend class gfxConfig
;
65 friend class GfxConfigManager
; // for testing
68 FeatureState() { Reset(); }
70 bool IsEnabled() const;
71 FeatureStatus
GetValue() const;
73 void EnableByDefault();
74 void DisableByDefault(FeatureStatus aStatus
, const char* aMessage
,
75 const nsACString
& aFailureId
);
76 bool SetDefault(bool aEnable
, FeatureStatus aDisableStatus
,
77 const char* aDisableMessage
);
78 bool InitOrUpdate(bool aEnable
, FeatureStatus aDisableStatus
,
79 const char* aMessage
);
80 void SetDefaultFromPref(const char* aPrefName
, bool aIsEnablePref
,
81 bool aDefaultValue
, Maybe
<bool> aUserValue
);
82 void SetDefaultFromPref(const char* aPrefName
, bool aIsEnablePref
,
84 void UserEnable(const char* aMessage
);
85 void UserForceEnable(const char* aMessage
);
86 void UserDisable(const char* aMessage
, const nsACString
& aFailureId
);
87 void Disable(FeatureStatus aStatus
, const char* aMessage
,
88 const nsACString
& aFailureId
);
89 void ForceDisable(FeatureStatus aStatus
, const char* aMessage
,
90 const nsACString
& aFailureId
) {
91 SetFailed(aStatus
, aMessage
, aFailureId
);
93 void SetFailed(FeatureStatus aStatus
, const char* aMessage
,
94 const nsACString
& aFailureId
);
95 bool MaybeSetFailed(bool aEnable
, FeatureStatus aStatus
, const char* aMessage
,
96 const nsACString
& aFailureId
);
97 bool MaybeSetFailed(FeatureStatus aStatus
, const char* aMessage
,
98 const nsACString
& aFailureId
);
100 // aType is "base", "user", "env", or "runtime".
101 // aMessage may be null.
102 typedef std::function
<void(const char* aType
, FeatureStatus aStatus
,
103 const char* aMessage
, const nsCString
& aFailureId
)>
105 void ForEachStatusChange(const StatusIterCallback
& aCallback
) const;
107 const char* GetFailureMessage() const;
108 const nsCString
& GetFailureId() const;
109 nsCString
GetStatusAndFailureIdString() const;
111 bool DisabledByDefault() const;
117 void SetUser(FeatureStatus aStatus
, const char* aMessage
,
118 const nsACString
& aFailureId
);
119 void SetEnvironment(FeatureStatus aStatus
, const char* aMessage
,
120 const nsACString
& aFailureId
);
121 void SetRuntime(FeatureStatus aStatus
, const char* aMessage
,
122 const nsACString
& aFailureId
);
123 bool IsForcedOnByUser() const;
124 const char* GetRuntimeMessage() const;
125 bool IsInitialized() const { return mDefault
.IsInitialized(); }
127 void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
132 FeatureStatus mStatus
;
133 nsCString mFailureId
;
135 void Set(FeatureStatus aStatus
);
136 void Set(FeatureStatus aStatus
, const char* aMessage
,
137 const nsACString
& aFailureId
);
138 bool IsInitialized() const { return mStatus
!= FeatureStatus::Unused
; }
139 const char* MessageOrNull() const {
140 return mMessage
[0] != '\0' ? mMessage
: nullptr;
142 const char* Message() const {
143 MOZ_ASSERT(MessageOrNull());
146 const nsCString
& FailureId() const { return mFailureId
; }
149 // The default state is the state we decide on startup, based on the operating
150 // system or a base preference.
152 // The user state factors in any changes to preferences that the user made.
154 // The environment state factors in any additional decisions made, such as
155 // availability or blocklisting.
157 // The runtime state factors in any problems discovered at runtime.
160 Instance mEnvironment
;
165 } // namespace mozilla
167 #endif // mozilla_gfx_config_gfxFeature_h