Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/gfxConfig.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_gfxConfig_h
7
#define mozilla_gfx_config_gfxConfig_h
8
9
#include <functional>
10
#include "gfxFeature.h"
11
#include "gfxFallback.h"
12
#include "mozilla/Assertions.h"
13
14
namespace mozilla {
15
namespace gfx {
16
17
// Defined in GraphicsMessages.ipdlh.
18
class FeatureChange;
19
20
// Manages the history and state of a graphics feature. The flow of a feature
21
// is:
22
//   - A default value, set by all.js, gfxPrefs, or gfxPlatform.
23
//   - A user value, set by an external value or user pref.
24
//   - An environment value, determined by system/hardware factors or nsIGfxInfo.
25
//   - A runtime value, determined by any failures encountered after enabling
26
//     the feature.
27
//
28
// Each state change for a feature is recorded in this class.
29
class gfxConfig
30
{
31
public:
32
  // Return the full state history of a feature.
33
  static FeatureState& GetFeature(Feature aFeature);
34
35
  // Query whether a parameter is enabled, taking into account any user or
36
  // runtime overrides. The algorithm works as follow:
37
  //
38
  //  1. If a runtime decision disabled the feature, return false.
39
  //  2. If the user force-enabled the feature, return true.
40
  //  3. If the environment disabled the feature, return false.
41
  //  4. If the user specified a decision, return it.
42
  //  5. Return the base setting for the feature.
43
  static bool IsEnabled(Feature aFeature);
44
45
  // Query the history of a parameter. ForcedOnByUser returns whether or not
46
  // the user specifically used a "force" preference to enable the parameter.
47
  // IsDisabledByDefault returns whether or not the initial status of the
48
  // feature, before adding user prefs and runtime decisions, was disabled.
49
  static bool IsForcedOnByUser(Feature aFeature);
50
51
  // This returns true if the feature was disabled by default, or was never
52
  // initialized to begin with.
53
  static bool IsDisabledByDefault(Feature aFeature);
54
55
  // Query the status value of a parameter. This is computed similar to
56
  // IsEnabled:
57
  //
58
  //  1. If a runtime failure was set, return it.
59
  //  2. If the user force-enabled the feature, return ForceEnabled.
60
  //  3. If an environment status was set, return it.
61
  //  4. If a user status was set, return it.
62
  //  5. Return the default status.
63
  static FeatureStatus GetValue(Feature aFeature);
64
65
  // Reset the entire state of a feature.
66
  static void Reset(Feature aFeature);
67
68
  // Initialize the base value of a parameter. The return value is aEnable.
69
  static bool SetDefault(Feature aFeature,
70
                         bool aEnable,
71
                         FeatureStatus aDisableStatus,
72
                         const char* aDisableMessage);
73
  static void DisableByDefault(Feature aFeature,
74
                               FeatureStatus aDisableStatus,
75
                               const char* aDisableMessage,
76
                               const nsACString& aFailureId = EmptyCString());
77
  static void EnableByDefault(Feature aFeature);
78
79
  // Inherit a computed value from another process.
80
  static void Inherit(Feature aFeature, FeatureStatus aStatus);
81
82
  // Set a environment status that overrides both the default and user
83
  // statuses; this should be used to disable features based on system
84
  // or hardware problems that can be determined up-front. The only
85
  // status that can override this decision is the user force-enabling
86
  // the feature.
87
  static void Disable(Feature aFeature,
88
                      FeatureStatus aStatus,
89
                      const char* aMessage,
90
                      const nsACString& aFailureId = EmptyCString());
91
92
  // Given a preference name, infer the default value and whether or not the
93
  // user has changed it. |aIsEnablePref| specifies whether or not the pref
94
  // is intended to enable a feature (true), or disable it (false).
95
  static void SetDefaultFromPref(Feature aFeature,
96
                                 const char* aPrefName,
97
                                 bool aIsEnablePref,
98
                                 bool aDefaultValue);
99
100
  // Disable a parameter based on a runtime decision. This permanently
101
  // disables the feature, since runtime decisions override all other
102
  // decisions.
103
  static void SetFailed(Feature aFeature,
104
                        FeatureStatus aStatus,
105
                        const char* aMessage,
106
                        const nsACString& aFailureId = EmptyCString());
107
108
  // Force a feature to be disabled permanently. This is the same as
109
  // SetFailed(), but the name may be clearer depending on the context.
110
  static void ForceDisable(Feature aFeature,
111
                           FeatureStatus aStatus,
112
                           const char* aMessage,
113
                           const nsACString& aFailureId = EmptyCString())
114
0
  {
115
0
    SetFailed(aFeature, aStatus, aMessage, aFailureId);
116
0
  }
117
118
  // Convenience helpers for SetFailed().
119
  static bool MaybeSetFailed(Feature aFeature,
120
                             bool aEnable,
121
                             FeatureStatus aDisableStatus,
122
                             const char* aDisableMessage,
123
                             const nsACString& aFailureId = EmptyCString())
124
0
  {
125
0
    if (!aEnable) {
126
0
      SetFailed(aFeature, aDisableStatus, aDisableMessage, aFailureId);
127
0
      return false;
128
0
    }
129
0
    return true;
130
0
  }
131
132
  // Convenience helper for SetFailed().
133
  static bool MaybeSetFailed(Feature aFeature,
134
                             FeatureStatus aStatus,
135
                             const char* aDisableMessage,
136
                             const nsACString& aFailureId = EmptyCString())
137
0
  {
138
0
    return MaybeSetFailed(
139
0
      aFeature,
140
0
      (aStatus != FeatureStatus::Available &&
141
0
       aStatus != FeatureStatus::ForceEnabled),
142
0
      aStatus,
143
0
      aDisableMessage, aFailureId);
144
0
  }
145
146
  // Re-enables a feature that was previously disabled, by attaching it to a
147
  // fallback. The fallback inherits the message that was used for disabling
148
  // the feature. This can be used, for example, when D3D11 fails at runtime
149
  // but we acquire a second, successful device with WARP.
150
  static void Reenable(Feature aFeature, Fallback aFallback);
151
152
  // Same as SetDefault, except if the feature already has a default value
153
  // set, the new value will be set as a runtime value. This is useful for
154
  // when the base value can change (for example, via an update from the
155
  // parent process).
156
  static bool InitOrUpdate(Feature aFeature,
157
                           bool aEnable,
158
                           FeatureStatus aDisableStatus,
159
                           const char* aDisableMessage);
160
161
  // Set a user status that overrides the base value (but not runtime value)
162
  // of a parameter.
163
  static void UserEnable(Feature aFeature, const char* aMessage);
164
  static void UserForceEnable(Feature aFeature, const char* aMessage);
165
  static void UserDisable(Feature aFeature, const char* aMessage, const nsACString& aFailureId = EmptyCString());
166
167
  // Query whether a fallback has been toggled.
168
  static bool UseFallback(Fallback aFallback);
169
170
  // Add a log entry denoting that a given fallback had to be used. This can
171
  // be called from any thread in the UI or GPU process.
172
  static void EnableFallback(Fallback aFallback, const char* aMessage);
173
174
  // Run a callback for each initialized FeatureState.
175
  typedef std::function<void(const char* aName,
176
                             const char* aDescription,
177
                             FeatureState& aFeature)> FeatureIterCallback;
178
  static void ForEachFeature(const FeatureIterCallback& aCallback);
179
180
  // Run a callback for each enabled fallback.
181
  typedef std::function<void(const char* aName, const char* aMsg)> 
182
    FallbackIterCallback;
183
  static void ForEachFallback(const FallbackIterCallback& aCallback);
184
185
  // Get the most descriptive failure id message for this feature.
186
  static const nsCString& GetFailureId(Feature aFeature);
187
188
  static void ImportChange(Feature aFeature, const FeatureChange& aChange);
189
190
  static void Init();
191
  static void Shutdown();
192
193
private:
194
  void ForEachFallbackImpl(const FallbackIterCallback& aCallback);
195
196
private:
197
  FeatureState& GetState(Feature aFeature) {
198
    MOZ_ASSERT(size_t(aFeature) < kNumFeatures);
199
    return mFeatures[size_t(aFeature)];
200
  }
201
0
  const FeatureState& GetState(Feature aFeature) const {
202
0
    MOZ_ASSERT(size_t(aFeature) < kNumFeatures);
203
0
    return mFeatures[size_t(aFeature)];
204
0
  }
205
206
  bool UseFallbackImpl(Fallback aFallback) const;
207
  void EnableFallbackImpl(Fallback aFallback, const char* aMessage);
208
209
private:
210
  static const size_t kNumFeatures = size_t(Feature::NumValues);
211
  static const size_t kNumFallbacks = size_t(Fallback::NumValues);
212
213
private:
214
  FeatureState mFeatures[kNumFeatures];
215
  uint64_t mFallbackBits;
216
217
private:
218
  struct FallbackLogEntry {
219
    Fallback mFallback;
220
    char mMessage[80];
221
  };
222
223
  FallbackLogEntry mFallbackLog[kNumFallbacks];
224
  size_t mNumFallbackLogEntries;
225
};
226
227
} // namespace gfx
228
} // namespace mozilla
229
230
#endif // mozilla_gfx_config_gfxConfig_h