Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/GfxInfoBase.cpp
Line
Count
Source (jump to first uncovered line)
1
/* vim: se cin sw=2 ts=2 et : */
2
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
 *
4
 * This Source Code Form is subject to the terms of the Mozilla Public
5
 * License, v. 2.0. If a copy of the MPL was not distributed with this
6
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8
#include "mozilla/ArrayUtils.h"
9
10
#include "GfxInfoBase.h"
11
12
#include "GfxDriverInfo.h"
13
#include "nsCOMPtr.h"
14
#include "nsCOMArray.h"
15
#include "nsString.h"
16
#include "nsUnicharUtils.h"
17
#include "nsVersionComparator.h"
18
#include "mozilla/Services.h"
19
#include "mozilla/Observer.h"
20
#include "nsIObserver.h"
21
#include "nsIObserverService.h"
22
#include "nsTArray.h"
23
#include "nsXULAppAPI.h"
24
#include "nsIXULAppInfo.h"
25
#include "mozilla/Preferences.h"
26
#include "mozilla/dom/ContentChild.h"
27
#include "mozilla/gfx/2D.h"
28
#include "mozilla/gfx/GPUProcessManager.h"
29
#include "mozilla/gfx/Logging.h"
30
#include "mozilla/gfx/gfxVars.h"
31
#include "mozilla/layers/PaintThread.h"
32
#include "gfxPrefs.h"
33
#include "gfxPlatform.h"
34
#include "gfxConfig.h"
35
#include "DriverCrashGuard.h"
36
37
using namespace mozilla::widget;
38
using namespace mozilla;
39
using mozilla::MutexAutoLock;
40
41
nsTArray<GfxDriverInfo>* GfxInfoBase::sDriverInfo;
42
nsTArray<dom::GfxInfoFeatureStatus>* GfxInfoBase::sFeatureStatus;
43
bool GfxInfoBase::sDriverInfoObserverInitialized;
44
bool GfxInfoBase::sShutdownOccurred;
45
46
// Observes for shutdown so that the child GfxDriverInfo list is freed.
47
class ShutdownObserver : public nsIObserver
48
{
49
0
  virtual ~ShutdownObserver() {}
50
51
public:
52
0
  ShutdownObserver() {}
53
54
  NS_DECL_ISUPPORTS
55
56
  NS_IMETHOD Observe(nsISupports *subject, const char *aTopic,
57
                     const char16_t *aData) override
58
0
  {
59
0
    MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
60
0
61
0
    delete GfxInfoBase::sDriverInfo;
62
0
    GfxInfoBase::sDriverInfo = nullptr;
63
0
64
0
    delete GfxInfoBase::sFeatureStatus;
65
0
    GfxInfoBase::sFeatureStatus = nullptr;
66
0
67
0
    for (uint32_t i = 0; i < DeviceFamilyMax; i++) {
68
0
      delete GfxDriverInfo::sDeviceFamilies[i];
69
0
      GfxDriverInfo::sDeviceFamilies[i] = nullptr;
70
0
    }
71
0
72
0
    for (uint32_t i = 0; i < DeviceVendorMax; i++) {
73
0
      delete GfxDriverInfo::sDeviceVendors[i];
74
0
      GfxDriverInfo::sDeviceVendors[i] = nullptr;
75
0
    }
76
0
77
0
    GfxInfoBase::sShutdownOccurred = true;
78
0
79
0
    return NS_OK;
80
0
  }
81
};
82
83
NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
84
85
void InitGfxDriverInfoShutdownObserver()
86
0
{
87
0
  if (GfxInfoBase::sDriverInfoObserverInitialized)
88
0
    return;
89
0
90
0
  GfxInfoBase::sDriverInfoObserverInitialized = true;
91
0
92
0
  nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
93
0
  if (!observerService) {
94
0
    NS_WARNING("Could not get observer service!");
95
0
    return;
96
0
  }
97
0
98
0
  ShutdownObserver *obs = new ShutdownObserver();
99
0
  observerService->AddObserver(obs, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
100
0
}
101
102
using namespace mozilla::widget;
103
using namespace mozilla::gfx;
104
using namespace mozilla;
105
106
NS_IMPL_ISUPPORTS(GfxInfoBase, nsIGfxInfo, nsIObserver, nsISupportsWeakReference)
107
108
0
#define BLACKLIST_PREF_BRANCH "gfx.blacklist."
109
0
#define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
110
#define BLACKLIST_ENTRY_TAG_NAME "gfxBlacklistEntry"
111
112
static const char*
113
GetPrefNameForFeature(int32_t aFeature)
114
0
{
115
0
  const char* name = nullptr;
116
0
  switch(aFeature) {
117
0
    case nsIGfxInfo::FEATURE_DIRECT2D:
118
0
      name = BLACKLIST_PREF_BRANCH "direct2d";
119
0
      break;
120
0
    case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
121
0
      name = BLACKLIST_PREF_BRANCH "layers.direct3d9";
122
0
      break;
123
0
    case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
124
0
      name = BLACKLIST_PREF_BRANCH "layers.direct3d10";
125
0
      break;
126
0
    case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
127
0
      name = BLACKLIST_PREF_BRANCH "layers.direct3d10-1";
128
0
      break;
129
0
    case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS:
130
0
      name = BLACKLIST_PREF_BRANCH "layers.direct3d11";
131
0
      break;
132
0
    case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE:
133
0
      name = BLACKLIST_PREF_BRANCH "direct3d11angle";
134
0
      break;
135
0
    case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING:
136
0
      name = BLACKLIST_PREF_BRANCH "hardwarevideodecoding";
137
0
      break;
138
0
    case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
139
0
      name = BLACKLIST_PREF_BRANCH "layers.opengl";
140
0
      break;
141
0
    case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
142
0
      name = BLACKLIST_PREF_BRANCH "webgl.opengl";
143
0
      break;
144
0
    case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
145
0
      name = BLACKLIST_PREF_BRANCH "webgl.angle";
146
0
      break;
147
0
    case nsIGfxInfo::FEATURE_WEBGL_MSAA:
148
0
      name = BLACKLIST_PREF_BRANCH "webgl.msaa";
149
0
      break;
150
0
    case nsIGfxInfo::FEATURE_STAGEFRIGHT:
151
0
      name = BLACKLIST_PREF_BRANCH "stagefright";
152
0
      break;
153
0
    case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION:
154
0
      name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration";
155
0
      break;
156
0
    case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE:
157
0
      name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.encode";
158
0
      break;
159
0
    case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE:
160
0
      name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.decode";
161
0
      break;
162
0
    case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION:
163
0
      name = BLACKLIST_PREF_BRANCH "canvas2d.acceleration";
164
0
      break;
165
0
    case nsIGfxInfo::FEATURE_DX_INTEROP2:
166
0
      name = BLACKLIST_PREF_BRANCH "dx.interop2";
167
0
      break;
168
0
    case nsIGfxInfo::FEATURE_GPU_PROCESS:
169
0
      name = BLACKLIST_PREF_BRANCH "gpu.process";
170
0
      break;
171
0
    case nsIGfxInfo::FEATURE_WEBGL2:
172
0
      name = BLACKLIST_PREF_BRANCH "webgl2";
173
0
      break;
174
0
    case nsIGfxInfo::FEATURE_ADVANCED_LAYERS:
175
0
      name = BLACKLIST_PREF_BRANCH "layers.advanced";
176
0
      break;
177
0
    case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX:
178
0
      name = BLACKLIST_PREF_BRANCH "d3d11.keyed.mutex";
179
0
      break;
180
0
    case nsIGfxInfo::FEATURE_WEBRENDER:
181
0
      name = BLACKLIST_PREF_BRANCH "webrender";
182
0
      break;
183
0
    case nsIGfxInfo::FEATURE_DX_NV12:
184
0
      name = BLACKLIST_PREF_BRANCH "dx.nv12";
185
0
      break;
186
0
    case nsIGfxInfo::FEATURE_VP8_HW_DECODE:
187
0
    case nsIGfxInfo::FEATURE_VP9_HW_DECODE:
188
0
      // We don't provide prefs for these features as these are
189
0
      // not handling downloadable blocklist.
190
0
      break;
191
0
    default:
192
0
      MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
193
0
      break;
194
0
  }
195
0
196
0
  return name;
197
0
}
198
199
// Returns the value of the pref for the relevant feature in aValue.
200
// If the pref doesn't exist, aValue is not touched, and returns false.
201
static bool
202
GetPrefValueForFeature(int32_t aFeature, int32_t& aValue, nsACString& aFailureId)
203
0
{
204
0
  const char *prefname = GetPrefNameForFeature(aFeature);
205
0
  if (!prefname)
206
0
    return false;
207
0
208
0
  aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
209
0
  if (!NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue))) {
210
0
    return false;
211
0
  }
