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