/src/mozilla-central/gfx/config/gfxFeature.h
Line | Count | Source (jump to first uncovered line) |
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 |
8 | | |
9 | | #include <functional> |
10 | | #include <stdint.h> |
11 | | #include "gfxTelemetry.h" |
12 | | #include "mozilla/Assertions.h" |
13 | | #include "nsString.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace gfx { |
17 | | |
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 | | /* Add new entries above this comment */ |
32 | | |
33 | | enum class Feature : uint32_t { |
34 | | #define MAKE_ENUM(name, type, desc) name, |
35 | | GFX_FEATURE_MAP(MAKE_ENUM) |
36 | | #undef MAKE_ENUM |
37 | | NumValues |
38 | | }; |
39 | | |
40 | | class FeatureState |
41 | | { |
42 | | friend class gfxConfig; |
43 | | |
44 | | public: |
45 | | bool IsEnabled() const; |
46 | | FeatureStatus GetValue() const; |
47 | | |
48 | | void EnableByDefault(); |
49 | | void DisableByDefault(FeatureStatus aStatus, const char* aMessage, const nsACString& aFailureId); |
50 | | bool SetDefault(bool aEnable, FeatureStatus aDisableStatus, const char* aDisableMessage); |
51 | | bool InitOrUpdate(bool aEnable, |
52 | | FeatureStatus aDisableStatus, |
53 | | const char* aMessage); |
54 | | void SetDefaultFromPref(const char* aPrefName, |
55 | | bool aIsEnablePref, |
56 | | bool aDefaultValue); |
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, const nsACString& aFailureId); |
61 | | void ForceDisable(FeatureStatus aStatus, const char* aMessage, const nsACString& aFailureId) { |
62 | | SetFailed(aStatus, aMessage, aFailureId); |
63 | | } |
64 | | void SetFailed(FeatureStatus aStatus, const char* aMessage, const nsACString& aFailureId); |
65 | | bool MaybeSetFailed(bool aEnable, FeatureStatus aStatus, const char* aMessage, const nsACString& aFailureId); |
66 | | bool MaybeSetFailed(FeatureStatus aStatus, const char* aMessage, const nsACString& aFailureId); |
67 | | |
68 | | // aType is "base", "user", "env", or "runtime". |
69 | | // aMessage may be null. |
70 | | typedef std::function<void(const char* aType, |
71 | | FeatureStatus aStatus, |
72 | | const char* aMessage)> StatusIterCallback; |
73 | | void ForEachStatusChange(const StatusIterCallback& aCallback) const; |
74 | | |
75 | | const char* GetFailureMessage() const; |
76 | | const nsCString& GetFailureId() const; |
77 | | |
78 | | bool DisabledByDefault() const; |
79 | | |
80 | | private: |
81 | | void SetUser(FeatureStatus aStatus, const char* aMessage); |
82 | | void SetEnvironment(FeatureStatus aStatus, const char* aMessage); |
83 | | void SetRuntime(FeatureStatus aStatus, const char* aMessage); |
84 | | bool IsForcedOnByUser() const; |
85 | | const char* GetRuntimeMessage() const; |
86 | 0 | bool IsInitialized() const { |
87 | 0 | return mDefault.IsInitialized(); |
88 | 0 | } |
89 | | |
90 | 0 | void AssertInitialized() const { |
91 | 0 | MOZ_ASSERT(IsInitialized()); |
92 | 0 | } |
93 | | |
94 | | // Clear all state. |
95 | | void Reset(); |
96 | | |
97 | | private: |
98 | | void SetFailureId(const nsACString& aFailureId); |
99 | | |
100 | | struct Instance { |
101 | | char mMessage[64]; |
102 | | FeatureStatus mStatus; |
103 | | |
104 | | void Set(FeatureStatus aStatus, const char* aMessage = nullptr); |
105 | 0 | bool IsInitialized() const { |
106 | 0 | return mStatus != FeatureStatus::Unused; |
107 | 0 | } |
108 | 0 | const char* MessageOrNull() const { |
109 | 0 | return mMessage[0] != '\0' ? mMessage : nullptr; |
110 | 0 | } |
111 | 0 | const char* Message() const { |
112 | 0 | MOZ_ASSERT(MessageOrNull()); |
113 | 0 | return mMessage; |
114 | 0 | } |
115 | | }; |
116 | | |
117 | | // The default state is the state we decide on startup, based on the operating |
118 | | // system or a base preference. |
119 | | // |
120 | | // The user state factors in any changes to preferences that the user made. |
121 | | // |
122 | | // The environment state factors in any additional decisions made, such as |
123 | | // availability or blacklisting. |
124 | | // |
125 | | // The runtime state factors in any problems discovered at runtime. |
126 | | Instance mDefault; |
127 | | Instance mUser; |
128 | | Instance mEnvironment; |
129 | | Instance mRuntime; |
130 | | |
131 | | // Store the first reported failureId for now but we might want to track this |
132 | | // by instance later if we need a specific breakdown. |
133 | | nsCString mFailureId; |
134 | | }; |
135 | | |
136 | | } // namespace gfx |
137 | | } // namespace mozilla |
138 | | |
139 | | #endif // mozilla_gfx_config_gfxFeature_h |