212
0
213
0
  nsCString failureprefname(prefname);
214
0
  failureprefname += ".failureid";
215
0
  nsAutoCString failureValue;
216
0
  nsresult rv = Preferences::GetCString(failureprefname.get(), failureValue);
217
0
  if (NS_SUCCEEDED(rv)) {
218
0
    aFailureId = failureValue.get();
219
0
  } else {
220
0
    aFailureId = "FEATURE_FAILURE_BLACKLIST_PREF";
221
0
  }
222
0
223
0
  return true;
224
0
}
225
226
static void
227
SetPrefValueForFeature(int32_t aFeature, int32_t aValue, const nsACString& aFailureId)
228
0
{
229
0
  const char *prefname = GetPrefNameForFeature(aFeature);
230
0
  if (!prefname)
231
0
    return;
232
0
233
0
  Preferences::SetInt(prefname, aValue);
234
0
  if (!aFailureId.IsEmpty()) {
235
0
    nsCString failureprefname(prefname);
236
0
    failureprefname += ".failureid";
237
0
    Preferences::SetCString(failureprefname.get(), aFailureId);
238
0
  }
239
0
}
240
241
static void
242
RemovePrefForFeature(int32_t aFeature)
243
0
{
244
0
  const char *prefname = GetPrefNameForFeature(aFeature);
245
0
  if (!prefname)
246
0
    return;
247
0
248
0
  Preferences::ClearUser(prefname);
249
0
}
250
251
static bool
252
GetPrefValueForDriverVersion(nsCString& aVersion)
253
0
{
254
0
  return NS_SUCCEEDED(Preferences::GetCString(SUGGESTED_VERSION_PREF,
255
0
                                              aVersion));
256
0
}
257
258
static void
259
SetPrefValueForDriverVersion(const nsAString& aVersion)
260
0
{
261
0
  Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion);
262
0
}
263
264
static void
265
RemovePrefForDriverVersion()
266
0
{
267
0
  Preferences::ClearUser(SUGGESTED_VERSION_PREF);
268
0
}
269
270
271
static OperatingSystem
272
BlacklistOSToOperatingSystem(const nsAString& os)
273
0
{
274
0
  if (os.EqualsLiteral("WINNT 6.1"))
275
0
    return OperatingSystem::Windows7;
276
0
  else if (os.EqualsLiteral("WINNT 6.2"))
277
0
    return OperatingSystem::Windows8;
278
0
  else if (os.EqualsLiteral("WINNT 6.3"))
279
0
    return OperatingSystem::Windows8_1;
280
0
  else if (os.EqualsLiteral("WINNT 10.0"))
281
0
    return OperatingSystem::Windows10;
282
0
  else if (os.EqualsLiteral("Linux"))
283
0
    return OperatingSystem::Linux;
284
0
  else if (os.EqualsLiteral("Darwin 9"))
285
0
    return OperatingSystem::OSX10_5;
286
0
  else if (os.EqualsLiteral("Darwin 10"))
287
0
    return OperatingSystem::OSX10_6;
288
0
  else if (os.EqualsLiteral("Darwin 11"))
289
0
    return OperatingSystem::OSX10_7;
290
0
  else if (os.EqualsLiteral("Darwin 12"))
291
0
    return OperatingSystem::OSX10_8;
292
0
  else if (os.EqualsLiteral("Darwin 13"))
293
0
    return OperatingSystem::OSX10_9;
294
0
  else if (os.EqualsLiteral("Darwin 14"))
295
0
    return OperatingSystem::OSX10_10;
296
0
  else if (os.EqualsLiteral("Darwin 15"))
297
0
    return OperatingSystem::OSX10_11;
298
0
  else if (os.EqualsLiteral("Darwin 16"))
299
0
    return OperatingSystem::OSX10_12;
300
0
  else if (os.EqualsLiteral("Darwin 17"))
301
0
    return OperatingSystem::OSX10_13;
302
0
  else if (os.EqualsLiteral("Android"))
303
0
    return OperatingSystem::Android;
304
0
  // For historical reasons, "All" in blocklist means "All Windows"
305
0
  else if (os.EqualsLiteral("All"))
306
0
    return OperatingSystem::Windows;
307
0
308
0
  return OperatingSystem::Unknown;
309
0
}
310
311
static GfxDeviceFamily*
312
BlacklistDevicesToDeviceFamily(nsTArray<nsCString>& devices)
313
0
{
314
0
  if (devices.Length() == 0)
315
0
    return nullptr;
316
0
317
0
  // For each device, get its device ID, and return a freshly-allocated
318
0
  // GfxDeviceFamily with the contents of that array.
319
0
  GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
320
0
321
0
  for (uint32_t i = 0; i < devices.Length(); ++i) {
322
0
    // We make sure we don't add any "empty" device entries to the array, so
323
0
    // we don't need to check if devices[i] is empty.
324
0
    deviceIds->AppendElement(NS_ConvertUTF8toUTF16(devices[i]));
325
0
  }
326
0
327
0
  return deviceIds;
328
0
}
329
330
static int32_t
331
BlacklistFeatureToGfxFeature(const nsAString& aFeature)
332
0
{
333
0
  MOZ_ASSERT(!aFeature.IsEmpty());
334
0
  if (aFeature.EqualsLiteral("DIRECT2D"))
335
0
    return nsIGfxInfo::FEATURE_DIRECT2D;
336
0
  else if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS"))
337
0
    return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
338
0
  else if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS"))
339
0
    return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
340
0
  else if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
341
0
    return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
342
0
  else if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS"))
343
0
    return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
344
0
  else if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE"))
345
0
    return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
346
0
  else if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
347
0
    return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
348
0
  else if (aFeature.EqualsLiteral("OPENGL_LAYERS"))
349
0
    return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
350
0
  else if (aFeature.EqualsLiteral("WEBGL_OPENGL"))
351
0
    return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
352
0
  else if (aFeature.EqualsLiteral("WEBGL_ANGLE"))
353
0
    return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
354
0
  else if (aFeature.EqualsLiteral("WEBGL_MSAA"))
355
0
    return nsIGfxInfo::FEATURE_WEBGL_MSAA;
356
0
  else if (aFeature.EqualsLiteral("STAGEFRIGHT"))
357
0
    return nsIGfxInfo::FEATURE_STAGEFRIGHT;
358
0
  else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
359
0
    return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
360
0
  else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
361
0
    return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
362
0
  else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION"))
363
0
    return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION;
364
0
  else if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION"))
365
0
      return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
366
0
  else if (aFeature.EqualsLiteral("DX_INTEROP2"))
367
0
    return nsIGfxInfo::FEATURE_DX_INTEROP2;
368
0
  else if (aFeature.EqualsLiteral("GPU_PROCESS"))
369
0
    return nsIGfxInfo::FEATURE_GPU_PROCESS;
370
0
  else if (aFeature.EqualsLiteral("WEBGL2"))
371
0
    return nsIGfxInfo::FEATURE_WEBGL2;
372
0
  else if (aFeature.EqualsLiteral("ADVANCED_LAYERS"))
373
0
    return nsIGfxInfo::FEATURE_ADVANCED_LAYERS;
374
0
  else if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX"))
375
0
    return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
376
0
  else if (aFeature.EqualsLiteral("WEBRENDER"))
377
0
    return nsIGfxInfo::FEATURE_WEBRENDER;
378
0
  else if (aFeature.EqualsLiteral("DX_NV12"))
379
0
    return nsIGfxInfo::FEATURE_DX_NV12;
380
0
  // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
381
0
  // in downloadable blocklist.
382
0
383
0
  // If we don't recognize the feature, it may be new, and something
384
0
  // this version doesn't understand.  So, nothing to do.  This is
385
0
  // different from feature not being specified at all, in which case
386
0
  // this method should not get called and we should continue with the
387
0
  // "all features" blocklisting.
388
0
  return -1;
389
0
}
390
391
static int32_t
392
BlacklistFeatureStatusToGfxFeatureStatus(const nsAString& aStatus)
393
0
{
394
0
  if (aStatus.EqualsLiteral("STATUS_OK"))
395
0
    return nsIGfxInfo::FEATURE_STATUS_OK;
396
0
  else if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
397
0
    return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
398
0
  else if (aStatus.EqualsLiteral("BLOCKED_DEVICE"))
399
0
    return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
400
0
  else if (aStatus.EqualsLiteral("DISCOURAGED"))
401
0
    return nsIGfxInfo::FEATURE_DISCOURAGED;
402
0
  else if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION"))
403
0
    return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
404
0
405
0
  // Do not allow it to set STATUS_UNKNOWN.  Also, we are not
406
0
  // expecting the "mismatch" status showing up here.
407
0
408
0
  return nsIGfxInfo::FEATURE_STATUS_OK;
409
0
}
410
411
static VersionComparisonOp
412
BlacklistComparatorToComparisonOp(const nsAString& op)
413
0
{
414
0
  if (op.EqualsLiteral("LESS_THAN"))
415
0
    return DRIVER_LESS_THAN;
416
0
  else if (op.EqualsLiteral("BUILD_ID_LESS_THAN"))
417
0
    return DRIVER_BUILD_ID_LESS_THAN;
418
0
  else if (op.EqualsLiteral("LESS_THAN_OR_EQUAL"))
419
0
    return DRIVER_LESS_THAN_OR_EQUAL;
420
0
  else if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
421
0
    return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL;
422
0
  else if (op.EqualsLiteral("GREATER_THAN"))
423
0
    return DRIVER_GREATER_THAN;
424
0
  else if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
425
0
    return DRIVER_GREATER_THAN_OR_EQUAL;
426
0
  else if (op.EqualsLiteral("EQUAL"))
427
0
    return DRIVER_EQUAL;
428
0
  else if (op.EqualsLiteral("NOT_EQUAL"))
429
0
    return DRIVER_NOT_EQUAL;
430
0
  else if (op.EqualsLiteral("BETWEEN_EXCLUSIVE"))
431
0
    return DRIVER_BETWEEN_EXCLUSIVE;
432
0
  else if (op.EqualsLiteral("BETWEEN_INCLUSIVE"))
433
0
    return DRIVER_BETWEEN_INCLUSIVE;
434
0
  else if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
435
0
    return DRIVER_BETWEEN_INCLUSIVE_START;
436
0
437
0
  return DRIVER_COMPARISON_IGNORED;
438
0
}
439
440
441
/*
442
  Deserialize Blacklist entries from string.
443
  e.g:
444
  os:WINNT 6.0\tvendor:0x8086\tdevices:0x2582,0x2782\tfeature:DIRECT3D_10_LAYERS\tfeatureStatus:BLOCKED_DRIVER_VERSION\tdriverVersion:8.52.322.2202\tdriverVersionComparator:LESS_THAN_OR_EQUAL
445
*/
446
static bool
447
BlacklistEntryToDriverInfo(nsCString& aBlacklistEntry,
448
                           GfxDriverInfo& aDriverInfo)
