Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / config / gfxFeature.h
blob98072d9369d7ec0719835fdc910a391c5de529af
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_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_HARDWARE_OVERLAY, Feature, "hardware decoded video overlay") \
44 _(VIDEO_SOFTWARE_OVERLAY, Feature, "software decoded video overlay") \
45 _(HW_DECODED_VIDEO_ZERO_COPY, Feature, "Hardware decoded video zero copy") \
46 _(VP8_HW_DECODE, Feature, "VP8 hardware decoding") \
47 _(VP9_HW_DECODE, Feature, "VP9 hardware decoding") \
48 _(DMABUF_SURFACE_EXPORT, Feature, "WebGL DMABuf surface export") \
49 _(REUSE_DECODER_DEVICE, Feature, "Reuse decoder device") \
50 _(BACKDROP_FILTER, Feature, "Backdrop filter") \
51 _(CANVAS_RENDERER_THREAD, Feature, "canvas renderer thread") \
52 _(ACCELERATED_CANVAS2D, Feature, "Accelerated Canvas2D") \
53 _(H264_HW_DECODE, Feature, "H.264 hardware decoding") \
54 _(AV1_HW_DECODE, Feature, "AV1 hardware decoding") \
55 _(REMOTE_CANVAS, Feature, "Remote canvas") \
56 /* Add new entries above this comment */
58 enum class Feature : uint32_t {
59 #define MAKE_ENUM(name, type, desc) name,
60 GFX_FEATURE_MAP(MAKE_ENUM)
61 #undef MAKE_ENUM
62 NumValues
65 class FeatureState {
66 friend class gfxConfig;
67 friend class GfxConfigManager; // for testing
69 public:
70 FeatureState() { Reset(); }
72 bool IsEnabled() const;
73 FeatureStatus GetValue() const;
75 void EnableByDefault();
76 void DisableByDefault(FeatureStatus aStatus, const char* aMessage,
77 const nsACString& aFailureId);
78 bool SetDefault(bool aEnable, FeatureStatus aDisableStatus,
79 const char* aDisableMessage);
80 bool InitOrUpdate(bool aEnable, FeatureStatus aDisableStatus,
81 const char* aMessage);
82 void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
83 bool aDefaultValue, Maybe<bool> aUserValue);
84 void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
85 bool aDefaultValue);
86 void UserEnable(const char* aMessage);
87 void UserForceEnable(const char* aMessage);
88 void UserDisable(const char* aMessage, const nsACString& aFailureId);
89 void Disable(FeatureStatus aStatus, const char* aMessage,
90 const nsACString& aFailureId);
91 void ForceDisable(FeatureStatus aStatus, const char* aMessage,
92 const nsACString& aFailureId) {
93 SetFailed(aStatus, aMessage, aFailureId);
95 void SetFailed(FeatureStatus aStatus, const char* aMessage,
96 const nsACString& aFailureId);
97 bool MaybeSetFailed(bool aEnable, FeatureStatus aStatus, const char* aMessage,
98 const nsACString& aFailureId);
99 bool MaybeSetFailed(FeatureStatus aStatus, const char* aMessage,
100 const nsACString& aFailureId);
102 // aType is "base", "user", "env", or "runtime".
103 // aMessage may be null.
104 typedef std::function<void(const char* aType, FeatureStatus aStatus,
105 const char* aMessage, const nsCString& aFailureId)>
106 StatusIterCallback;
107 void ForEachStatusChange(const StatusIterCallback& aCallback) const;
109 const char* GetFailureMessage() const;
110 const nsCString& GetFailureId() const;
111 nsCString GetStatusAndFailureIdString() const;
113 bool DisabledByDefault() const;
115 // Clear all state.
116 void Reset();
118 private:
119 void SetUser(FeatureStatus aStatus, const char* aMessage,
120 const nsACString& aFailureId);
121 void SetEnvironment(FeatureStatus aStatus, const char* aMessage,
122 const nsACString& aFailureId);
123 void SetRuntime(FeatureStatus aStatus, const char* aMessage,
124 const nsACString& aFailureId);
125 bool IsForcedOnByUser() const;
126 const char* GetRuntimeMessage() const;
127 bool IsInitialized() const { return mDefault.IsInitialized(); }
129 void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
131 private:
132 struct Instance {
133 char mMessage[64];
134 FeatureStatus mStatus;
135 nsCString mFailureId;
137 void Set(FeatureStatus aStatus);
138 void Set(FeatureStatus aStatus, const char* aMessage,
139 const nsACString& aFailureId);
140 bool IsInitialized() const { return mStatus != FeatureStatus::Unused; }
141 const char* MessageOrNull() const {
142 return mMessage[0] != '\0' ? mMessage : nullptr;
144 const char* Message() const {
145 MOZ_ASSERT(MessageOrNull());
146 return mMessage;
148 const nsCString& FailureId() const { return mFailureId; }
151 // The default state is the state we decide on startup, based on the operating
152 // system or a base preference.
154 // The user state factors in any changes to preferences that the user made.
156 // The environment state factors in any additional decisions made, such as
157 // availability or blocklisting.
159 // The runtime state factors in any problems discovered at runtime.
160 Instance mDefault;
161 Instance mUser;
162 Instance mEnvironment;
163 Instance mRuntime;
166 } // namespace gfx
167 } // namespace mozilla
169 #endif // mozilla_gfx_config_gfxFeature_h