Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/config/gfxConfig.cpp
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
#include "gfxConfig.h"
7
#include "mozilla/UniquePtr.h"
8
#include "mozilla/Unused.h"
9
#include "mozilla/gfx/GPUParent.h"
10
#include "mozilla/gfx/GraphicsMessages.h"
11
#include "plstr.h"
12
13
namespace mozilla {
14
namespace gfx {
15
16
static UniquePtr<gfxConfig> sConfig;
17
18
/* static */ FeatureState&
19
gfxConfig::GetFeature(Feature aFeature)
20
0
{
21
0
  return sConfig->GetState(aFeature);
22
0
}
23
24
/* static */ bool
25
gfxConfig::IsEnabled(Feature aFeature)
26
0
{
27
0
  const FeatureState& state = sConfig->GetState(aFeature);
28
0
  return state.IsEnabled();
29
0
}
30
31
/* static */ bool
32
gfxConfig::IsDisabledByDefault(Feature aFeature)
33
0
{
34
0
  const FeatureState& state = sConfig->GetState(aFeature);
35
0
  return state.DisabledByDefault();
36
0
}
37
38
/* static */ bool
39
gfxConfig::IsForcedOnByUser(Feature aFeature)
40
0
{
41
0
  const FeatureState& state = sConfig->GetState(aFeature);
42
0
  return state.IsForcedOnByUser();
43
0
}
44
45
/* static */ FeatureStatus
46
gfxConfig::GetValue(Feature aFeature)
47
0
{
48
0
  const FeatureState& state = sConfig->GetState(aFeature);
49
0
  return state.GetValue();
50
0
}
51
52
/* static */ bool
53
gfxConfig::SetDefault(Feature aFeature,
54
                      bool aEnable,
55
                      FeatureStatus aDisableStatus,
56
                      const char* aDisableMessage)
57
0
{
58
0
  FeatureState& state = sConfig->GetState(aFeature);
59
0
  return state.SetDefault(aEnable, aDisableStatus, aDisableMessage);
60
0
}
61
62
/* static */ void
63
gfxConfig::DisableByDefault(Feature aFeature,
64
                            FeatureStatus aDisableStatus,
65
                            const char* aDisableMessage,
66
                            const nsACString& aFailureId)
67
0
{
68
0
  FeatureState& state = sConfig->GetState(aFeature);
69
0
  state.DisableByDefault(aDisableStatus, aDisableMessage, aFailureId);
70
0
}
71
72
/* static */ void
73
gfxConfig::EnableByDefault(Feature aFeature)
74
0
{
75
0
  FeatureState& state = sConfig->GetState(aFeature);
76
0
  state.EnableByDefault();
77
0
}
78
79
/* static */ void
80
gfxConfig::SetDefaultFromPref(Feature aFeature,
81
                              const char* aPrefName,
82
                              bool aIsEnablePref,
83
                              bool aDefaultValue)
84
0
{
85
0
  FeatureState& state = sConfig->GetState(aFeature);
86
0
  return state.SetDefaultFromPref(aPrefName, aIsEnablePref, aDefaultValue);
87
0
}
88
89
/* static */ bool
90
gfxConfig::InitOrUpdate(Feature aFeature,
91
                        bool aEnable,
92
                        FeatureStatus aDisableStatus,
93
                        const char* aDisableMessage)
94
0
{
95
0
  FeatureState& state = sConfig->GetState(aFeature);
96
0
  return state.InitOrUpdate(aEnable, aDisableStatus, aDisableMessage);
97
0
}
98
99
/* static */ void
100
gfxConfig::SetFailed(Feature aFeature, FeatureStatus aStatus, const char* aMessage,
101
                     const nsACString& aFailureId)
102
0
{
103
0
  FeatureState& state = sConfig->GetState(aFeature);
104
0
  state.SetFailed(aStatus, aMessage, aFailureId);
105
0
}
106
107
/* static */ void
108
gfxConfig::Disable(Feature aFeature, FeatureStatus aStatus, const char* aMessage,
109
                   const nsACString& aFailureId)
110
0
{
111
0
  FeatureState& state = sConfig->GetState(aFeature);
112
0
  state.Disable(aStatus, aMessage, aFailureId);
113
0
}
114
115
/* static */ void
116
gfxConfig::UserEnable(Feature aFeature, const char* aMessage)
117
0
{
118
0
  FeatureState& state = sConfig->GetState(aFeature);
119
0
  state.UserEnable(aMessage);
120
0
}
121
122
/* static */ void
123
gfxConfig::UserForceEnable(Feature aFeature, const char* aMessage)
124
0
{
125
0
  FeatureState& state = sConfig->GetState(aFeature);
126
0
  state.UserForceEnable(aMessage);
127
0
}
128
129
/* static */ void
130
gfxConfig::UserDisable(Feature aFeature, const char* aMessage, const nsACString& aFailureId)
131
0
{
132
0
  FeatureState& state = sConfig->GetState(aFeature);
133
0
  state.UserDisable(aMessage, aFailureId);
134
0
}
135
136
/* static */ void
137
gfxConfig::Reenable(Feature aFeature, Fallback aFallback)
138
0
{
139
0
  FeatureState& state = sConfig->GetState(aFeature);
140
0
  MOZ_ASSERT(IsFeatureStatusFailure(state.GetValue()));
141
0
142
0
  const char* message = state.GetRuntimeMessage();
143
0
  EnableFallback(aFallback, message);
144
0
  state.SetRuntime(FeatureStatus::Available, nullptr);
145
0
}
146
147
/* static */ void
148
gfxConfig::Reset(Feature aFeature)
149
0
{
150
0
  FeatureState& state = sConfig->GetState(aFeature);
151
0
  state.Reset();
152
0
}
153
154
/* static */ void
155
gfxConfig::Inherit(Feature aFeature, FeatureStatus aStatus)
156
{
157
  FeatureState& state = sConfig->GetState(aFeature);
158
159
  state.Reset();
160
161
  switch (aStatus) {
162
  case FeatureStatus::Unused:
163
    break;
164
  case FeatureStatus::Available:
165
    gfxConfig::EnableByDefault(aFeature);
166
    break;
167
  case FeatureStatus::ForceEnabled:
168
    gfxConfig::EnableByDefault(aFeature);
169
    gfxConfig::UserForceEnable(aFeature, "Inherited from parent process");
170
    break;
171
  default:
172
    gfxConfig::SetDefault(
173
      aFeature,
174
      false,
175
      aStatus,
176
      "Disabled in parent process");
177
    break;
178
  }
179
}
180
181
/* static */ bool
182
gfxConfig::UseFallback(Fallback aFallback)
183
0
{
184
0
  return sConfig->UseFallbackImpl(aFallback);
185
0
}
186
187
/* static */ void
188
gfxConfig::EnableFallback(Fallback aFallback, const char* aMessage)
189
0
{
190
0
  if (!NS_IsMainThread()) {
191
0
    nsCString message(aMessage);
192
0
    NS_DispatchToMainThread(
193
0
      NS_NewRunnableFunction("gfxConfig::EnableFallback",
194
0
                             [=]() -> void {
195
0
196
0
        gfxConfig::EnableFallback(aFallback, message.get());
197
0
      }));
198
0
    return;
199
0
  }
200
0
201
0
  if (XRE_IsGPUProcess()) {
202
0
    nsCString message(aMessage);
203
0
    Unused << GPUParent::GetSingleton()->SendUsedFallback(aFallback, message);
204
0
    return;
205
0
  }
206
0
207
0
  sConfig->EnableFallbackImpl(aFallback, aMessage);
208
0
}
209
210
bool
211
gfxConfig::UseFallbackImpl(Fallback aFallback) const
212
0
{
213
0
  return !!(mFallbackBits & (uint64_t(1) << uint64_t(aFallback)));
214
0
}
215
216
void
217
gfxConfig::EnableFallbackImpl(Fallback aFallback, const char* aMessage)
218
0
{
219
0
  if (!UseFallbackImpl(aFallback)) {
220
0
    MOZ_ASSERT(mNumFallbackLogEntries < kNumFallbacks);
221
0
222
0
    FallbackLogEntry& entry = mFallbackLog[mNumFallbackLogEntries];
223
0
    mNumFallbackLogEntries++;
224
0
225
0
    entry.mFallback = aFallback;
226
0
    PL_strncpyz(entry.mMessage, aMessage, sizeof(entry.mMessage));
227
0
  }
228
0
  mFallbackBits |= (uint64_t(1) << uint64_t(aFallback));
229
0
}
230
231
struct FeatureInfo {
232
  const char* name;
233
  const char* description;
234
};
235
static const FeatureInfo sFeatureInfo[] = {
236
#define FOR_EACH_FEATURE(name, type, desc) {#name, desc},
237
  GFX_FEATURE_MAP(FOR_EACH_FEATURE)
238
#undef FOR_EACH_FEATURE
239
  {nullptr, nullptr}
240
};
241
242
/* static */ void
243
gfxConfig::ForEachFeature(const FeatureIterCallback& aCallback)
244
0
{
245
0
  for (size_t i = 0; i < kNumFeatures; i++) {
246
0
    FeatureState& state = GetFeature(static_cast<Feature>(i));
247
0
    if (!state.IsInitialized()) {
248
0
      continue;
249
0
    }
250
0
251
0
    aCallback(sFeatureInfo[i].name,
252
0
              sFeatureInfo[i].description,
253
0
              state);
254
0
  }
255
0
}
256
257
static const char* sFallbackNames[] = {
258
#define FOR_EACH_FALLBACK(name) #name,
259
  GFX_FALLBACK_MAP(FOR_EACH_FALLBACK)
260
#undef FOR_EACH_FALLBACK
261
  nullptr
262
};
263
264
/* static  */ void
265
gfxConfig::ForEachFallback(const FallbackIterCallback& aCallback)
266
0
{
267
0
  sConfig->ForEachFallbackImpl(aCallback);
268
0
}
269
270
void
271
gfxConfig::ForEachFallbackImpl(const FallbackIterCallback& aCallback)
272
0
{
273
0
  for (size_t i = 0; i < mNumFallbackLogEntries; i++) {
274
0
    const FallbackLogEntry& entry = mFallbackLog[i];
275
0
    aCallback(sFallbackNames[size_t(entry.mFallback)], entry.mMessage);
276
0
  }
277
0
}
278
279
/* static */ const nsCString&
280
gfxConfig::GetFailureId(Feature aFeature)
281
0
{
282
0
  const FeatureState& state = sConfig->GetState(aFeature);
283
0
  return state.GetFailureId();
284
0
}
285
286
/* static */ void
287
gfxConfig::ImportChange(Feature aFeature, const FeatureChange& aChange)
288
0
{
289
0
  if (aChange.type() == FeatureChange::Tnull_t) {
290
0
    return;
291
0
  }
292
0
293
0
  const FeatureFailure& failure = aChange.get_FeatureFailure();
294
0
  gfxConfig::SetFailed(
295
0
    aFeature,
296
0
    failure.status(),
297
0
    failure.message().get(),
298
0
    failure.failureId());
299
0
}
300
301
/* static */ void
302
gfxConfig::Init()
303
0
{
304
0
  sConfig = mozilla::MakeUnique<gfxConfig>();
305
0
}
306
307
/* static */ void
308
gfxConfig::Shutdown()
309
0
{
310
0
  sConfig = nullptr;
311
0
}
312
313
} // namespace gfx
314
} // namespace mozilla