449
0
{
450
0
  // If we get an application version to be zero, something is not working
451
0
  // and we are not going to bother checking the blocklist versions.
452
0
  // See TestGfxWidgets.cpp for how version comparison works.
453
0
  // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
454
0
  static mozilla::Version zeroV("0");
455
0
  static mozilla::Version appV(GfxInfoBase::GetApplicationVersion().get());
456
0
  if (appV <= zeroV) {
457
0
      gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false)) << "Invalid application version " << GfxInfoBase::GetApplicationVersion().get();
458
0
  }
459
0
460
0
  nsTArray<nsCString> keyValues;
461
0
  ParseString(aBlacklistEntry, '\t', keyValues);
462
0
463
0
  aDriverInfo.mRuleId = NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_NO_ID");
464
0
465
0
  for (uint32_t i = 0; i < keyValues.Length(); ++i) {
466
0
    nsCString keyValue = keyValues[i];
467
0
    nsTArray<nsCString> splitted;
468
0
    ParseString(keyValue, ':', splitted);
469
0
    if (splitted.Length() != 2) {
470
0
      // If we don't recognize the input data, we do not want to proceed.
471
0
      gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false)) << "Unrecognized data " << keyValue.get();
472
0
      return false;
473
0
    }
474
0
    nsCString key = splitted[0];
475
0
    nsCString value = splitted[1];
476
0
    NS_ConvertUTF8toUTF16 dataValue(value);
477
0
478
0
    if (value.Length() == 0) {
479
0
      // Safety check for empty values.
480
0
      gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false)) << "Empty value for " << key.get();
481
0
      return false;
482
0
    }
483
0
484
0
    if (key.EqualsLiteral("blockID")) {
485
0
       nsCString blockIdStr = NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_") + value;
486
0
       aDriverInfo.mRuleId = blockIdStr.get();
487
0
    } else if (key.EqualsLiteral("os")) {
488
0
      aDriverInfo.mOperatingSystem = BlacklistOSToOperatingSystem(dataValue);
489
0
    } else if (key.EqualsLiteral("osversion")) {
490
0
      aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
491
0
    } else if (key.EqualsLiteral("vendor")) {
492
0
      aDriverInfo.mAdapterVendor = dataValue;
493
0
    } else if (key.EqualsLiteral("feature")) {
494
0
      aDriverInfo.mFeature = BlacklistFeatureToGfxFeature(dataValue);
495
0
      if (aDriverInfo.mFeature < 0) {
496
0
        // If we don't recognize the feature, we do not want to proceed.
497
0
        gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false)) << "Unrecognized feature " << value.get();
498
0
        return false;
499
0
      }
500
0
    } else if (key.EqualsLiteral("featureStatus")) {
501
0
      aDriverInfo.mFeatureStatus = BlacklistFeatureStatusToGfxFeatureStatus(dataValue);
502
0
    } else if (key.EqualsLiteral("driverVersion")) {
503
0
      uint64_t version;
504
0
      if (ParseDriverVersion(dataValue, &version))
505
0
        aDriverInfo.mDriverVersion = version;
506
0
    } else if (key.EqualsLiteral("driverVersionMax")) {
507
0
      uint64_t version;
508
0
      if (ParseDriverVersion(dataValue, &version))
509
0
        aDriverInfo.mDriverVersionMax = version;
510
0
    } else if (key.EqualsLiteral("driverVersionComparator")) {
511
0
      aDriverInfo.mComparisonOp = BlacklistComparatorToComparisonOp(dataValue);
512
0
    } else if (key.EqualsLiteral("model")) {
513
0
      aDriverInfo.mModel = dataValue;
514
0
    } else if (key.EqualsLiteral("product")) {
515
0
      aDriverInfo.mProduct = dataValue;
516
0
    } else if (key.EqualsLiteral("manufacturer")) {
517
0
      aDriverInfo.mManufacturer = dataValue;
518
0
    } else if (key.EqualsLiteral("hardware")) {
519
0
      aDriverInfo.mHardware = dataValue;
520
0
    } else if (key.EqualsLiteral("versionRange")) {
521
0
      nsTArray<nsCString> versionRange;
522
0
      ParseString(value, ',', versionRange);
523
0
      if (versionRange.Length() != 2) {
524
0
        gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false)) << "Unrecognized versionRange " << value.get();
525
0
        return false;
526
0
      }
527
0
      nsCString minValue = versionRange[0];
528
0
      nsCString maxValue = versionRange[1];
529
0
530
0
      mozilla::Version minV(minValue.get());
531
0
      mozilla::Version maxV(maxValue.get());
532
0
533
0
      if (minV > zeroV && !(appV >= minV)) {
534
0
        // The version of the application is less than the minimal version
535
0
        // this blocklist entry applies to, so we can just ignore it by
536
0
        // returning false and letting the caller deal with it.
537
0
        return false;
538
0
      }
539
0
      if (maxV > zeroV && !(appV <= maxV)) {
540
0
        // The version of the application is more than the maximal version
541
0
        // this blocklist entry applies to, so we can just ignore it by
542
0
        // returning false and letting the caller deal with it.
543
0
        return false;
544
0
      }
545
0
    } else if (key.EqualsLiteral("devices")) {
546
0
      nsTArray<nsCString> devices;
547
0
      ParseString(value, ',', devices);
548
0
      GfxDeviceFamily* deviceIds = BlacklistDevicesToDeviceFamily(devices);
549
0
      if (deviceIds) {
550
0
        // Get GfxDriverInfo to adopt the devices array we created.
551
0
        aDriverInfo.mDeleteDevices = true;
552
0
        aDriverInfo.mDevices = deviceIds;
553
0
      }
554
0
    }
555
0
    // We explicitly ignore unknown elements.
556
0
  }
557
0
558
0
  return true;
