1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
8 #include "mozilla/ArrayUtils.h"
10 #include "GfxInfoBase.h"
12 #include "GfxDriverInfo.h"
13 #include "js/Array.h" // JS::GetArrayLength, JS::NewArrayObject
15 #include "nsCOMArray.h"
17 #include "nsUnicharUtils.h"
18 #include "nsVersionComparator.h"
19 #include "mozilla/Services.h"
20 #include "mozilla/Observer.h"
21 #include "nsIObserver.h"
22 #include "nsIObserverService.h"
24 #include "nsXULAppAPI.h"
25 #include "nsIXULAppInfo.h"
26 #include "mozilla/Preferences.h"
27 #include "mozilla/StaticPrefs_gfx.h"
28 #include "mozilla/gfx/2D.h"
29 #include "mozilla/gfx/GPUProcessManager.h"
30 #include "mozilla/gfx/Logging.h"
31 #include "mozilla/gfx/gfxVars.h"
32 #include "mozilla/layers/PaintThread.h"
34 #include "gfxPlatform.h"
35 #include "gfxConfig.h"
36 #include "DriverCrashGuard.h"
38 using namespace mozilla::widget
;
39 using namespace mozilla
;
40 using mozilla::MutexAutoLock
;
42 nsTArray
<GfxDriverInfo
>* GfxInfoBase::sDriverInfo
;
43 nsTArray
<dom::GfxInfoFeatureStatus
>* GfxInfoBase::sFeatureStatus
;
44 bool GfxInfoBase::sDriverInfoObserverInitialized
;
45 bool GfxInfoBase::sShutdownOccurred
;
47 // Observes for shutdown so that the child GfxDriverInfo list is freed.
48 class ShutdownObserver
: public nsIObserver
{
49 virtual ~ShutdownObserver() {}
56 NS_IMETHOD
Observe(nsISupports
* subject
, const char* aTopic
,
57 const char16_t
* aData
) override
{
58 MOZ_ASSERT(strcmp(aTopic
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
) == 0);
60 delete GfxInfoBase::sDriverInfo
;
61 GfxInfoBase::sDriverInfo
= nullptr;
63 delete GfxInfoBase::sFeatureStatus
;
64 GfxInfoBase::sFeatureStatus
= nullptr;
66 for (uint32_t i
= 0; i
< DeviceFamilyMax
; i
++) {
67 delete GfxDriverInfo::sDeviceFamilies
[i
];
68 GfxDriverInfo::sDeviceFamilies
[i
] = nullptr;
71 for (uint32_t i
= 0; i
< DeviceVendorMax
; i
++) {
72 delete GfxDriverInfo::sDeviceVendors
[i
];
73 GfxDriverInfo::sDeviceVendors
[i
] = nullptr;
76 for (uint32_t i
= 0; i
< DriverVendorMax
; i
++) {
77 delete GfxDriverInfo::sDriverVendors
[i
];
78 GfxDriverInfo::sDriverVendors
[i
] = nullptr;
81 GfxInfoBase::sShutdownOccurred
= true;
87 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
89 static void InitGfxDriverInfoShutdownObserver() {
90 if (GfxInfoBase::sDriverInfoObserverInitialized
) return;
92 GfxInfoBase::sDriverInfoObserverInitialized
= true;
94 nsCOMPtr
<nsIObserverService
> observerService
= services::GetObserverService();
95 if (!observerService
) {
96 NS_WARNING("Could not get observer service!");
100 ShutdownObserver
* obs
= new ShutdownObserver();
101 observerService
->AddObserver(obs
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
, false);
104 using namespace mozilla::widget
;
105 using namespace mozilla::gfx
;
106 using namespace mozilla
;
108 NS_IMPL_ISUPPORTS(GfxInfoBase
, nsIGfxInfo
, nsIObserver
,
109 nsISupportsWeakReference
)
111 #define BLACKLIST_PREF_BRANCH "gfx.blacklist."
112 #define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
113 #define BLACKLIST_ENTRY_TAG_NAME "gfxBlacklistEntry"
115 static const char* GetPrefNameForFeature(int32_t aFeature
) {
116 const char* name
= nullptr;
118 case nsIGfxInfo::FEATURE_DIRECT2D
:
119 name
= BLACKLIST_PREF_BRANCH
"direct2d";
121 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
:
122 name
= BLACKLIST_PREF_BRANCH
"layers.direct3d9";
124 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
:
125 name
= BLACKLIST_PREF_BRANCH
"layers.direct3d10";
127 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
:
128 name
= BLACKLIST_PREF_BRANCH
"layers.direct3d10-1";
130 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
:
131 name
= BLACKLIST_PREF_BRANCH
"layers.direct3d11";
133 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
134 name
= BLACKLIST_PREF_BRANCH
"direct3d11angle";
136 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
:
137 name
= BLACKLIST_PREF_BRANCH
"hardwarevideodecoding";
139 case nsIGfxInfo::FEATURE_OPENGL_LAYERS
:
140 name
= BLACKLIST_PREF_BRANCH
"layers.opengl";
142 case nsIGfxInfo::FEATURE_WEBGL_OPENGL
:
143 name
= BLACKLIST_PREF_BRANCH
"webgl.opengl";
145 case nsIGfxInfo::FEATURE_WEBGL_ANGLE
:
146 name
= BLACKLIST_PREF_BRANCH
"webgl.angle";
148 case nsIGfxInfo::FEATURE_WEBGL_MSAA
:
149 name
= BLACKLIST_PREF_BRANCH
"webgl.msaa";
151 case nsIGfxInfo::FEATURE_STAGEFRIGHT
:
152 name
= BLACKLIST_PREF_BRANCH
"stagefright";
154 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
:
155 name
= BLACKLIST_PREF_BRANCH
"webrtc.hw.acceleration.h264";
157 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
:
158 name
= BLACKLIST_PREF_BRANCH
"webrtc.hw.acceleration.encode";
160 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
:
161 name
= BLACKLIST_PREF_BRANCH
"webrtc.hw.acceleration.decode";
163 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
:
164 name
= BLACKLIST_PREF_BRANCH
"canvas2d.acceleration";
166 case nsIGfxInfo::FEATURE_DX_INTEROP2
:
167 name
= BLACKLIST_PREF_BRANCH
"dx.interop2";
169 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
170 name
= BLACKLIST_PREF_BRANCH
"gpu.process";
172 case nsIGfxInfo::FEATURE_WEBGL2
:
173 name
= BLACKLIST_PREF_BRANCH
"webgl2";
175 case nsIGfxInfo::FEATURE_ADVANCED_LAYERS
:
176 name
= BLACKLIST_PREF_BRANCH
"layers.advanced";
178 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
:
179 name
= BLACKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
181 case nsIGfxInfo::FEATURE_WEBRENDER
:
182 name
= BLACKLIST_PREF_BRANCH
"webrender";
184 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
185 name
= BLACKLIST_PREF_BRANCH
"webrender.compositor";
187 case nsIGfxInfo::FEATURE_DX_NV12
:
188 name
= BLACKLIST_PREF_BRANCH
"dx.nv12";
190 case nsIGfxInfo::FEATURE_DX_P010
:
191 name
= BLACKLIST_PREF_BRANCH
"dx.p010";
193 case nsIGfxInfo::FEATURE_DX_P016
:
194 name
= BLACKLIST_PREF_BRANCH
"dx.p016";
196 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
197 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
198 // We don't provide prefs for these features as these are
199 // not handling downloadable blocklist.
201 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
202 name
= BLACKLIST_PREF_BRANCH
"gl.swizzle";
205 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
212 // Returns the value of the pref for the relevant feature in aValue.
213 // If the pref doesn't exist, aValue is not touched, and returns false.
214 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
215 nsACString
& aFailureId
) {
216 const char* prefname
= GetPrefNameForFeature(aFeature
);
217 if (!prefname
) return false;
219 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
220 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
224 nsCString
failureprefname(prefname
);
225 failureprefname
+= ".failureid";
226 nsAutoCString failureValue
;
227 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
228 if (NS_SUCCEEDED(rv
)) {
229 aFailureId
= failureValue
.get();
231 aFailureId
= "FEATURE_FAILURE_BLACKLIST_PREF";
237 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
238 const nsACString
& aFailureId
) {
239 const char* prefname
= GetPrefNameForFeature(aFeature
);
240 if (!prefname
) return;
241 if (XRE_IsParentProcess()) {
242 delete GfxInfoBase::sFeatureStatus
;
243 GfxInfoBase::sFeatureStatus
= nullptr;
246 Preferences::SetInt(prefname
, aValue
);
247 if (!aFailureId
.IsEmpty()) {
248 nsCString
failureprefname(prefname
);
249 failureprefname
+= ".failureid";
250 Preferences::SetCString(failureprefname
.get(), aFailureId
);
254 static void RemovePrefForFeature(int32_t aFeature
) {
255 const char* prefname
= GetPrefNameForFeature(aFeature
);
256 if (!prefname
) return;
258 if (XRE_IsParentProcess()) {
259 delete GfxInfoBase::sFeatureStatus
;
260 GfxInfoBase::sFeatureStatus
= nullptr;
262 Preferences::ClearUser(prefname
);
265 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
267 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
270 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
271 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
274 static void RemovePrefForDriverVersion() {
275 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
278 static OperatingSystem
BlacklistOSToOperatingSystem(const nsAString
& os
) {
279 if (os
.EqualsLiteral("WINNT 6.1"))
280 return OperatingSystem::Windows7
;
281 else if (os
.EqualsLiteral("WINNT 6.2"))
282 return OperatingSystem::Windows8
;
283 else if (os
.EqualsLiteral("WINNT 6.3"))
284 return OperatingSystem::Windows8_1
;
285 else if (os
.EqualsLiteral("WINNT 10.0"))
286 return OperatingSystem::Windows10
;
287 else if (os
.EqualsLiteral("Linux"))
288 return OperatingSystem::Linux
;
289 else if (os
.EqualsLiteral("Darwin 9"))
290 return OperatingSystem::OSX10_5
;
291 else if (os
.EqualsLiteral("Darwin 10"))
292 return OperatingSystem::OSX10_6
;
293 else if (os
.EqualsLiteral("Darwin 11"))
294 return OperatingSystem::OSX10_7
;
295 else if (os
.EqualsLiteral("Darwin 12"))
296 return OperatingSystem::OSX10_8
;
297 else if (os
.EqualsLiteral("Darwin 13"))
298 return OperatingSystem::OSX10_9
;
299 else if (os
.EqualsLiteral("Darwin 14"))
300 return OperatingSystem::OSX10_10
;
301 else if (os
.EqualsLiteral("Darwin 15"))
302 return OperatingSystem::OSX10_11
;
303 else if (os
.EqualsLiteral("Darwin 16"))
304 return OperatingSystem::OSX10_12
;
305 else if (os
.EqualsLiteral("Darwin 17"))
306 return OperatingSystem::OSX10_13
;
307 else if (os
.EqualsLiteral("Darwin 18"))
308 return OperatingSystem::OSX10_14
;
309 else if (os
.EqualsLiteral("Darwin 19"))
310 return OperatingSystem::OSX10_15
;
311 else if (os
.EqualsLiteral("Android"))
312 return OperatingSystem::Android
;
313 // For historical reasons, "All" in blocklist means "All Windows"
314 else if (os
.EqualsLiteral("All"))
315 return OperatingSystem::Windows
;
317 return OperatingSystem::Unknown
;
320 static GfxDeviceFamily
* BlacklistDevicesToDeviceFamily(
321 nsTArray
<nsCString
>& devices
) {
322 if (devices
.Length() == 0) return nullptr;
324 // For each device, get its device ID, and return a freshly-allocated
325 // GfxDeviceFamily with the contents of that array.
326 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
328 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
329 // We make sure we don't add any "empty" device entries to the array, so
330 // we don't need to check if devices[i] is empty.
331 deviceIds
->AppendElement(NS_ConvertUTF8toUTF16(devices
[i
]));
337 static int32_t BlacklistFeatureToGfxFeature(const nsAString
& aFeature
) {
338 MOZ_ASSERT(!aFeature
.IsEmpty());
339 if (aFeature
.EqualsLiteral("DIRECT2D"))
340 return nsIGfxInfo::FEATURE_DIRECT2D
;
341 else if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS"))
342 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
343 else if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS"))
344 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
345 else if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
346 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
347 else if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS"))
348 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
349 else if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE"))
350 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
351 else if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
352 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
353 else if (aFeature
.EqualsLiteral("OPENGL_LAYERS"))
354 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
355 else if (aFeature
.EqualsLiteral("WEBGL_OPENGL"))
356 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
357 else if (aFeature
.EqualsLiteral("WEBGL_ANGLE"))
358 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
359 else if (aFeature
.EqualsLiteral("WEBGL_MSAA"))
360 return nsIGfxInfo::FEATURE_WEBGL_MSAA
;
361 else if (aFeature
.EqualsLiteral("STAGEFRIGHT"))
362 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
363 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
364 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
365 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
366 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
367 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264"))
368 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
369 else if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION"))
370 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
371 else if (aFeature
.EqualsLiteral("DX_INTEROP2"))
372 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
373 else if (aFeature
.EqualsLiteral("GPU_PROCESS"))
374 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
375 else if (aFeature
.EqualsLiteral("WEBGL2"))
376 return nsIGfxInfo::FEATURE_WEBGL2
;
377 else if (aFeature
.EqualsLiteral("ADVANCED_LAYERS"))
378 return nsIGfxInfo::FEATURE_ADVANCED_LAYERS
;
379 else if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX"))
380 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
381 else if (aFeature
.EqualsLiteral("WEBRENDER"))
382 return nsIGfxInfo::FEATURE_WEBRENDER
;
383 else if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR"))
384 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
385 else if (aFeature
.EqualsLiteral("DX_NV12"))
386 return nsIGfxInfo::FEATURE_DX_NV12
;
387 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
388 // in downloadable blocklist.
389 else if (aFeature
.EqualsLiteral("GL_SWIZZLE"))
390 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
392 // If we don't recognize the feature, it may be new, and something
393 // this version doesn't understand. So, nothing to do. This is
394 // different from feature not being specified at all, in which case
395 // this method should not get called and we should continue with the
396 // "all features" blocklisting.
400 static int32_t BlacklistFeatureStatusToGfxFeatureStatus(
401 const nsAString
& aStatus
) {
402 if (aStatus
.EqualsLiteral("STATUS_OK"))
403 return nsIGfxInfo::FEATURE_STATUS_OK
;
404 else if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
405 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
406 else if (aStatus
.EqualsLiteral("BLOCKED_DEVICE"))
407 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
408 else if (aStatus
.EqualsLiteral("DISCOURAGED"))
409 return nsIGfxInfo::FEATURE_DISCOURAGED
;
410 else if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION"))
411 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
413 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
414 // expecting the "mismatch" status showing up here.
416 return nsIGfxInfo::FEATURE_STATUS_OK
;
419 static VersionComparisonOp
BlacklistComparatorToComparisonOp(
420 const nsAString
& op
) {
421 if (op
.EqualsLiteral("LESS_THAN"))
422 return DRIVER_LESS_THAN
;
423 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN"))
424 return DRIVER_BUILD_ID_LESS_THAN
;
425 else if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL"))
426 return DRIVER_LESS_THAN_OR_EQUAL
;
427 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
428 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
429 else if (op
.EqualsLiteral("GREATER_THAN"))
430 return DRIVER_GREATER_THAN
;
431 else if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
432 return DRIVER_GREATER_THAN_OR_EQUAL
;
433 else if (op
.EqualsLiteral("EQUAL"))
435 else if (op
.EqualsLiteral("NOT_EQUAL"))
436 return DRIVER_NOT_EQUAL
;
437 else if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE"))
438 return DRIVER_BETWEEN_EXCLUSIVE
;
439 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE"))
440 return DRIVER_BETWEEN_INCLUSIVE
;
441 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
442 return DRIVER_BETWEEN_INCLUSIVE_START
;
444 return DRIVER_COMPARISON_IGNORED
;
448 Deserialize Blacklist entries from string.
450 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
452 static bool BlacklistEntryToDriverInfo(nsCString
& aBlacklistEntry
,
453 GfxDriverInfo
& aDriverInfo
) {
454 // If we get an application version to be zero, something is not working
455 // and we are not going to bother checking the blocklist versions.
456 // See TestGfxWidgets.cpp for how version comparison works.
457 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
458 static mozilla::Version
zeroV("0");
459 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
461 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
462 << "Invalid application version "
463 << GfxInfoBase::GetApplicationVersion().get();
466 nsTArray
<nsCString
> keyValues
;
467 ParseString(aBlacklistEntry
, '\t', keyValues
);
469 aDriverInfo
.mRuleId
=
470 NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_NO_ID");
472 for (uint32_t i
= 0; i
< keyValues
.Length(); ++i
) {
473 nsCString keyValue
= keyValues
[i
];
474 nsTArray
<nsCString
> splitted
;
475 ParseString(keyValue
, ':', splitted
);
476 if (splitted
.Length() != 2) {
477 // If we don't recognize the input data, we do not want to proceed.
478 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
479 << "Unrecognized data " << keyValue
.get();
482 nsCString key
= splitted
[0];
483 nsCString value
= splitted
[1];
484 NS_ConvertUTF8toUTF16
dataValue(value
);
486 if (value
.Length() == 0) {
487 // Safety check for empty values.
488 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
489 << "Empty value for " << key
.get();
493 if (key
.EqualsLiteral("blockID")) {
494 nsCString blockIdStr
=
495 NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_") + value
;
496 aDriverInfo
.mRuleId
= blockIdStr
.get();
497 } else if (key
.EqualsLiteral("os")) {
498 aDriverInfo
.mOperatingSystem
= BlacklistOSToOperatingSystem(dataValue
);
499 } else if (key
.EqualsLiteral("osversion")) {
500 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
501 } else if (key
.EqualsLiteral("vendor")) {
502 aDriverInfo
.mAdapterVendor
= dataValue
;
503 } else if (key
.EqualsLiteral("driverVendor")) {
504 aDriverInfo
.mDriverVendor
= dataValue
;
505 } else if (key
.EqualsLiteral("feature")) {
506 aDriverInfo
.mFeature
= BlacklistFeatureToGfxFeature(dataValue
);
507 if (aDriverInfo
.mFeature
< 0) {
508 // If we don't recognize the feature, we do not want to proceed.
509 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
510 << "Unrecognized feature " << value
.get();
513 } else if (key
.EqualsLiteral("featureStatus")) {
514 aDriverInfo
.mFeatureStatus
=
515 BlacklistFeatureStatusToGfxFeatureStatus(dataValue
);
516 } else if (key
.EqualsLiteral("driverVersion")) {
518 if (ParseDriverVersion(dataValue
, &version
))
519 aDriverInfo
.mDriverVersion
= version
;
520 } else if (key
.EqualsLiteral("driverVersionMax")) {
522 if (ParseDriverVersion(dataValue
, &version
))
523 aDriverInfo
.mDriverVersionMax
= version
;
524 } else if (key
.EqualsLiteral("driverVersionComparator")) {
525 aDriverInfo
.mComparisonOp
= BlacklistComparatorToComparisonOp(dataValue
);
526 } else if (key
.EqualsLiteral("model")) {
527 aDriverInfo
.mModel
= dataValue
;
528 } else if (key
.EqualsLiteral("product")) {
529 aDriverInfo
.mProduct
= dataValue
;
530 } else if (key
.EqualsLiteral("manufacturer")) {
531 aDriverInfo
.mManufacturer
= dataValue
;
532 } else if (key
.EqualsLiteral("hardware")) {
533 aDriverInfo
.mHardware
= dataValue
;
534 } else if (key
.EqualsLiteral("versionRange")) {
535 nsTArray
<nsCString
> versionRange
;
536 ParseString(value
, ',', versionRange
);
537 if (versionRange
.Length() != 2) {
538 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
539 << "Unrecognized versionRange " << value
.get();
542 nsCString minValue
= versionRange
[0];
543 nsCString maxValue
= versionRange
[1];
545 mozilla::Version
minV(minValue
.get());
546 mozilla::Version
maxV(maxValue
.get());
548 if (minV
> zeroV
&& !(appV
>= minV
)) {
549 // The version of the application is less than the minimal version
550 // this blocklist entry applies to, so we can just ignore it by
551 // returning false and letting the caller deal with it.
554 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
555 // The version of the application is more than the maximal version
556 // this blocklist entry applies to, so we can just ignore it by
557 // returning false and letting the caller deal with it.
560 } else if (key
.EqualsLiteral("devices")) {
561 nsTArray
<nsCString
> devices
;
562 ParseString(value
, ',', devices
);
563 GfxDeviceFamily
* deviceIds
= BlacklistDevicesToDeviceFamily(devices
);
565 // Get GfxDriverInfo to adopt the devices array we created.
566 aDriverInfo
.mDeleteDevices
= true;
567 aDriverInfo
.mDevices
= deviceIds
;
570 // We explicitly ignore unknown elements.
576 static void BlacklistEntriesToDriverInfo(nsTArray
<nsCString
>& aBlacklistEntries
,
577 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
579 aDriverInfo
.SetLength(aBlacklistEntries
.Length());
581 for (uint32_t i
= 0; i
< aBlacklistEntries
.Length(); ++i
) {
582 nsCString blacklistEntry
= aBlacklistEntries
[i
];
584 if (BlacklistEntryToDriverInfo(blacklistEntry
, di
)) {
586 // Prevent di falling out of scope from destroying the devices.
587 di
.mDeleteDevices
= false;
593 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
594 const char16_t
* aData
) {
595 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
596 nsTArray
<GfxDriverInfo
> driverInfo
;
597 nsTArray
<nsCString
> blacklistEntries
;
598 nsCString utf8Data
= NS_ConvertUTF16toUTF8(aData
);
599 if (utf8Data
.Length() > 0) {
600 ParseString(utf8Data
, '\n', blacklistEntries
);
602 BlacklistEntriesToDriverInfo(blacklistEntries
, driverInfo
);
603 EvaluateDownloadedBlacklist(driverInfo
);
609 GfxInfoBase::GfxInfoBase() : mMutex("GfxInfoBase") {}
611 GfxInfoBase::~GfxInfoBase() {}
613 nsresult
GfxInfoBase::Init() {
614 InitGfxDriverInfoShutdownObserver();
616 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
618 os
->AddObserver(this, "blocklist-data-gfxItems", true);
625 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
627 // Ignore the gfx.blocklist.all pref on release and beta.
628 #if defined(RELEASE_OR_BETA)
629 int32_t blocklistAll
= 0;
631 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
633 if (blocklistAll
> 0) {
634 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
635 << "Forcing blocklisting all features";
636 *aStatus
= FEATURE_BLOCKED_DEVICE
;
637 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
639 } else if (blocklistAll
< 0) {
640 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
641 << "Ignoring any feature blocklisting.";
642 *aStatus
= FEATURE_STATUS_OK
;
646 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
650 if (XRE_IsContentProcess()) {
651 // Use the cached data received from the parent process.
652 MOZ_ASSERT(sFeatureStatus
);
653 bool success
= false;
654 for (const auto& fs
: *sFeatureStatus
) {
655 if (fs
.feature() == aFeature
) {
656 aFailureId
= fs
.failureId();
657 *aStatus
= fs
.status();
662 return success
? NS_OK
: NS_ERROR_FAILURE
;
666 nsTArray
<GfxDriverInfo
> driverInfo
;
668 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
672 void GfxInfoBase::GetAllFeatures(dom::XPCOMInitData
& xpcomInit
) {
673 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
674 if (!sFeatureStatus
) {
675 sFeatureStatus
= new nsTArray
<dom::GfxInfoFeatureStatus
>();
676 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
678 nsAutoCString failureId
;
679 GetFeatureStatus(i
, failureId
, &status
);
680 dom::GfxInfoFeatureStatus gfxFeatureStatus
;
681 gfxFeatureStatus
.feature() = i
;
682 gfxFeatureStatus
.status() = status
;
683 gfxFeatureStatus
.failureId() = failureId
;
684 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
687 for (const auto& status
: *sFeatureStatus
) {
688 dom::GfxInfoFeatureStatus copy
= status
;
689 xpcomInit
.gfxFeatureStatus().AppendElement(copy
);
693 // Matching OS go somewhat beyond the simple equality check because of the
694 // "All Windows" and "All OS X" variations.
696 // aBlockedOS is describing the system(s) we are trying to block.
697 // aSystemOS is describing the system we are running on.
699 // aSystemOS should not be "Windows" or "OSX" - it should be set to
700 // a particular version instead.
701 // However, it is valid for aBlockedOS to be one of those generic values,
702 // as we could be blocking all of the versions.
703 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
704 OperatingSystem aSystemOS
) {
705 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
706 aSystemOS
!= OperatingSystem::OSX
);
708 // If the block entry OS is unknown, it doesn't match
709 if (aBlockedOS
== OperatingSystem::Unknown
) {
714 if (aBlockedOS
== OperatingSystem::Windows
) {
715 // We do want even "unknown" aSystemOS to fall under "all windows"
720 #if defined(XP_MACOSX)
721 if (aBlockedOS
== OperatingSystem::OSX
) {
722 // We do want even "unknown" aSystemOS to fall under "all OS X"
727 return aSystemOS
== aBlockedOS
;
730 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
731 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
732 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
) {
733 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
735 // Get the adapters once then reuse below
736 nsAutoString adapterVendorID
[2];
737 nsAutoString adapterDeviceID
[2];
738 nsAutoString adapterDriverVendor
[2];
739 nsAutoString adapterDriverVersionString
[2];
740 bool adapterInfoFailed
[2];
742 adapterInfoFailed
[0] =
743 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
744 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
745 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
746 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
747 adapterInfoFailed
[1] =
748 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
749 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
750 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
751 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
752 // No point in going on if we don't have adapter info
753 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
757 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
758 uint64_t driverVersion
[2] = {0, 0};
759 if (!adapterInfoFailed
[0]) {
760 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
762 if (!adapterInfoFailed
[1]) {
763 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
768 for (; i
< info
.Length(); i
++) {
769 // If we don't have the info for this GPU, no need to check further.
770 // It is unclear that we would ever have a mixture of 1st and 2nd
771 // GPU, but leaving the code in for that possibility for now.
772 // (Actually, currently mGpu2 will never be true, so this can
773 // be optimized out.)
774 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
775 if (adapterInfoFailed
[infoIndex
]) {
779 // Do the operating system check first, no point in getting the driver
780 // info if we won't need to use it.
781 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
)) {
785 if (info
[i
].mOperatingSystemVersion
&&
786 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
790 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
794 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
795 adapterDriverVendor
[infoIndex
])) {
799 if (info
[i
].mDevices
!= GfxDriverInfo::allDevices
&&
800 info
[i
].mDevices
->Length()) {
801 bool deviceMatches
= false;
802 for (uint32_t j
= 0; j
< info
[i
].mDevices
->Length(); j
++) {
803 if ((*info
[i
].mDevices
)[j
].Equals(
804 adapterDeviceID
[infoIndex
],
805 nsCaseInsensitiveStringComparator())) {
806 deviceMatches
= true;
811 if (!deviceMatches
) {
818 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
821 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
824 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
827 if (!info
[i
].mManufacturer
.IsEmpty() &&
828 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
832 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
833 switch (info
[i
].mComparisonOp
) {
834 case DRIVER_LESS_THAN
:
835 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
837 case DRIVER_BUILD_ID_LESS_THAN
:
838 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
840 case DRIVER_LESS_THAN_OR_EQUAL
:
841 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
843 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
844 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
846 case DRIVER_GREATER_THAN
:
847 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
849 case DRIVER_GREATER_THAN_OR_EQUAL
:
850 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
853 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
855 case DRIVER_NOT_EQUAL
:
856 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
858 case DRIVER_BETWEEN_EXCLUSIVE
:
859 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
860 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
862 case DRIVER_BETWEEN_INCLUSIVE
:
863 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
864 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
866 case DRIVER_BETWEEN_INCLUSIVE_START
:
867 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
868 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
870 case DRIVER_COMPARISON_IGNORED
:
871 // We don't have a comparison op, so we match everything.
875 NS_WARNING("Bogus op in GfxDriverInfo");
879 // We don't care what driver version it was. We only check OS version and if
880 // the device matches.
884 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
885 if (info
[i
].mFeature
== GfxDriverInfo::allFeatures
||
886 info
[i
].mFeature
== aFeature
) {
887 status
= info
[i
].mFeatureStatus
;
888 if (!info
[i
].mRuleId
.IsEmpty()) {
889 aFailureId
= info
[i
].mRuleId
.get();
891 aFailureId
= "FEATURE_FAILURE_DL_BLACKLIST_NO_ID";
899 // As a very special case, we block D2D on machines with an NVidia 310M GPU
900 // as either the primary or secondary adapter. D2D is also blocked when the
901 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
902 // If the primary GPU already matched something in the blocklist then we
903 // ignore this special rule. See bug 1008759.
904 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
905 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
906 if (!adapterInfoFailed
[1]) {
907 nsAString
& nvVendorID
=
908 (nsAString
&)GfxDriverInfo::GetDeviceVendor(VendorNVIDIA
);
909 const nsString nv310mDeviceId
= NS_LITERAL_STRING("0x0A70");
910 if (nvVendorID
.Equals(adapterVendorID
[1],
911 nsCaseInsensitiveStringComparator()) &&
912 nv310mDeviceId
.Equals(adapterDeviceID
[1],
913 nsCaseInsensitiveStringComparator())) {
914 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
915 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
920 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
921 // back to the Windows handler, so we must handle this here.
922 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
923 if (info
[i
].mSuggestedVersion
) {
924 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
925 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
926 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
927 aSuggestedVersion
.AppendPrintf(
928 "%lld.%lld.%lld.%lld",
929 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
930 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
931 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
932 (info
[i
].mDriverVersion
& 0x000000000000ffff));
940 void GfxInfoBase::SetFeatureStatus(
941 const nsTArray
<dom::GfxInfoFeatureStatus
>& aFS
) {
942 MOZ_ASSERT(!sFeatureStatus
);
943 sFeatureStatus
= new nsTArray
<dom::GfxInfoFeatureStatus
>(aFS
);
946 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
947 const nsAString
& aAdapterVendor
) {
948 return aBlocklistVendor
.Equals(aAdapterVendor
,
949 nsCaseInsensitiveStringComparator()) ||
950 aBlocklistVendor
.Equals(GfxDriverInfo::GetDeviceVendor(VendorAll
),
951 nsCaseInsensitiveStringComparator());
954 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
955 const nsAString
& aDriverVendor
) {
956 return aBlocklistVendor
.Equals(aDriverVendor
,
957 nsCaseInsensitiveStringComparator()) ||
958 aBlocklistVendor
.Equals(
959 GfxDriverInfo::GetDriverVendor(DriverVendorAll
),
960 nsCaseInsensitiveStringComparator());
963 nsresult
GfxInfoBase::GetFeatureStatusImpl(
964 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
965 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
966 OperatingSystem
* aOS
/* = nullptr */) {
968 gfxWarning() << "Invalid feature <= 0";
972 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
973 // Terminate now with the status determined by the derived type (OS-specific
978 if (sShutdownOccurred
) {
979 // This is futile; we've already commenced shutdown and our blocklists have
980 // been deleted. We may want to look into resurrecting the blocklist instead
981 // but for now, just don't even go there.
985 // If an operating system was provided by the derived GetFeatureStatusImpl,
986 // grab it here. Otherwise, the OS is unknown.
987 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
989 nsAutoString adapterVendorID
;
990 nsAutoString adapterDeviceID
;
991 nsAutoString adapterDriverVersionString
;
992 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
993 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
994 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
995 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
996 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1000 // Check if the device is blocked from the downloaded blocklist. If not, check
1001 // the static list after that. This order is used so that we can later escape
1002 // out of static blocks (i.e. if we were wrong or something was patched, we
1003 // can back out our static block without doing a release).
1005 if (aDriverInfo
.Length()) {
1006 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1007 aFeature
, aFailureId
, os
);
1010 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1012 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1013 aFeature
, aFailureId
, os
);
1016 // It's now done being processed. It's safe to set the status to STATUS_OK.
1017 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1018 *aStatus
= nsIGfxInfo::FEATURE_STATUS_OK
;
1027 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1028 nsAString
& aVersion
) {
1030 if (GetPrefValueForDriverVersion(version
)) {
1031 aVersion
= NS_ConvertASCIItoUTF16(version
);
1036 nsCString discardFailureId
;
1037 nsTArray
<GfxDriverInfo
> driverInfo
;
1038 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1042 void GfxInfoBase::EvaluateDownloadedBlacklist(
1043 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1044 int32_t features
[] = {nsIGfxInfo::FEATURE_DIRECT2D
,
1045 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
,
1046 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
,
1047 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
,
1048 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
,
1049 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
,
1050 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
,
1051 nsIGfxInfo::FEATURE_OPENGL_LAYERS
,
1052 nsIGfxInfo::FEATURE_WEBGL_OPENGL
,
1053 nsIGfxInfo::FEATURE_WEBGL_ANGLE
,
1054 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
,
1055 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
,
1056 nsIGfxInfo::FEATURE_WEBGL_MSAA
,
1057 nsIGfxInfo::FEATURE_STAGEFRIGHT
,
1058 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
,
1059 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
,
1060 nsIGfxInfo::FEATURE_VP8_HW_DECODE
,
1061 nsIGfxInfo::FEATURE_VP9_HW_DECODE
,
1062 nsIGfxInfo::FEATURE_DX_INTEROP2
,
1063 nsIGfxInfo::FEATURE_GPU_PROCESS
,
1064 nsIGfxInfo::FEATURE_WEBGL2
,
1065 nsIGfxInfo::FEATURE_ADVANCED_LAYERS
,
1066 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
1067 nsIGfxInfo::FEATURE_WEBRENDER
,
1068 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
,
1069 nsIGfxInfo::FEATURE_DX_NV12
,
1070 nsIGfxInfo::FEATURE_DX_P010
,
1071 nsIGfxInfo::FEATURE_DX_P016
,
1072 nsIGfxInfo::FEATURE_GL_SWIZZLE
,
1075 // For every feature we know about, we evaluate whether this blacklist has a
1076 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1077 // GetFeatureStatus above, so we don't need to hold on to this blacklist
1078 // anywhere permanent.
1080 while (features
[i
]) {
1082 nsCString failureId
;
1083 nsAutoString suggestedVersion
;
1084 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1085 features
[i
], &status
, suggestedVersion
, aDriverInfo
, failureId
))) {
1088 case nsIGfxInfo::FEATURE_STATUS_OK
:
1089 RemovePrefForFeature(features
[i
]);
1092 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1093 if (!suggestedVersion
.IsEmpty()) {
1094 SetPrefValueForDriverVersion(suggestedVersion
);
1096 RemovePrefForDriverVersion();
1100 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1101 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1102 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1103 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1104 SetPrefValueForFeature(features
[i
], status
, failureId
);
1113 NS_IMETHODIMP_(void)
1114 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1115 // gfxCriticalError has a mutex lock of its own, so we may not actually
1116 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1117 // will not return the copy of the logs unless it can get the same lock
1118 // that gfxCriticalError uses. Still, that is so much of an implementation
1119 // detail that it's nicer to just add an extra lock here and in
1121 MutexAutoLock
lock(mMutex
);
1123 // By default, gfxCriticalError asserts; make it not assert in this case.
1124 gfxCriticalError(CriticalLog::DefaultOptions(false))
1125 << "(LF) " << failure
.BeginReading();
1128 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1129 nsTArray
<nsCString
>& failures
) {
1130 MutexAutoLock
lock(mMutex
);
1132 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1133 if (!logForwarder
) {
1134 return NS_ERROR_UNEXPECTED
;
1137 // There are two string copies in this method, starting with this one. We are
1138 // assuming this is not a big deal, as the size of the array should be small
1139 // and the strings in it should be small as well (the error messages in the
1140 // code.) The second copy happens with the AppendElement() calls.
1141 // Technically, we don't need the mutex lock after the StringVectorCopy()
1143 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1144 LoggingRecord::const_iterator it
;
1145 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1146 failures
.AppendElement(
1147 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1148 indices
.AppendElement(Get
<0>(*it
));
1154 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1156 static void InitCollectors() {
1157 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1160 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1161 JS::MutableHandle
<JS::Value
> aResult
) {
1163 InfoObject
obj(aCx
);
1165 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1166 (*sCollectors
)[i
]->GetInfo(obj
);
1169 // Some example property definitions
1170 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1171 // obj.DefineProperty("renderer", mRendererIDsString);
1172 // obj.DefineProperty("five", 5);
1175 return NS_ERROR_FAILURE
;
1178 aResult
.setObject(*obj
.mObj
);
1182 nsAutoCString gBaseAppVersion
;
1184 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1185 static bool versionInitialized
= false;
1186 if (!versionInitialized
) {
1187 // If we fail to get the version, we will not try again.
1188 versionInitialized
= true;
1190 // Get the version from xpcom/system/nsIXULAppInfo.idl
1191 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1193 app
->GetVersion(gBaseAppVersion
);
1196 return gBaseAppVersion
;
1199 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1201 sCollectors
->AppendElement(collector
);
1204 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1206 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1207 if ((*sCollectors
)[i
] == collector
) {
1208 sCollectors
->RemoveElementAt(i
);
1212 if (sCollectors
->IsEmpty()) {
1214 sCollectors
= nullptr;
1218 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
, JS::HandleObject aOutArray
) {
1219 // If we have no platform specific implementation for detecting monitors, we
1220 // can just get the screen size from gfxPlatform as the best guess.
1221 if (!gfxPlatform::Initialized()) {
1225 // If the screen size is empty, we are probably in xpcshell.
1226 gfx::IntSize screenSize
= gfxPlatform::GetPlatform()->GetScreenSize();
1228 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1230 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1231 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1233 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1234 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1236 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1237 JS_SetElement(aCx
, aOutArray
, 0, element
);
1243 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandleValue aResult
) {
1244 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1246 nsresult rv
= FindMonitors(aCx
, array
);
1247 if (NS_FAILED(rv
)) {
1251 aResult
.setObject(*array
);
1255 static inline bool SetJSPropertyString(JSContext
* aCx
,
1256 JS::Handle
<JSObject
*> aObj
,
1257 const char* aProp
, const char* aString
) {
1258 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1263 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1264 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1267 template <typename T
>
1268 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1271 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1274 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1277 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1278 JS::MutableHandle
<JS::Value
> aOut
) {
1279 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1281 return NS_ERROR_OUT_OF_MEMORY
;
1283 aOut
.setObject(*obj
);
1285 layers::LayersBackend backend
=
1286 gfxPlatform::Initialized()
1287 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1288 : layers::LayersBackend::LAYERS_NONE
;
1289 const char* backendName
= layers::GetLayersBackendName(backend
);
1290 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1292 // If graphics isn't initialized yet, just stop now.
1293 if (!gfxPlatform::Initialized()) {
1297 DescribeFeatures(aCx
, obj
);
1301 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1302 JS::MutableHandle
<JS::Value
> aOut
) {
1303 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1304 if (!containerObj
) {
1305 return NS_ERROR_OUT_OF_MEMORY
;
1307 aOut
.setObject(*containerObj
);
1309 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1310 if (!featureArray
) {
1311 return NS_ERROR_OUT_OF_MEMORY
;
1314 // Collect features.
1315 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1316 FeatureState
& aFeature
) -> void {
1317 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1321 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1322 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1323 !SetJSPropertyString(aCx
, obj
, "status",
1324 FeatureStatusToString(aFeature
.GetValue()))) {
1328 JS::Rooted
<JS::Value
> log(aCx
);
1329 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1332 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1336 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1341 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1342 if (!fallbackArray
) {
1343 return NS_ERROR_OUT_OF_MEMORY
;
1346 // Collect fallbacks.
1347 gfxConfig::ForEachFallback(
1348 [&](const char* aName
, const char* aMessage
) -> void {
1349 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1354 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1355 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1359 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1364 JS::Rooted
<JS::Value
> val(aCx
);
1366 val
= JS::ObjectValue(*featureArray
);
1367 JS_SetProperty(aCx
, containerObj
, "features", val
);
1369 val
= JS::ObjectValue(*fallbackArray
);
1370 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1375 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1376 const FeatureState
& aFeature
,
1377 JS::MutableHandle
<JS::Value
> aOut
) {
1378 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1382 aOut
.setObject(*log
);
1384 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1385 const char* aMessage
) -> void {
1386 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1391 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1392 !SetJSPropertyString(aCx
, obj
, "status",
1393 FeatureStatusToString(aStatus
)) ||
1394 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1398 if (!AppendJSElement(aCx
, log
, obj
)) {
1406 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1407 JS::Rooted
<JSObject
*> obj(aCx
);
1409 gfx::FeatureStatus gpuProcess
=
1410 gfxConfig::GetValue(gfx::Feature::GPU_PROCESS
);
1411 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1413 gfx::FeatureStatus wrQualified
=
1414 gfxConfig::GetValue(gfx::Feature::WEBRENDER_QUALIFIED
);
1415 InitFeatureObject(aCx
, aObj
, "wrQualified", wrQualified
, &obj
);
1417 gfx::FeatureStatus webrender
= gfxConfig::GetValue(gfx::Feature::WEBRENDER
);
1418 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1420 // Only include AL if the platform attempted to use it.
1421 gfx::FeatureStatus advancedLayers
=
1422 gfxConfig::GetValue(gfx::Feature::ADVANCED_LAYERS
);
1423 if (advancedLayers
!= FeatureStatus::Unused
) {
1424 InitFeatureObject(aCx
, aObj
, "advancedLayers", advancedLayers
, &obj
);
1426 if (gfxConfig::UseFallback(Fallback::NO_CONSTANT_BUFFER_OFFSETTING
)) {
1427 JS::Rooted
<JS::Value
> trueVal(aCx
, JS::BooleanValue(true));
1428 JS_SetProperty(aCx
, obj
, "noConstantBufferOffsetting", trueVal
);
1433 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1434 JS::Handle
<JSObject
*> aContainer
,
1436 mozilla::gfx::FeatureStatus
& aFeatureStatus
,
1437 JS::MutableHandle
<JSObject
*> aOutObj
) {
1438 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1444 const char* status
= FeatureStatusToString(aFeatureStatus
);
1446 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
));
1447 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1448 JS_SetProperty(aCx
, obj
, "status", val
);
1450 // Add the feature object to the container.
1452 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1453 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1460 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1461 JS::MutableHandle
<JS::Value
> aOut
) {
1462 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1464 return NS_ERROR_OUT_OF_MEMORY
;
1466 aOut
.setObject(*array
);
1468 DriverCrashGuard::ForEachActiveCrashGuard(
1469 [&](const char* aName
, const char* aPrefName
) -> void {
1470 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1474 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1477 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1480 if (!AppendJSElement(aCx
, array
, obj
)) {
1489 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled
) {
1490 *aWebRenderEnabled
= gfxVars::UseWebRender();
1495 GfxInfoBase::GetUsesTiling(bool* aUsesTiling
) {
1496 *aUsesTiling
= gfxPlatform::GetPlatform()->UsesTiling();
1501 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling
) {
1502 *aUsesTiling
= gfxPlatform::GetPlatform()->ContentUsesTiling();
1507 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled
) {
1508 *aOffMainThreadPaintEnabled
= gfxConfig::IsEnabled(gfx::Feature::OMTP
);
1513 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1514 int32_t* aOffMainThreadPaintWorkerCount
) {
1515 if (gfxConfig::IsEnabled(gfx::Feature::OMTP
)) {
1516 *aOffMainThreadPaintWorkerCount
=
1517 layers::PaintThread::CalculatePaintWorkerCount();
1519 *aOffMainThreadPaintWorkerCount
= 0;
1525 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1526 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1531 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1532 *aIsHeadless
= gfxPlatform::IsHeadless();
1537 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1538 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1542 case BackendType::DIRECT2D1_1
: {
1543 outStr
.AppendPrintf("Direct2D 1.1");
1546 case BackendType::SKIA
: {
1547 outStr
.AppendPrintf("Skia");
1550 case BackendType::CAIRO
: {
1551 outStr
.AppendPrintf("Cairo");
1555 return NS_ERROR_FAILURE
;
1558 aContentBackend
.Assign(outStr
);
1563 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1564 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1566 // Not supported in content processes.
1567 return NS_ERROR_FAILURE
;
1570 *aOutValue
= !!gpu
->GetGPUChild();
1575 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1576 gfxPlatform::GetPlatform();
1578 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1580 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1581 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1583 gpm
->LaunchGPUProcess();
1584 gpm
->EnsureGPUReady();
1586 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1594 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1595 GfxInfoBase::AddCollector(this);
1598 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1599 GfxInfoBase::RemoveCollector(this);