559
0
}
560
561
static void
562
BlacklistEntriesToDriverInfo(nsTArray<nsCString>& aBlacklistEntries,
563
                             nsTArray<GfxDriverInfo>& aDriverInfo)
564
0
{
565
0
  aDriverInfo.Clear();
566
0
  aDriverInfo.SetLength(aBlacklistEntries.Length());
567
0
568
0
  for (uint32_t i = 0; i < aBlacklistEntries.Length(); ++i) {
569
0
    nsCString blacklistEntry = aBlacklistEntries[i];
570
0
    GfxDriverInfo di;
571
0
    if (BlacklistEntryToDriverInfo(blacklistEntry, di)) {
572
0
      aDriverInfo[i] = di;
573
0
      // Prevent di falling out of scope from destroying the devices.
574
0
      di.mDeleteDevices = false;
575
0
    }
576
0
  }
577
0
}
578
579
NS_IMETHODIMP
580
GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
581
                     const char16_t* aData)
582
0
{
583
0
  if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
584
0
    nsTArray<GfxDriverInfo> driverInfo;
585
0
    nsTArray<nsCString> blacklistEntries;
586
0
    nsCString utf8Data = NS_ConvertUTF16toUTF8(aData);
587
0
    if (utf8Data.Length() > 0) {
588
0
      ParseString(utf8Data, '\n', blacklistEntries);
589
0
    }
590
0
    BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
591
0
    EvaluateDownloadedBlacklist(driverInfo);
592
0
  }
593
0
594
0
  return NS_OK;
595
0
}
596
597
GfxInfoBase::GfxInfoBase()
598
    : mMutex("GfxInfoBase")
599
0
{
600
0
}
601
602
GfxInfoBase::~GfxInfoBase()
603
0
{
604
0
}
605
606
nsresult
607
GfxInfoBase::Init()
608
0
{
609
0
  InitGfxDriverInfoShutdownObserver();
610
0
  gfxPrefs::GetSingleton();
611
0
612
0
  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
613
0
  if (os) {
614
0
    os->AddObserver(this, "blocklist-data-gfxItems", true);
615
0
  }
616
0
617
0
  return NS_OK;
618
0
}
619
620
NS_IMETHODIMP
621
GfxInfoBase::GetFeatureStatus(int32_t aFeature, nsACString& aFailureId, int32_t* aStatus)
622
0
{
623
0
  int32_t blocklistAll = gfxPrefs::BlocklistAll();
624
0
  if (blocklistAll > 0) {
625
0
    gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false)) << "Forcing blocklisting all features";
626
0
    *aStatus = FEATURE_BLOCKED_DEVICE;
627
0
    aFailureId = "FEATURE_FAILURE_BLOCK_ALL";
628
0
    return NS_OK;
629
0
  } else if (blocklistAll < 0) {
630
0
    gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false)) << "Ignoring any feature blocklisting.";
631
0
    *aStatus = FEATURE_STATUS_OK;
632
0
    return NS_OK;
633
0
  }
634
0
635
0
  if (GetPrefValueForFeature(aFeature, *aStatus, aFailureId)) {
636
0
    return NS_OK;
637
0
  }
638
0
639
0
  if (XRE_IsContentProcess()) {
640
0
    // Use the cached data received from the parent process.
641
0
    MOZ_ASSERT(sFeatureStatus);
642
0
    bool success = false;
643
0
    for (const auto& fs : *sFeatureStatus) {
644
0
      if (fs.feature() == aFeature) {
645
0
        aFailureId = fs.failureId();
646
0
        *aStatus = fs.status();
647
0
        success = true;
648
0
        break;
649
0
      }
650
0
    }
651
0
    return success ? NS_OK : NS_ERROR_FAILURE;
652
0
  }
653
0
654
0
  nsString version;
655
0
  nsTArray<GfxDriverInfo> driverInfo;
656
0
  nsresult rv = GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo, aFailureId);
657
0
  return rv;
658
0
}
659
660
// Matching OS go somewhat beyond the simple equality check because of the
661
// "All Windows" and "All OS X" variations.
662
//
663
// aBlockedOS is describing the system(s) we are trying to block.
664
// aSystemOS is describing the system we are running on.
665
//
666
// aSystemOS should not be "Windows" or "OSX" - it should be set to
667
// a particular version instead.
668
// However, it is valid for aBlockedOS to be one of those generic values,
669
// as we could be blocking all of the versions.
670
inline bool
671
MatchingOperatingSystems(OperatingSystem aBlockedOS, OperatingSystem aSystemOS)
672
0
{
673
0
  MOZ_ASSERT(aSystemOS != OperatingSystem::Windows &&
674
0
             aSystemOS != OperatingSystem::OSX);
675
0
676
0
  // If the block entry OS is unknown, it doesn't match
677
0
  if (aBlockedOS == OperatingSystem::Unknown) {
678
0
    return false;
679
0
  }
680
0
681
#if defined (XP_WIN)
682
  if (aBlockedOS == OperatingSystem::Windows) {
683
    // We do want even "unknown" aSystemOS to fall under "all windows"
684
    return true;
685
  }
686
#endif
687
688
#if defined (XP_MACOSX)
689
  if (aBlockedOS == OperatingSystem::OSX) {
690
    // We do want even "unknown" aSystemOS to fall under "all OS X"
691
    return true;
692
  }
693
#endif
694
695
0
  return aSystemOS == aBlockedOS;
696
0
}
697
698
int32_t
699
GfxInfoBase::FindBlocklistedDeviceInList(const nsTArray<GfxDriverInfo>& info,
700
                                         nsAString& aSuggestedVersion,
701
                                         int32_t aFeature,
702
                                         nsACString& aFailureId,
703
                                         OperatingSystem os)
704
0
{
705
0
  int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
706
0
707
0
  // Get the adapters once then reuse below
708
0
  nsAutoString adapterVendorID[2];
709
0
  nsAutoString adapterDeviceID[2];
710
0
  nsAutoString adapterDriverVersionString[2];
711
0
  bool adapterInfoFailed[2];
712
0
713
0
  adapterInfoFailed[0] = (NS_FAILED(GetAdapterVendorID(adapterVendorID[0])) ||
714
0
        NS_FAILED(GetAdapterDeviceID(adapterDeviceID[0])) ||
715
0
        NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString[0])));
716
0
  adapterInfoFailed[1] = (NS_FAILED(GetAdapterVendorID2(adapterVendorID[1])) ||
717
0
        NS_FAILED(GetAdapterDeviceID2(adapterDeviceID[1])) ||
718
0
        NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString[1])));
719
0
  // No point in going on if we don't have adapter info
720
0
  if (adapterInfoFailed[0] && adapterInfoFailed[1]) {
721
0
    return 0;
722
0
  }
723
0
724
#if defined(XP_WIN) || defined(ANDROID)
725
  uint64_t driverVersion[2] = {0, 0};
726
  if (!adapterInfoFailed[0]) {
727
    ParseDriverVersion(adapterDriverVersionString[0], &driverVersion[0]);
728
  }
729
  if (!adapterInfoFailed[1]) {
730
    ParseDriverVersion(adapterDriverVersionString[1], &driverVersion[1]);
731
  }
732
#endif
733
734
0
  uint32_t i = 0;
735
0
  for (; i < info.Length(); i++) {
736
0
    // If we don't have the info for this GPU, no need to check further.
737
0
    // It is unclear that we would ever have a mixture of 1st and 2nd
738
0
    // GPU, but leaving the code in for that possibility for now.
739
0
    // (Actually, currently mGpu2 will never be true, so this can
740
0
    // be optimized out.)
741
0
    uint32_t infoIndex = info[i].mGpu2 ? 1 : 0;
742
0
    if (adapterInfoFailed[infoIndex]) {
743
0
      continue;
744
0
    }
745
0
746
0
    // Do the operating system check first, no point in getting the driver
747
0
    // info if we won't need to use it.
748
0
    if (!MatchingOperatingSystems(info[i].mOperatingSystem, os)) {
749
0
      continue;
750
0
    }
751
0
752
0
    if (info[i].mOperatingSystemVersion && info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
753
0
        continue;
754
0
    }
755
0
756
0
    if (!info[i].mAdapterVendor.Equals(GfxDriverInfo::GetDeviceVendor(VendorAll), nsCaseInsensitiveStringComparator()) &&
757
0
        !info[i].mAdapterVendor.Equals(adapterVendorID[infoIndex], nsCaseInsensitiveStringComparator())) {
758
0
      continue;
759
0
    }
760
0
761
0
    if (info[i].mDevices != GfxDriverInfo::allDevices && info[i].mDevices->Length()) {
762
0
        bool deviceMatches = false;
763
0
        for (uint32_t j = 0; j < info[i].mDevices->Length(); j++) {
764
0
            if ((*info[i].mDevices)[j].Equals(adapterDeviceID[infoIndex], nsCaseInsensitiveStringComparator())) {
765
0
                deviceMatches = true;
766
0
                break;
767
0
            }
768
0
        }
769
0
770
0
        if (!deviceMatches) {
771
0
            continue;
772
0
        }
773
0
    }
774
0
775
0
    bool match = false;
776
0
777
0
    if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
778
0
        continue;
779
0
    }
780
0
    if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
781
0
        continue;
782
0
    }
783
0
    if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
784
0
        continue;
785
0
    }
786
0
    if (!info[i].mManufacturer.IsEmpty() && !info[i].mManufacturer.Equals(Manufacturer())) {
787
0
        continue;
788
0
    }
789
0
790
#if defined(XP_WIN) || defined(ANDROID)
791
    switch (info[i].mComparisonOp) {
792
    case DRIVER_LESS_THAN:
793
      match = driverVersion[infoIndex] < info[i].mDriverVersion;
794
      break;
795
    case DRIVER_BUILD_ID_LESS_THAN:
796
      match = (driverVersion[infoIndex] & 0xFFFF) < info[i].mDriverVersion;
797
      break;
798
    case DRIVER_LESS_THAN_OR_EQUAL:
799
      match = driverVersion[infoIndex] <= info[i].mDriverVersion;
800
      break;
801
    case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL:
802
      match = (driverVersion[infoIndex] & 0xFFFF) <= info[i].mDriverVersion;
803
      break;
804
    case DRIVER_GREATER_THAN:
805
      match = driverVersion[infoIndex] > info[i].mDriverVersion;
806
      break;
807
    case DRIVER_GREATER_THAN_OR_EQUAL:
808
      match = driverVersion[infoIndex] >= info[i].mDriverVersion;
809
      break;
810
    case DRIVER_EQUAL:
811
      match = driverVersion[infoIndex] == info[i].mDriverVersion;
812
      break;
813
    case DRIVER_NOT_EQUAL:
814
      match = driverVersion[infoIndex] != info[i].mDriverVersion;
815
      break;
816
    case DRIVER_BETWEEN_EXCLUSIVE:
817
      match = driverVersion[infoIndex] > info[i].mDriverVersion && driverVersion[infoIndex] < info[i].mDriverVersionMax;
818
      break;
819
    case DRIVER_BETWEEN_INCLUSIVE:
820
      match = driverVersion[infoIndex] >= info[i].mDriverVersion && driverVersion[infoIndex] <= info[i].mDriverVersionMax;
821
      break;
822
    case DRIVER_BETWEEN_INCLUSIVE_START:
823
      match = driverVersion[infoIndex] >= info[i].mDriverVersion && driverVersion[infoIndex] < info[i].mDriverVersionMax;
824
      break;
825
    case DRIVER_COMPARISON_IGNORED:
826
      // We don't have a comparison op, so we match everything.
827
      match = true;
828
      break;
829
    default:
830
      NS_WARNING("Bogus op in GfxDriverInfo");
831
      break;
832
    }
833
#else
834
    // We don't care what driver version it was. We only check OS version and if
835
0
    // the device matches.
836
0
    match = true;
837
0
#endif
838
0
839
0
    if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
840
0
      if (info[i].mFeature == GfxDriverInfo::allFeatures ||
841
0
          info[i].mFeature == aFeature)
842
0
      {
843
0
        status = info[i].mFeatureStatus;
844
0
        if (!info[i].mRuleId.IsEmpty()) {
845
0
          aFailureId = info[i].mRuleId.get();
846
0
        } else {
847
0
          aFailureId = "FEATURE_FAILURE_DL_BLACKLIST_NO_ID";
848
0
        }
849
0
        break;
850
0
      }
851
0
    }
852
0
  }
853
0
854
#if defined(XP_WIN)
855
  // As a very special case, we block D2D on machines with an NVidia 310M GPU
856
  // as either the primary or secondary adapter.  D2D is also blocked when the
857
  // NV 310M is the primary adapter (using the standard blocklisting mechanism).
858
  // If the primary GPU already matched something in the blocklist then we
859
  // ignore this special rule.  See bug 1008759.
860
  if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN &&
861
    (aFeature == nsIGfxInfo::FEATURE_DIRECT2D)) {
862
    if (!adapterInfoFailed[1]) {
863
      nsAString &nvVendorID = (nsAString &)GfxDriverInfo::GetDeviceVendor(VendorNVIDIA);
864
      const nsString nv310mDeviceId = NS_LITERAL_STRING("0x0A70");
865
      if (nvVendorID.Equals(adapterVendorID[1], nsCaseInsensitiveStringComparator()) &&
866
        nv310mDeviceId.Equals(adapterDeviceID[1], nsCaseInsensitiveStringComparator())) {
867
        status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
868
        aFailureId = "FEATURE_FAILURE_D2D_NV310M_BLOCK";
869
      }
870
    }
871
  }
872
873
  // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
874
  // back to the Windows handler, so we must handle this here.
875
  if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
876
    if (info[i].mSuggestedVersion) {
877
        aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
878
    } else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
879
               info[i].mDriverVersion != GfxDriverInfo::allDriverVersions)
880
    {
881
        aSuggestedVersion.AppendPrintf("%lld.%lld.%lld.%lld",
882
                                      (info[i].mDriverVersion & 0xffff000000000000) >> 48,
883
                                      (info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
884
                                      (info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
885
                                      (info[i].mDriverVersion & 0x000000000000ffff));
886
    }
887
  }
888
#endif
889
890
0
  return status;
891
0
}
892
893
void
894
GfxInfoBase::SetFeatureStatus(const nsTArray<dom::GfxInfoFeatureStatus>& aFS)
895
0
{
896
0
  MOZ_ASSERT(!sFeatureStatus);
897
0
  sFeatureStatus = new nsTArray<dom::GfxInfoFeatureStatus>(aFS);
898
0
}
899
900
nsresult
901
GfxInfoBase::GetFeatureStatusImpl(int32_t aFeature,
902
                                  int32_t* aStatus,
903
                                  nsAString& aSuggestedVersion,
904
                                  const nsTArray<GfxDriverInfo>& aDriverInfo,
905
                                  nsACString& aFailureId,
906
                                  OperatingSystem* aOS /* = nullptr */)
907
0
{
908
0
  if (aFeature <= 0) {
909
0
    gfxWarning() << "Invalid feature <= 0";
910
0
    return NS_OK;
911
0
  }
912
0
913
0
  if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
914
0
    // Terminate now with the status determined by the derived type (OS-specific
915
0
    // code).
916
0
    return NS_OK;
917
0
  }
918
0
919
0
  if (sShutdownOccurred) {
920
0
    // This is futile; we've already commenced shutdown and our blocklists have
921
0
    // been deleted. We may want to look into resurrecting the blocklist instead
922
0
    // but for now, just don't even go there.
923
0
    return NS_OK;
924
0
  }
925
0
926
0
  // If an operating system was provided by the derived GetFeatureStatusImpl,
927
0
  // grab it here. Otherwise, the OS is unknown.
928
0
  OperatingSystem os = (aOS ? *aOS : OperatingSystem::Unknown);
929
0
930
0
  nsAutoString adapterVendorID;
931
0
  nsAutoString adapterDeviceID;
932
0
  nsAutoString adapterDriverVersionString;
933
0
  if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
934
0
      NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
935
0
      NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString)))
936
0
  {
937
0
    aFailureId = "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
938
0
    *aStatus = FEATURE_BLOCKED_DEVICE;
939
0
    return NS_OK;
940
0
  }
941
0
942
0
  // Check if the device is blocked from the downloaded blocklist. If not, check
943
0
  // the static list after that. This order is used so that we can later escape
944
0
  // out of static blocks (i.e. if we were wrong or something was patched, we
945
0
  // can back out our static block without doing a release).
946
0
  int32_t status;
947
0
  if (aDriverInfo.Length()) {
948
0
    status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature, aFailureId, os);
949
0
  } else {
950
0
    if (!sDriverInfo) {
951
0
      sDriverInfo = new nsTArray<GfxDriverInfo>();
952
0
    }
953
0
    status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion, aFeature, aFailureId, os);
954
0
  }
955
0
956
0
  // It's now done being processed. It's safe to set the status to STATUS_OK.
957
0
  if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
958
0
    *aStatus = nsIGfxInfo::FEATURE_STATUS_OK;
959
0
  } else {
960
0
    *aStatus = status;
961
0
  }
962
0
963
0
  return NS_OK;
964
0
}
965
966
NS_IMETHODIMP
967
GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
968
                                              nsAString& aVersion)
969
0
{
970
0
  nsCString version;
971
0
  if (GetPrefValueForDriverVersion(version)) {
972
0
    aVersion = NS_ConvertASCIItoUTF16(version);
973
0
    return NS_OK;
974
0
  }
975
0
976
0
  int32_t status;
977
0
  nsCString discardFailureId;
978
0
  nsTArray<GfxDriverInfo> driverInfo;
979
0
  return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo, discardFailureId);
980
0
}
981
982
void
983
GfxInfoBase::EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo)
984
0
{
985
0
  int32_t features[] = {
986
0
    nsIGfxInfo::FEATURE_DIRECT2D,
987
0
    nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
988
0
    nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
989
0
    nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
990
0
    nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS,
991
0
    nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE,
992
0
    nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
993
0
    nsIGfxInfo::FEATURE_OPENGL_LAYERS,
994
0
    nsIGfxInfo::FEATURE_WEBGL_OPENGL,
995
0
    nsIGfxInfo::FEATURE_WEBGL_ANGLE,
996
0
    nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE,
997
0
    nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE,
998
0
    nsIGfxInfo::FEATURE_WEBGL_MSAA,
999
0
    nsIGfxInfo::FEATURE_STAGEFRIGHT,
1000
0
    nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION,
1001
0
    nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION,
1002
0
    nsIGfxInfo::FEATURE_VP8_HW_DECODE,
1003
0
    nsIGfxInfo::FEATURE_VP9_HW_DECODE,
1004
0
    nsIGfxInfo::FEATURE_DX_INTEROP2,
1005
0
    nsIGfxInfo::FEATURE_GPU_PROCESS,
1006
0
    nsIGfxInfo::FEATURE_WEBGL2,
1007
0
    nsIGfxInfo::FEATURE_ADVANCED_LAYERS,
1008
0
    nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX,
1009
0
    nsIGfxInfo::FEATURE_WEBRENDER,
1010
0
    nsIGfxInfo::FEATURE_DX_NV12,
1011
0
    0
1012
0
  };
1013
0
1014
0
  // For every feature we know about, we evaluate whether this blacklist has a
1015
0
  // non-STATUS_OK status. If it does, we set the pref we evaluate in
1016
0
  // GetFeatureStatus above, so we don't need to hold on to this blacklist
1017
0
  // anywhere permanent.
1018
0
  int i = 0;
1019
0
  while (features[i]) {
1020
0
    int32_t status;
1021
0
    nsCString failureId;
1022
0
    nsAutoString suggestedVersion;
1023
0
    if (NS_SUCCEEDED(GetFeatureStatusImpl(features[i], &status,
1024
0
                                          suggestedVersion,
1025
0
                                          aDriverInfo,
1026
0
                                          failureId))) {
1027
0
      switch (status) {
1028
0
        default:
1029
0
        case nsIGfxInfo::FEATURE_STATUS_OK:
1030
0
          RemovePrefForFeature(features[i]);
1031
0
          break;
1032
0
1033
0
        case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
1034
0
          if (!suggestedVersion.IsEmpty()) {
1035
0
            SetPrefValueForDriverVersion(suggestedVersion);
1036
0
          } else {
1037
0
            RemovePrefForDriverVersion();
1038
0
          }
1039
0
          MOZ_FALLTHROUGH;
1040
0
1041
0
        case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION:
1042
0
        case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
1043
0
        case nsIGfxInfo::FEATURE_DISCOURAGED:
1044
0
        case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
1045
0
          SetPrefValueForFeature(features[i], status, failureId);
1046
0
          break;
1047
0
      }
1048
0
    }
1049
0
1050
0
    ++i;
1051
0
  }
1052
0
}
1053
1054
NS_IMETHODIMP_(void)
1055
GfxInfoBase::LogFailure(const nsACString &failure)
1056
0
{
1057
0
  // gfxCriticalError has a mutex lock of its own, so we may not actually
1058
0
  // need this lock. ::GetFailures() accesses the data but the LogForwarder
1059
0
  // will not return the copy of the logs unless it can get the same lock
1060
0
  // that gfxCriticalError uses.  Still, that is so much of an implementation
1061
0
  // detail that it's nicer to just add an extra lock here and in ::GetFailures()
1062
0
  MutexAutoLock lock(mMutex);
1063
0
1064
0
  // By default, gfxCriticalError asserts; make it not assert in this case.
1065
0
  gfxCriticalError(CriticalLog::DefaultOptions(false)) << "(LF) " << failure.BeginReading();
1066
0
}
1067
1068
/* XPConnect method of returning arrays is very ugly. Would not recommend. */
1069
NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t* failureCount,
1070
                                       int32_t** indices,
1071
                                       char ***failures)
1072
0
{
1073
0
  MutexAutoLock lock(mMutex);
1074
0
1075
0
  NS_ENSURE_ARG_POINTER(failureCount);
1076
0
  NS_ENSURE_ARG_POINTER(failures);
1077
0
1078
0
  *failures = nullptr;
1079
0
  *failureCount = 0;
1080
0
1081
0
  // indices is "allowed" to be null, the caller may not care about them,
1082
0
  // although calling from JS doesn't seem to get us there.
1083
0
  if (indices) *indices = nullptr;
1084
0
1085
0
  LogForwarder* logForwarder = Factory::GetLogForwarder();
1086
0
  if (!logForwarder) {
1087
0
    return NS_ERROR_UNEXPECTED;
1088
0
  }
1089
0
1090
0
  // There are two stirng copies in this method, starting with this one. We are
1091
0
  // assuming this is not a big deal, as the size of the array should be small
1092
0
  // and the strings in it should be small as well (the error messages in the
1093
0
  // code.)  The second copy happens with the Clone() calls.  Technically,
1094
0
  // we don't need the mutex lock after the StringVectorCopy() call.
1095
0
  LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
1096
0
  *failureCount = loggedStrings.size();
1097
0
1098
0
  if (*failureCount != 0) {
1099
0
    *failures = (char**)moz_xmalloc(*failureCount * sizeof(char*));
1100
0
    if (indices) {
1101
0
      *indices = (int32_t*)moz_xmalloc(*failureCount * sizeof(int32_t));
1102
0
    }
1103
0
1104
0
    /* copy over the failure messages into the array we just allocated */
1105
0
    LoggingRecord::const_iterator it;
1106
0
    uint32_t i=0;
1107
0
    for(it = loggedStrings.begin() ; it != loggedStrings.end(); ++it, i++) {
1108
0
      (*failures)[i] =
1109
0
        (char*) moz_xmemdup(Get<1>(*it).c_str(), Get<1>(*it).size() + 1);
1110
0
      if (indices) (*indices)[i] = Get<0>(*it);
1111
0
    }
1112
0
  }
1113
0
1114
0
  return NS_OK;
1115
0
}
1116
1117
nsTArray<GfxInfoCollectorBase*> *sCollectors;
1118
1119
static void
1120
InitCollectors()
1121
0
{
1122
0
  if (!sCollectors)
1123
0
    sCollectors = new nsTArray<GfxInfoCollectorBase*>;
1124
0
}
1125
1126
nsresult GfxInfoBase::GetInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aResult)
1127
0
{
1128
0
  InitCollectors();
1129
0
  InfoObject obj(aCx);
1130
0
1131
0
  for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1132
0
    (*sCollectors)[i]->GetInfo(obj);
1133
0
  }
1134
0
1135
0
  // Some example property definitions
1136
0
  // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1137
0
  // obj.DefineProperty("renderer", mRendererIDsString);
1138
0
  // obj.DefineProperty("five", 5);
1139
0
1140
0
  if (!obj.mOk) {
1141
0
    return NS_ERROR_FAILURE;
1142
0
  }
1143
0
1144
0
  aResult.setObject(*obj.mObj);
1145
0
  return NS_OK;
1146
0
}
1147
1148
nsAutoCString gBaseAppVersion;
1149
1150
const nsCString&
1151
GfxInfoBase::GetApplicationVersion()
1152
0
{
1153
0
  static bool versionInitialized = false;
1154
0
  if (!versionInitialized) {
1155
0
    // If we fail to get the version, we will not try again.
1156
0
    versionInitialized = true;
1157
0
1158
0
    // Get the version from xpcom/system/nsIXULAppInfo.idl
1159
0
    nsCOMPtr<nsIXULAppInfo> app = do_GetService("@mozilla.org/xre/app-info;1");
1160
0
    if (app) {
1161
0
      app->GetVersion(gBaseAppVersion);
1162
0
    }
1163
0
  }
1164
0
  return gBaseAppVersion;
1165
0
}
1166
1167
void
1168
GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector)
1169
0
{
1170
0
  InitCollectors();
1171
0
  sCollectors->AppendElement(collector);
1172
0
}
1173
1174
void
1175
GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector)
1176
0
{
1177
0
  InitCollectors();
1178
0
  for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1179
0
    if ((*sCollectors)[i] == collector) {
1180
0
      sCollectors->RemoveElementAt(i);
1181
0
      break;
1182
0
    }
1183
0
  }
1184
0
  if (sCollectors->IsEmpty()) {
1185
0
    delete sCollectors;
1186
0
    sCollectors = nullptr;
1187
0
  }
1188
0
}
1189
1190
NS_IMETHODIMP
1191
GfxInfoBase::GetMonitors(JSContext* aCx, JS::MutableHandleValue aResult)
1192
0
{
1193
0
  JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
1194
0
1195
0
  nsresult rv = FindMonitors(aCx, array);
1196
0
  if (NS_FAILED(rv)) {
1197
0
    return rv;
1198
0
  }
1199
0
1200
0
  aResult.setObject(*array);
1201
0
  return NS_OK;
1202
0
}
1203
1204
static const char*
1205
GetLayersBackendName(layers::LayersBackend aBackend)
1206
0
{
1207
0
  switch (aBackend) {
1208
0
    case layers::LayersBackend::LAYERS_NONE:
1209
0
      return "none";
1210
0
    case layers::LayersBackend::LAYERS_OPENGL:
1211
0
      return "opengl";
1212
0
    case layers::LayersBackend::LAYERS_D3D11:
1213
0
      return "d3d11";
1214
0
    case layers::LayersBackend::LAYERS_CLIENT:
1215
0
      return "client";
1216
0
    case layers::LayersBackend::LAYERS_WR:
1217
0
      return "webrender";
1218
0
    case layers::LayersBackend::LAYERS_BASIC:
1219
0
      return "basic";
1220
0
    default:
1221
0
      MOZ_ASSERT_UNREACHABLE("unknown layers backend");
1222
0
      return "unknown";
1223
0
  }
1224
0
}
1225
1226
static inline bool
1227
SetJSPropertyString(JSContext* aCx, JS::Handle<JSObject*> aObj,
1228
                    const char* aProp, const char* aString)
1229
0
{
1230
0
  JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, aString));
1231
0
  if (!str) {
1232
0
    return false;
1233
0
  }
1234
0
1235
0
  JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1236
0
  return JS_SetProperty(aCx, aObj, aProp, val);
1237
0
}
1238
1239
template <typename T>
1240
static inline bool
1241
AppendJSElement(JSContext* aCx, JS::Handle<JSObject*> aObj, const T& aValue)
1242
0
{
1243
0
  uint32_t index;
1244
0
  if (!JS_GetArrayLength(aCx, aObj, &index)) {
1245
0
    return false;
1246
0
  }
1247
0
  return JS_SetElement(aCx, aObj, index, aValue);
1248
0
}
1249
1250
nsresult
1251
GfxInfoBase::GetFeatures(JSContext* aCx, JS::MutableHandle<JS::Value> aOut)
1252
0
{
1253
0
  JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1254
0
  if (!obj) {
1255
0
    return NS_ERROR_OUT_OF_MEMORY;
1256
0
  }
1257
0
  aOut.setObject(*obj);
1258
0
1259
0
  layers::LayersBackend backend = gfxPlatform::Initialized()
1260
0
                                  ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1261
0
                                  : layers::LayersBackend::LAYERS_NONE;
1262
0
  const char* backendName = GetLayersBackendName(backend);
1263
0
  SetJSPropertyString(aCx, obj, "compositor", backendName);
1264
0
1265
0
  // If graphics isn't initialized yet, just stop now.
1266
0
  if (!gfxPlatform::Initialized()) {
1267
0
    return NS_OK;
1268
0
  }
1269
0
1270
0
  DescribeFeatures(aCx, obj);
1271
0
  return NS_OK;
1272
0
}
1273
1274
nsresult GfxInfoBase::GetFeatureLog(JSContext* aCx, JS::MutableHandle<JS::Value> aOut)
1275
0
{
1276
0
  JS::Rooted<JSObject*> containerObj(aCx, JS_NewPlainObject(aCx));
1277
0
  if (!containerObj) {
1278
0
    return NS_ERROR_OUT_OF_MEMORY;
1279
0
  }
1280
0
  aOut.setObject(*containerObj);
1281
0
1282
0
  JS::Rooted<JSObject*> featureArray(aCx, JS_NewArrayObject(aCx, 0));
1283
0
  if (!featureArray) {
1284
0
    return NS_ERROR_OUT_OF_MEMORY;
1285
0
  }
1286
0
1287
0
  // Collect features.
1288
0
  gfxConfig::ForEachFeature([&](const char* aName,
1289
0
                                const char* aDescription,
1290
0
                                FeatureState& aFeature) -> void {
1291
0
    JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1292
0
    if (!obj) {
1293
0
      return;
1294
0
    }
1295
0
    if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1296
0
        !SetJSPropertyString(aCx, obj, "description", aDescription) ||
1297
0
        !SetJSPropertyString(aCx, obj, "status", FeatureStatusToString(aFeature.GetValue())))
1298
0
    {
1299
0
      return;
1300
0
    }
1301
0
1302
0
    JS::Rooted<JS::Value> log(aCx);
1303
0
    if (!BuildFeatureStateLog(aCx, aFeature, &log)) {
1304
0
      return;
1305
0
    }
1306
0
    if (!JS_SetProperty(aCx, obj, "log", log)) {
1307
0
      return;
1308
0
    }
1309
0
1310
0
    if (!AppendJSElement(aCx, featureArray, obj)) {
1311
0
      return;
1312
0
    }
1313
0
  });
1314
0
1315
0
  JS::Rooted<JSObject*> fallbackArray(aCx, JS_NewArrayObject(aCx, 0));
1316
0
  if (!fallbackArray) {
1317
0
    return NS_ERROR_OUT_OF_MEMORY;
1318
0
  }
1319
0
1320
0
  // Collect fallbacks.
1321
0
  gfxConfig::ForEachFallback([&](const char* aName, const char* aMessage) -> void {
1322
0
    JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1323
0
    if (!obj) {
1324
0
      return;
1325
0
    }
1326
0
1327
0
    if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1328
0
        !SetJSPropertyString(aCx, obj, "message", aMessage))
1329
0
    {
1330
0
      return;
1331
0
    }
1332
0
1333
0
    if (!AppendJSElement(aCx, fallbackArray, obj)) {
1334
0
      return;
1335
0
    }
1336
0
  });
1337
0
1338
0
  JS::Rooted<JS::Value> val(aCx);
1339
0
1340
0
  val = JS::ObjectValue(*featureArray);
1341
0
  JS_SetProperty(aCx, containerObj, "features", val);
1342
0
1343
0
  val = JS::ObjectValue(*fallbackArray);
1344
0
  JS_SetProperty(aCx, containerObj, "fallbacks", val);
1345
0
1346
0
  return NS_OK;
1347
0
}
1348
1349
bool
1350
GfxInfoBase::BuildFeatureStateLog(JSContext* aCx, const FeatureState& aFeature,
1351
                                  JS::MutableHandle<JS::Value> aOut)
1352
0
{
1353
0
  JS::Rooted<JSObject*> log(aCx, JS_NewArrayObject(aCx, 0));
1354
0
  if (!log) {
1355
0
    return false;
1356
0
  }
1357
0
  aOut.setObject(*log);
1358
0
1359
0
  aFeature.ForEachStatusChange([&](const char* aType,
1360
0
                                   FeatureStatus aStatus,
1361
0
                                   const char* aMessage) -> void {
1362
0
    JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1363
0
    if (!obj) {
1364
0
      return;
1365
0
    }
1366
0
1367
0
    if (!SetJSPropertyString(aCx, obj, "type", aType) ||
1368
0
        !SetJSPropertyString(aCx, obj, "status", FeatureStatusToString(aStatus)) ||
1369
0
        (aMessage && !SetJSPropertyString(aCx, obj, "message", aMessage)))
1370
0
    {
1371
0
      return;
1372
0
    }
1373
0
1374
0
    if (!AppendJSElement(aCx, log, obj)) {
1375
0
      return;
1376
0
    }
1377
0
  });
1378
0
1379
0
  return true;
1380
0
}
1381
1382
void
1383
GfxInfoBase::DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> aObj)
1384
0
{
1385
0
  JS::Rooted<JSObject*> obj(aCx);
1386
0
1387
0
  gfx::FeatureStatus gpuProcess = gfxConfig::GetValue(Feature::GPU_PROCESS);
1388
0
  InitFeatureObject(aCx, aObj, "gpuProcess", gpuProcess, &obj);
1389
0
1390
0
  gfx::FeatureStatus wrQualified = gfxConfig::GetValue(Feature::WEBRENDER_QUALIFIED);
1391
0
  InitFeatureObject(aCx, aObj, "wrQualified", wrQualified, &obj);
1392
0
1393
0
  gfx::FeatureStatus webrender = gfxConfig::GetValue(Feature::WEBRENDER);
1394
0
  InitFeatureObject(aCx, aObj, "webrender", webrender, &obj);
1395
0
1396
0
  // Only include AL if the platform attempted to use it.
1397
0
  gfx::FeatureStatus advancedLayers = gfxConfig::GetValue(Feature::ADVANCED_LAYERS);
1398
0
  if (advancedLayers != FeatureStatus::Unused) {
1399
0
    InitFeatureObject(aCx, aObj, "advancedLayers", advancedLayers, &obj);
1400
0
1401
0
    if (gfxConfig::UseFallback(Fallback::NO_CONSTANT_BUFFER_OFFSETTING)) {
1402
0
      JS::Rooted<JS::Value> trueVal(aCx, JS::BooleanValue(true));
1403
0
      JS_SetProperty(aCx, obj, "noConstantBufferOffsetting", trueVal);
1404
0
    }
1405
0
  }
1406
0
}
1407
1408
bool
1409
GfxInfoBase::InitFeatureObject(JSContext* aCx,
1410
                               JS::Handle<JSObject*> aContainer,
1411
                               const char* aName,
1412
                               mozilla::gfx::FeatureStatus& aFeatureStatus,
1413
                               JS::MutableHandle<JSObject*> aOutObj)
1414
0
{
1415
0
  JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1416
0
  if (!obj) {
1417
0
    return false;
1418
0
  }
1419
0
1420
0
  // Set "status".
1421
0
  const char* status = FeatureStatusToString(aFeatureStatus);
1422
0
1423
0
  JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, status));
1424
0
  JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1425
0
  JS_SetProperty(aCx, obj, "status", val);
1426
0
1427
0
  // Add the feature object to the container.
1428
0
  {
1429
0
    JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
1430
0
    JS_SetProperty(aCx, aContainer, aName, val);
1431
0
  }
1432
0
1433
0
  aOutObj.set(obj);
1434
0
  return true;
1435
0
}
1436
1437
nsresult
1438
GfxInfoBase::GetActiveCrashGuards(JSContext* aCx, JS::MutableHandle<JS::Value> aOut)
1439
0
{
1440
0
  JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
1441
0
  if (!array) {
1442
0
    return NS_ERROR_OUT_OF_MEMORY;
1443
0
  }
1444
0
  aOut.setObject(*array);
1445
0
1446
0
  DriverCrashGuard::ForEachActiveCrashGuard([&](const char* aName,
1447
0
                                                const char* aPrefName) -> void {
1448
0
    JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1449
0
    if (!obj) {
1450
0
      return;
1451
0
    }
1452
0
    if (!SetJSPropertyString(aCx, obj, "type", aName)) {
1453
0
      return;
1454
0
    }
1455
0
    if (!SetJSPropertyString(aCx, obj, "prefName", aPrefName)) {
1456
0
      return;
1457
0
    }
1458
0
    if (!AppendJSElement(aCx, array, obj)) {
1459
0
      return;
1460
0
    }
1461
0
  });
1462
0
1463
0
  return NS_OK;
1464
0
}
1465
1466
NS_IMETHODIMP
1467
GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled)
1468
0
{
1469
0
  *aWebRenderEnabled = gfxVars::UseWebRender();
1470
0
  return NS_OK;
1471
0
}
1472
1473
NS_IMETHODIMP
1474
GfxInfoBase::GetUsesTiling(bool* aUsesTiling)
1475
0
{
1476
0
  *aUsesTiling = gfxPlatform::GetPlatform()->UsesTiling();
1477
0
  return NS_OK;
1478
0
}
1479
1480
NS_IMETHODIMP
1481
GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling)
1482
0
{
1483
0
  *aUsesTiling = gfxPlatform::GetPlatform()->ContentUsesTiling();
1484
0
  return NS_OK;
1485
0
}
1486
1487
NS_IMETHODIMP
1488
GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled)
1489
0
{
1490
0
  *aOffMainThreadPaintEnabled = gfxConfig::IsEnabled(Feature::OMTP);
1491
0
  return NS_OK;
1492
0
}
1493
1494
NS_IMETHODIMP
1495
GfxInfoBase::GetOffMainThreadPaintWorkerCount(int32_t* aOffMainThreadPaintWorkerCount)
1496
0
{
1497
0
  if (gfxConfig::IsEnabled(Feature::OMTP)) {
1498
0
    *aOffMainThreadPaintWorkerCount = layers::PaintThread::CalculatePaintWorkerCount();
1499
0
  } else {
1500
0
    *aOffMainThreadPaintWorkerCount = 0;
1501
0
  }
1502
0
  return NS_OK;
1503
0
}
1504
1505
NS_IMETHODIMP
1506
GfxInfoBase::GetIsHeadless(bool* aIsHeadless)
1507
0
{
1508
0
  *aIsHeadless = gfxPlatform::IsHeadless();
1509
0
  return NS_OK;
1510
0
}
1511
1512
NS_IMETHODIMP
1513
GfxInfoBase::GetContentBackend(nsAString & aContentBackend)
1514
0
{
1515
0
  BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1516
0
  nsString outStr;
1517
0
1518
0
  switch (backend) {
1519
0
  case BackendType::DIRECT2D1_1: {
1520
0
    outStr.AppendPrintf("Direct2D 1.1");
1521
0
    break;
1522
0
  }
1523
0
  case BackendType::SKIA: {
1524
0
    outStr.AppendPrintf("Skia");
1525
0
    break;
1526
0
  }
1527
0
  case BackendType::CAIRO: {
1528
0
    outStr.AppendPrintf("Cairo");
1529
0
    break;
1530
0
  }
1531
0
  default:
1532
0
    return NS_ERROR_FAILURE;
1533
0
  }
1534
0
1535
0
  aContentBackend.Assign(outStr);
1536
0
  return NS_OK;
1537
0
}
1538
1539
NS_IMETHODIMP
1540
GfxInfoBase::GetUsingGPUProcess(bool *aOutValue)
1541
0
{
1542
0
  GPUProcessManager* gpu = GPUProcessManager::Get();
1543
0
  if (!gpu) {
1544
0
    // Not supported in content processes.
1545
0
    return NS_ERROR_FAILURE;
1546
0
  }
1547
0
1548
0
  *aOutValue = !!gpu->GetGPUChild();
1549
0
  return NS_OK;
1550
0
}
1551
1552
NS_IMETHODIMP
1553
GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool *_retval)
1554
0
{
1555
0
  gfxPlatform::GetPlatform();
1556
0
1557
0
  GPUProcessManager* gpm = GPUProcessManager::Get();
1558
0
  if (aEnable) {
1559
0
    if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
1560
0
      gfxConfig::UserForceEnable(Feature::GPU_PROCESS, "xpcshell-test");
1561
0
    }
1562
0
    gpm->LaunchGPUProcess();
1563
0
    gpm->EnsureGPUReady();
1564
0
  } else {
1565
0
    gfxConfig::UserDisable(Feature::GPU_PROCESS, "xpcshell-test");
1566
0
    gpm->KillProcess();
1567
0
  }
1568
0
1569
0
  *_retval = true;
1570
0
  return NS_OK;
1571
0
}
1572
1573
GfxInfoCollectorBase::GfxInfoCollectorBase()
1574
0
{
1575
0
  GfxInfoBase::AddCollector(this);
1576
0
}
1577
1578
GfxInfoCollectorBase::~GfxInfoCollectorBase()
1579
0
{
1580
0
  GfxInfoBase::RemoveCollector(this);
1581
0
}