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 <mutex> // std::call_once
14 #include "GfxDriverInfo.h"
15 #include "js/Array.h" // JS::GetArrayLength, JS::NewArrayObject
16 #include "js/PropertyAndElement.h" // JS_SetElement, JS_SetProperty
18 #include "nsCOMArray.h"
20 #include "nsUnicharUtils.h"
21 #include "nsVersionComparator.h"
22 #include "mozilla/Services.h"
23 #include "mozilla/Observer.h"
24 #include "nsIObserver.h"
25 #include "nsIObserverService.h"
26 #include "nsIScreenManager.h"
28 #include "nsXULAppAPI.h"
29 #include "nsIXULAppInfo.h"
30 #include "mozilla/ClearOnShutdown.h"
31 #include "mozilla/Preferences.h"
32 #include "mozilla/StaticPrefs_gfx.h"
33 #include "mozilla/gfx/2D.h"
34 #include "mozilla/gfx/GPUProcessManager.h"
35 #include "mozilla/gfx/Logging.h"
36 #include "mozilla/gfx/gfxVars.h"
38 #include "gfxPlatform.h"
39 #include "gfxConfig.h"
40 #include "DriverCrashGuard.h"
42 using namespace mozilla::widget
;
43 using namespace mozilla
;
44 using mozilla::MutexAutoLock
;
46 nsTArray
<GfxDriverInfo
>* GfxInfoBase::sDriverInfo
;
47 StaticAutoPtr
<nsTArray
<gfx::GfxInfoFeatureStatus
>> GfxInfoBase::sFeatureStatus
;
48 bool GfxInfoBase::sDriverInfoObserverInitialized
;
49 bool GfxInfoBase::sShutdownOccurred
;
51 // Call this when setting sFeatureStatus to a non-null pointer to
52 // ensure destruction even if the GfxInfo component is never instantiated.
53 static void InitFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>* aPtr
) {
54 static std::once_flag sOnce
;
55 std::call_once(sOnce
, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus
); });
56 GfxInfoBase::sFeatureStatus
= aPtr
;
59 // Observes for shutdown so that the child GfxDriverInfo list is freed.
60 class ShutdownObserver
: public nsIObserver
{
61 virtual ~ShutdownObserver() = default;
64 ShutdownObserver() = default;
68 NS_IMETHOD
Observe(nsISupports
* subject
, const char* aTopic
,
69 const char16_t
* aData
) override
{
70 MOZ_ASSERT(strcmp(aTopic
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
) == 0);
72 delete GfxInfoBase::sDriverInfo
;
73 GfxInfoBase::sDriverInfo
= nullptr;
75 for (auto& deviceFamily
: GfxDriverInfo::sDeviceFamilies
) {
77 deviceFamily
= nullptr;
80 for (auto& desktop
: GfxDriverInfo::sDesktopEnvironment
) {
85 for (auto& windowProtocol
: GfxDriverInfo::sWindowProtocol
) {
86 delete windowProtocol
;
87 windowProtocol
= nullptr;
90 for (auto& deviceVendor
: GfxDriverInfo::sDeviceVendors
) {
92 deviceVendor
= nullptr;
95 for (auto& driverVendor
: GfxDriverInfo::sDriverVendors
) {
97 driverVendor
= nullptr;
100 GfxInfoBase::sShutdownOccurred
= true;
106 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
108 static void InitGfxDriverInfoShutdownObserver() {
109 if (GfxInfoBase::sDriverInfoObserverInitialized
) return;
111 GfxInfoBase::sDriverInfoObserverInitialized
= true;
113 nsCOMPtr
<nsIObserverService
> observerService
= services::GetObserverService();
114 if (!observerService
) {
115 NS_WARNING("Could not get observer service!");
119 ShutdownObserver
* obs
= new ShutdownObserver();
120 observerService
->AddObserver(obs
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
, false);
123 using namespace mozilla::widget
;
124 using namespace mozilla::gfx
;
125 using namespace mozilla
;
127 NS_IMPL_ISUPPORTS(GfxInfoBase
, nsIGfxInfo
, nsIObserver
,
128 nsISupportsWeakReference
)
130 #define BLOCKLIST_PREF_BRANCH "gfx.blacklist."
131 #define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
133 static const char* GetPrefNameForFeature(int32_t aFeature
) {
134 const char* name
= nullptr;
136 case nsIGfxInfo::FEATURE_DIRECT2D
:
137 name
= BLOCKLIST_PREF_BRANCH
"direct2d";
139 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
:
140 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d9";
142 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
:
143 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10";
145 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
:
146 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10-1";
148 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
:
149 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d11";
151 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
152 name
= BLOCKLIST_PREF_BRANCH
"direct3d11angle";
154 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
:
155 name
= BLOCKLIST_PREF_BRANCH
"hardwarevideodecoding";
157 case nsIGfxInfo::FEATURE_OPENGL_LAYERS
:
158 name
= BLOCKLIST_PREF_BRANCH
"layers.opengl";
160 case nsIGfxInfo::FEATURE_WEBGL_OPENGL
:
161 name
= BLOCKLIST_PREF_BRANCH
"webgl.opengl";
163 case nsIGfxInfo::FEATURE_WEBGL_ANGLE
:
164 name
= BLOCKLIST_PREF_BRANCH
"webgl.angle";
166 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
:
167 name
= BLOCKLIST_PREF_BRANCH
"webgl.msaa";
169 case nsIGfxInfo::FEATURE_STAGEFRIGHT
:
170 name
= BLOCKLIST_PREF_BRANCH
"stagefright";
172 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
:
173 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.h264";
175 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
:
176 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.encode";
178 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
:
179 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.decode";
181 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
:
182 name
= BLOCKLIST_PREF_BRANCH
"canvas2d.acceleration";
184 case nsIGfxInfo::FEATURE_DX_INTEROP2
:
185 name
= BLOCKLIST_PREF_BRANCH
"dx.interop2";
187 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
188 name
= BLOCKLIST_PREF_BRANCH
"gpu.process";
190 case nsIGfxInfo::FEATURE_WEBGL2
:
191 name
= BLOCKLIST_PREF_BRANCH
"webgl2";
193 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
:
194 name
= BLOCKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
196 case nsIGfxInfo::FEATURE_WEBRENDER
:
197 name
= BLOCKLIST_PREF_BRANCH
"webrender";
199 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
200 name
= BLOCKLIST_PREF_BRANCH
"webrender.compositor";
202 case nsIGfxInfo::FEATURE_DX_NV12
:
203 name
= BLOCKLIST_PREF_BRANCH
"dx.nv12";
205 case nsIGfxInfo::FEATURE_DX_P010
:
206 name
= BLOCKLIST_PREF_BRANCH
"dx.p010";
208 case nsIGfxInfo::FEATURE_DX_P016
:
209 name
= BLOCKLIST_PREF_BRANCH
"dx.p016";
211 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
212 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
213 // We don't provide prefs for these features as these are
214 // not handling downloadable blocklist.
216 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
217 name
= BLOCKLIST_PREF_BRANCH
"gl.swizzle";
219 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
:
220 name
= BLOCKLIST_PREF_BRANCH
"webrender.scissored_cache_clears";
222 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
223 name
= BLOCKLIST_PREF_BRANCH
"webgl.allow-oop";
225 case nsIGfxInfo::FEATURE_THREADSAFE_GL
:
226 name
= BLOCKLIST_PREF_BRANCH
"gl.threadsafe";
228 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS
:
229 name
= BLOCKLIST_PREF_BRANCH
"webrender.optimized-shaders";
231 case nsIGfxInfo::FEATURE_X11_EGL
:
232 name
= BLOCKLIST_PREF_BRANCH
"x11.egl";
234 case nsIGfxInfo::FEATURE_DMABUF
:
235 name
= BLOCKLIST_PREF_BRANCH
"dmabuf";
237 case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE
:
238 name
= BLOCKLIST_PREF_BRANCH
"webrender.program-binary-disk";
241 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
248 // Returns the value of the pref for the relevant feature in aValue.
249 // If the pref doesn't exist, aValue is not touched, and returns false.
250 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
251 nsACString
& aFailureId
) {
252 const char* prefname
= GetPrefNameForFeature(aFeature
);
253 if (!prefname
) return false;
255 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
256 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
260 nsCString
failureprefname(prefname
);
261 failureprefname
+= ".failureid";
262 nsAutoCString failureValue
;
263 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
264 if (NS_SUCCEEDED(rv
)) {
265 aFailureId
= failureValue
.get();
267 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
273 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
274 const nsACString
& aFailureId
) {
275 const char* prefname
= GetPrefNameForFeature(aFeature
);
276 if (!prefname
) return;
277 if (XRE_IsParentProcess()) {
278 GfxInfoBase::sFeatureStatus
= nullptr;
281 Preferences::SetInt(prefname
, aValue
);
282 if (!aFailureId
.IsEmpty()) {
283 nsCString
failureprefname(prefname
);
284 failureprefname
+= ".failureid";
285 Preferences::SetCString(failureprefname
.get(), aFailureId
);
289 static void RemovePrefForFeature(int32_t aFeature
) {
290 const char* prefname
= GetPrefNameForFeature(aFeature
);
291 if (!prefname
) return;
293 if (XRE_IsParentProcess()) {
294 GfxInfoBase::sFeatureStatus
= nullptr;
296 Preferences::ClearUser(prefname
);
299 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
301 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
304 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
305 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
308 static void RemovePrefForDriverVersion() {
309 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
312 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
313 if (os
.EqualsLiteral("WINNT 6.1")) {
314 return OperatingSystem::Windows7
;
316 if (os
.EqualsLiteral("WINNT 6.2")) {
317 return OperatingSystem::Windows8
;
319 if (os
.EqualsLiteral("WINNT 6.3")) {
320 return OperatingSystem::Windows8_1
;
322 if (os
.EqualsLiteral("WINNT 10.0")) {
323 return OperatingSystem::Windows10
;
325 if (os
.EqualsLiteral("Linux")) {
326 return OperatingSystem::Linux
;
328 if (os
.EqualsLiteral("Darwin 9")) {
329 return OperatingSystem::OSX10_5
;
331 if (os
.EqualsLiteral("Darwin 10")) {
332 return OperatingSystem::OSX10_6
;
334 if (os
.EqualsLiteral("Darwin 11")) {
335 return OperatingSystem::OSX10_7
;
337 if (os
.EqualsLiteral("Darwin 12")) {
338 return OperatingSystem::OSX10_8
;
340 if (os
.EqualsLiteral("Darwin 13")) {
341 return OperatingSystem::OSX10_9
;
343 if (os
.EqualsLiteral("Darwin 14")) {
344 return OperatingSystem::OSX10_10
;
346 if (os
.EqualsLiteral("Darwin 15")) {
347 return OperatingSystem::OSX10_11
;
349 if (os
.EqualsLiteral("Darwin 16")) {
350 return OperatingSystem::OSX10_12
;
352 if (os
.EqualsLiteral("Darwin 17")) {
353 return OperatingSystem::OSX10_13
;
355 if (os
.EqualsLiteral("Darwin 18")) {
356 return OperatingSystem::OSX10_14
;
358 if (os
.EqualsLiteral("Darwin 19")) {
359 return OperatingSystem::OSX10_15
;
361 if (os
.EqualsLiteral("Darwin 20")) {
362 return OperatingSystem::OSX11_0
;
364 if (os
.EqualsLiteral("Android")) {
365 return OperatingSystem::Android
;
366 // For historical reasons, "All" in blocklist means "All Windows"
368 if (os
.EqualsLiteral("All")) {
369 return OperatingSystem::Windows
;
371 if (os
.EqualsLiteral("Darwin")) {
372 return OperatingSystem::OSX
;
375 return OperatingSystem::Unknown
;
378 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
379 nsTArray
<nsCString
>& devices
) {
380 if (devices
.Length() == 0) return nullptr;
382 // For each device, get its device ID, and return a freshly-allocated
383 // GfxDeviceFamily with the contents of that array.
384 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
386 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
387 // We make sure we don't add any "empty" device entries to the array, so
388 // we don't need to check if devices[i] is empty.
389 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
395 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
396 MOZ_ASSERT(!aFeature
.IsEmpty());
397 if (aFeature
.EqualsLiteral("DIRECT2D")) {
398 return nsIGfxInfo::FEATURE_DIRECT2D
;
400 if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS")) {
401 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
403 if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS")) {
404 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
406 if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
407 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
409 if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS")) {
410 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
412 if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE")) {
413 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
415 if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
416 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
418 if (aFeature
.EqualsLiteral("OPENGL_LAYERS")) {
419 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
421 if (aFeature
.EqualsLiteral("WEBGL_OPENGL")) {
422 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
424 if (aFeature
.EqualsLiteral("WEBGL_ANGLE")) {
425 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
427 if (aFeature
.EqualsLiteral("WEBGL_MSAA")) {
428 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
430 if (aFeature
.EqualsLiteral("STAGEFRIGHT")) {
431 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
433 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
434 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
436 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
437 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
439 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
440 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
442 if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION")) {
443 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
445 if (aFeature
.EqualsLiteral("DX_INTEROP2")) {
446 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
448 if (aFeature
.EqualsLiteral("GPU_PROCESS")) {
449 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
451 if (aFeature
.EqualsLiteral("WEBGL2")) {
452 return nsIGfxInfo::FEATURE_WEBGL2
;
454 if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX")) {
455 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
457 if (aFeature
.EqualsLiteral("WEBRENDER")) {
458 return nsIGfxInfo::FEATURE_WEBRENDER
;
460 if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
461 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
463 if (aFeature
.EqualsLiteral("DX_NV12")) {
464 return nsIGfxInfo::FEATURE_DX_NV12
;
466 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
467 // in downloadable blocklist.
468 if (aFeature
.EqualsLiteral("GL_SWIZZLE")) {
469 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
471 if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
472 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
474 if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
475 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
477 if (aFeature
.EqualsLiteral("THREADSAFE_GL")) {
478 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
480 if (aFeature
.EqualsLiteral("X11_EGL")) {
481 return nsIGfxInfo::FEATURE_X11_EGL
;
483 if (aFeature
.EqualsLiteral("DMABUF")) {
484 return nsIGfxInfo::FEATURE_DMABUF
;
487 // If we don't recognize the feature, it may be new, and something
488 // this version doesn't understand. So, nothing to do. This is
489 // different from feature not being specified at all, in which case
490 // this method should not get called and we should continue with the
491 // "all features" blocklisting.
495 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
496 const nsAString
& aStatus
) {
497 if (aStatus
.EqualsLiteral("STATUS_OK")) {
498 return nsIGfxInfo::FEATURE_STATUS_OK
;
500 if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
501 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
503 if (aStatus
.EqualsLiteral("BLOCKED_DEVICE")) {
504 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
506 if (aStatus
.EqualsLiteral("DISCOURAGED")) {
507 return nsIGfxInfo::FEATURE_DISCOURAGED
;
509 if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION")) {
510 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
512 if (aStatus
.EqualsLiteral("DENIED")) {
513 return nsIGfxInfo::FEATURE_DENIED
;
515 if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED")) {
516 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
518 if (aStatus
.EqualsLiteral("ALLOW_ALWAYS")) {
519 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
522 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
523 // expecting the "mismatch" status showing up here.
525 return nsIGfxInfo::FEATURE_STATUS_OK
;
528 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
529 const nsAString
& op
) {
530 if (op
.EqualsLiteral("LESS_THAN")) {
531 return DRIVER_LESS_THAN
;
533 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN")) {
534 return DRIVER_BUILD_ID_LESS_THAN
;
536 if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
537 return DRIVER_LESS_THAN_OR_EQUAL
;
539 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
540 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
542 if (op
.EqualsLiteral("GREATER_THAN")) {
543 return DRIVER_GREATER_THAN
;
545 if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
546 return DRIVER_GREATER_THAN_OR_EQUAL
;
548 if (op
.EqualsLiteral("EQUAL")) {
551 if (op
.EqualsLiteral("NOT_EQUAL")) {
552 return DRIVER_NOT_EQUAL
;
554 if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
555 return DRIVER_BETWEEN_EXCLUSIVE
;
557 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE")) {
558 return DRIVER_BETWEEN_INCLUSIVE
;
560 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
561 return DRIVER_BETWEEN_INCLUSIVE_START
;
564 return DRIVER_COMPARISON_IGNORED
;
568 Deserialize Blocklist entries from string.
570 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
572 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
573 GfxDriverInfo
& aDriverInfo
) {
574 // If we get an application version to be zero, something is not working
575 // and we are not going to bother checking the blocklist versions.
576 // See TestGfxWidgets.cpp for how version comparison works.
577 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
578 static mozilla::Version
zeroV("0");
579 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
581 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
582 << "Invalid application version "
583 << GfxInfoBase::GetApplicationVersion().get();
586 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
588 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
589 nsTArray
<nsCString
> splitted
;
590 ParseString(keyValue
, ':', splitted
);
591 if (splitted
.Length() != 2) {
592 // If we don't recognize the input data, we do not want to proceed.
593 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
594 << "Unrecognized data " << nsCString(keyValue
).get();
597 const nsCString
& key
= splitted
[0];
598 const nsCString
& value
= splitted
[1];
599 NS_ConvertUTF8toUTF16
dataValue(value
);
601 if (value
.Length() == 0) {
602 // Safety check for empty values.
603 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
604 << "Empty value for " << key
.get();
608 if (key
.EqualsLiteral("blockID")) {
609 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
610 aDriverInfo
.mRuleId
= blockIdStr
.get();
611 } else if (key
.EqualsLiteral("os")) {
612 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
613 } else if (key
.EqualsLiteral("osversion")) {
614 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
615 } else if (key
.EqualsLiteral("desktopEnvironment")) {
616 aDriverInfo
.mDesktopEnvironment
= dataValue
;
617 } else if (key
.EqualsLiteral("windowProtocol")) {
618 aDriverInfo
.mWindowProtocol
= dataValue
;
619 } else if (key
.EqualsLiteral("vendor")) {
620 aDriverInfo
.mAdapterVendor
= dataValue
;
621 } else if (key
.EqualsLiteral("driverVendor")) {
622 aDriverInfo
.mDriverVendor
= dataValue
;
623 } else if (key
.EqualsLiteral("feature")) {
624 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
625 if (aDriverInfo
.mFeature
< 0) {
626 // If we don't recognize the feature, we do not want to proceed.
627 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
628 << "Unrecognized feature " << value
.get();
631 } else if (key
.EqualsLiteral("featureStatus")) {
632 aDriverInfo
.mFeatureStatus
=
633 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
634 } else if (key
.EqualsLiteral("driverVersion")) {
636 if (ParseDriverVersion(dataValue
, &version
))
637 aDriverInfo
.mDriverVersion
= version
;
638 } else if (key
.EqualsLiteral("driverVersionMax")) {
640 if (ParseDriverVersion(dataValue
, &version
))
641 aDriverInfo
.mDriverVersionMax
= version
;
642 } else if (key
.EqualsLiteral("driverVersionComparator")) {
643 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
644 } else if (key
.EqualsLiteral("model")) {
645 aDriverInfo
.mModel
= dataValue
;
646 } else if (key
.EqualsLiteral("product")) {
647 aDriverInfo
.mProduct
= dataValue
;
648 } else if (key
.EqualsLiteral("manufacturer")) {
649 aDriverInfo
.mManufacturer
= dataValue
;
650 } else if (key
.EqualsLiteral("hardware")) {
651 aDriverInfo
.mHardware
= dataValue
;
652 } else if (key
.EqualsLiteral("versionRange")) {
653 nsTArray
<nsCString
> versionRange
;
654 ParseString(value
, ',', versionRange
);
655 if (versionRange
.Length() != 2) {
656 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
657 << "Unrecognized versionRange " << value
.get();
660 const nsCString
& minValue
= versionRange
[0];
661 const nsCString
& maxValue
= versionRange
[1];
663 mozilla::Version
minV(minValue
.get());
664 mozilla::Version
maxV(maxValue
.get());
666 if (minV
> zeroV
&& !(appV
>= minV
)) {
667 // The version of the application is less than the minimal version
668 // this blocklist entry applies to, so we can just ignore it by
669 // returning false and letting the caller deal with it.
672 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
673 // The version of the application is more than the maximal version
674 // this blocklist entry applies to, so we can just ignore it by
675 // returning false and letting the caller deal with it.
678 } else if (key
.EqualsLiteral("devices")) {
679 nsTArray
<nsCString
> devices
;
680 ParseString(value
, ',', devices
);
681 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
683 // Get GfxDriverInfo to adopt the devices array we created.
684 aDriverInfo
.mDeleteDevices
= true;
685 aDriverInfo
.mDevices
= deviceIds
;
688 // We explicitly ignore unknown elements.
695 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
696 const char16_t
* aData
) {
697 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
698 nsTArray
<GfxDriverInfo
> driverInfo
;
699 NS_ConvertUTF16toUTF8
utf8Data(aData
);
701 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
703 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
704 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
705 // Probably some non-standard semantics of the copy/move operations?
706 *driverInfo
.AppendElement() = di
;
707 // Prevent di falling out of scope from destroying the devices.
708 di
.mDeleteDevices
= false;
710 driverInfo
.AppendElement();
714 EvaluateDownloadedBlocklist(driverInfo
);
720 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
722 GfxInfoBase::~GfxInfoBase() = default;
724 nsresult
GfxInfoBase::Init() {
725 InitGfxDriverInfoShutdownObserver();
727 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
729 os
->AddObserver(this, "blocklist-data-gfxItems", true);
735 void GfxInfoBase::GetData() {
736 if (mScreenPixels
!= INT64_MAX
) {
737 // Already initialized.
741 nsCOMPtr
<nsIScreenManager
> manager
=
742 do_GetService("@mozilla.org/gfx/screenmanager;1");
744 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
748 manager
->GetTotalScreenPixels(&mScreenPixels
);
752 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
754 // Ignore the gfx.blocklist.all pref on release and beta.
755 #if defined(RELEASE_OR_BETA)
756 int32_t blocklistAll
= 0;
758 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
760 if (blocklistAll
> 0) {
761 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
762 << "Forcing blocklisting all features";
763 *aStatus
= FEATURE_BLOCKED_DEVICE
;
764 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
768 if (blocklistAll
< 0) {
769 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
770 << "Ignoring any feature blocklisting.";
771 *aStatus
= FEATURE_STATUS_OK
;
775 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
779 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
780 // Use the cached data received from the parent process.
781 MOZ_ASSERT(sFeatureStatus
);
782 bool success
= false;
783 for (const auto& fs
: *sFeatureStatus
) {
784 if (fs
.feature() == aFeature
) {
785 aFailureId
= fs
.failureId();
786 *aStatus
= fs
.status();
791 return success
? NS_OK
: NS_ERROR_FAILURE
;
795 nsTArray
<GfxDriverInfo
> driverInfo
;
797 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
801 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
802 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
803 if (!sFeatureStatus
) {
804 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
805 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
807 nsAutoCString failureId
;
808 GetFeatureStatus(i
, failureId
, &status
);
809 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
810 gfxFeatureStatus
.feature() = i
;
811 gfxFeatureStatus
.status() = status
;
812 gfxFeatureStatus
.failureId() = failureId
;
813 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
817 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
818 for (const auto& status
: *sFeatureStatus
) {
819 gfx::GfxInfoFeatureStatus copy
= status
;
820 features
.AppendElement(copy
);
825 inline bool MatchingAllowStatus(int32_t aStatus
) {
827 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
828 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
835 // Matching OS go somewhat beyond the simple equality check because of the
836 // "All Windows" and "All OS X" variations.
838 // aBlockedOS is describing the system(s) we are trying to block.
839 // aSystemOS is describing the system we are running on.
841 // aSystemOS should not be "Windows" or "OSX" - it should be set to
842 // a particular version instead.
843 // However, it is valid for aBlockedOS to be one of those generic values,
844 // as we could be blocking all of the versions.
845 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
846 OperatingSystem aSystemOS
,
847 uint32_t aSystemOSBuild
) {
848 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
849 aSystemOS
!= OperatingSystem::OSX
);
851 // If the block entry OS is unknown, it doesn't match
852 if (aBlockedOS
== OperatingSystem::Unknown
) {
857 if (aBlockedOS
== OperatingSystem::Windows
) {
858 // We do want even "unknown" aSystemOS to fall under "all windows"
862 constexpr uint32_t kMinWin10BuildNumber
= 18362;
863 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
864 aSystemOS
== OperatingSystem::Windows10
) {
865 // For allowlist purposes, we sometimes want to restrict to only recent
866 // versions of Windows 10. This is a bit of a kludge but easier than adding
867 // complicated blocklist infrastructure for build ID comparisons like driver
869 return aSystemOSBuild
>= kMinWin10BuildNumber
;
872 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
873 if (aSystemOS
== OperatingSystem::Windows10
) {
874 return aSystemOSBuild
< kMinWin10BuildNumber
;
881 #if defined(XP_MACOSX)
882 if (aBlockedOS
== OperatingSystem::OSX
) {
883 // We do want even "unknown" aSystemOS to fall under "all OS X"
888 return aSystemOS
== aBlockedOS
;
891 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
892 switch (aBatteryStatus
) {
893 case BatteryStatus::All
:
895 case BatteryStatus::None
:
897 case BatteryStatus::Present
:
901 MOZ_ASSERT_UNREACHABLE("bad battery status");
905 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
906 int64_t aScreenPixels
) {
907 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
908 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
910 switch (aScreenStatus
) {
911 case ScreenSizeStatus::All
:
913 case ScreenSizeStatus::Small
:
914 return aScreenPixels
<= kMaxSmallPixels
;
915 case ScreenSizeStatus::SmallAndMedium
:
916 return aScreenPixels
<= kMaxMediumPixels
;
917 case ScreenSizeStatus::Medium
:
918 return aScreenPixels
> kMaxSmallPixels
&&
919 aScreenPixels
<= kMaxMediumPixels
;
920 case ScreenSizeStatus::MediumAndLarge
:
921 return aScreenPixels
> kMaxSmallPixels
;
922 case ScreenSizeStatus::Large
:
923 return aScreenPixels
> kMaxMediumPixels
;
926 MOZ_ASSERT_UNREACHABLE("bad screen status");
930 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
931 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
932 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
934 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
936 // Some properties are not available on all platforms.
937 nsAutoString desktopEnvironment
;
938 nsresult rv
= GetDesktopEnvironment(desktopEnvironment
);
939 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
943 nsAutoString windowProtocol
;
944 rv
= GetWindowProtocol(windowProtocol
);
945 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
949 bool hasBattery
= false;
950 rv
= GetHasBattery(&hasBattery
);
951 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
955 uint32_t osBuild
= OperatingSystemBuild();
957 // Get the adapters once then reuse below
958 nsAutoString adapterVendorID
[2];
959 nsAutoString adapterDeviceID
[2];
960 nsAutoString adapterDriverVendor
[2];
961 nsAutoString adapterDriverVersionString
[2];
962 bool adapterInfoFailed
[2];
964 adapterInfoFailed
[0] =
965 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
966 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
967 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
968 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
969 adapterInfoFailed
[1] =
970 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
971 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
972 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
973 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
974 // No point in going on if we don't have adapter info
975 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
979 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
980 uint64_t driverVersion
[2] = {0, 0};
981 if (!adapterInfoFailed
[0]) {
982 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
984 if (!adapterInfoFailed
[1]) {
985 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
990 for (; i
< info
.Length(); i
++) {
991 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
992 // blocklisting. Only consider entries for our search mode.
993 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
997 // If we don't have the info for this GPU, no need to check further.
998 // It is unclear that we would ever have a mixture of 1st and 2nd
999 // GPU, but leaving the code in for that possibility for now.
1000 // (Actually, currently mGpu2 will never be true, so this can
1001 // be optimized out.)
1002 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
1003 if (adapterInfoFailed
[infoIndex
]) {
1007 // Do the operating system check first, no point in getting the driver
1008 // info if we won't need to use it.
1009 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
1013 if (info
[i
].mOperatingSystemVersion
&&
1014 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
1018 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
1022 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
1026 if (!DoesDesktopEnvironmentMatch(info
[i
].mDesktopEnvironment
,
1027 desktopEnvironment
)) {
1031 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
1035 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
1039 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
1040 adapterDriverVendor
[infoIndex
])) {
1044 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
1045 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
1046 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
1051 // Failed to search, allowlist should not match, blocklist should match
1052 // for safety reasons
1062 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
1065 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
1068 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
1071 if (!info
[i
].mManufacturer
.IsEmpty() &&
1072 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1076 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1077 switch (info
[i
].mComparisonOp
) {
1078 case DRIVER_LESS_THAN
:
1079 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1081 case DRIVER_BUILD_ID_LESS_THAN
:
1082 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1084 case DRIVER_LESS_THAN_OR_EQUAL
:
1085 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1087 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1088 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1090 case DRIVER_GREATER_THAN
:
1091 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1093 case DRIVER_GREATER_THAN_OR_EQUAL
:
1094 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1097 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1099 case DRIVER_NOT_EQUAL
:
1100 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1102 case DRIVER_BETWEEN_EXCLUSIVE
:
1103 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1104 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1106 case DRIVER_BETWEEN_INCLUSIVE
:
1107 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1108 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1110 case DRIVER_BETWEEN_INCLUSIVE_START
:
1111 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1112 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1114 case DRIVER_COMPARISON_IGNORED
:
1115 // We don't have a comparison op, so we match everything.
1119 NS_WARNING("Bogus op in GfxDriverInfo");
1123 // We don't care what driver version it was. We only check OS version and if
1124 // the device matches.
1128 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1129 if (info
[i
].mFeature
== GfxDriverInfo::allFeatures
||
1130 info
[i
].mFeature
== aFeature
) {
1131 status
= info
[i
].mFeatureStatus
;
1132 if (!info
[i
].mRuleId
.IsEmpty()) {
1133 aFailureId
= info
[i
].mRuleId
.get();
1135 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1143 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1144 // as either the primary or secondary adapter. D2D is also blocked when the
1145 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1146 // If the primary GPU already matched something in the blocklist then we
1147 // ignore this special rule. See bug 1008759.
1148 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1149 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1150 if (!adapterInfoFailed
[1]) {
1151 nsAString
& nvVendorID
=
1152 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1153 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1154 if (nvVendorID
.Equals(adapterVendorID
[1],
1155 nsCaseInsensitiveStringComparator
) &&
1156 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1157 nsCaseInsensitiveStringComparator
)) {
1158 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1159 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1164 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1165 // back to the Windows handler, so we must handle this here.
1166 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1167 if (info
[i
].mSuggestedVersion
) {
1168 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1169 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1170 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1171 aSuggestedVersion
.AppendPrintf(
1172 "%lld.%lld.%lld.%lld",
1173 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1174 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1175 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1176 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1184 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1185 MOZ_ASSERT(!sFeatureStatus
);
1186 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1189 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1190 const nsAString
& aBlocklistDesktop
, const nsAString
& aDesktopEnv
) {
1191 return aBlocklistDesktop
.Equals(aDesktopEnv
,
1192 nsCaseInsensitiveStringComparator
) ||
1193 aBlocklistDesktop
.Equals(
1194 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All
),
1195 nsCaseInsensitiveStringComparator
);
1198 bool GfxInfoBase::DoesWindowProtocolMatch(
1199 const nsAString
& aBlocklistWindowProtocol
,
1200 const nsAString
& aWindowProtocol
) {
1201 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1202 nsCaseInsensitiveStringComparator
) ||
1203 aBlocklistWindowProtocol
.Equals(
1204 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1205 nsCaseInsensitiveStringComparator
);
1208 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1209 const nsAString
& aAdapterVendor
) {
1210 return aBlocklistVendor
.Equals(aAdapterVendor
,
1211 nsCaseInsensitiveStringComparator
) ||
1212 aBlocklistVendor
.Equals(
1213 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1214 nsCaseInsensitiveStringComparator
);
1217 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1218 const nsAString
& aDriverVendor
) {
1219 return aBlocklistVendor
.Equals(aDriverVendor
,
1220 nsCaseInsensitiveStringComparator
) ||
1221 aBlocklistVendor
.Equals(
1222 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1223 nsCaseInsensitiveStringComparator
);
1226 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1227 return aFeature
== nsIGfxInfo::FEATURE_WEBRENDER
;
1230 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1231 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1232 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1233 OperatingSystem
* aOS
/* = nullptr */) {
1234 if (aFeature
<= 0) {
1235 gfxWarning() << "Invalid feature <= 0";
1239 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1240 // Terminate now with the status determined by the derived type (OS-specific
1245 if (sShutdownOccurred
) {
1246 // This is futile; we've already commenced shutdown and our blocklists have
1247 // been deleted. We may want to look into resurrecting the blocklist instead
1248 // but for now, just don't even go there.
1252 // Ensure any additional initialization required is complete.
1255 // If an operating system was provided by the derived GetFeatureStatusImpl,
1256 // grab it here. Otherwise, the OS is unknown.
1257 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1259 nsAutoString adapterVendorID
;
1260 nsAutoString adapterDeviceID
;
1261 nsAutoString adapterDriverVersionString
;
1262 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1263 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1264 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1265 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1266 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1270 // Check if the device is blocked from the downloaded blocklist. If not, check
1271 // the static list after that. This order is used so that we can later escape
1272 // out of static blocks (i.e. if we were wrong or something was patched, we
1273 // can back out our static block without doing a release).
1275 if (aDriverInfo
.Length()) {
1277 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1278 aFailureId
, os
, /* aForAllowing */ false);
1281 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1283 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1284 aFeature
, aFailureId
, os
,
1285 /* aForAllowing */ false);
1288 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1289 if (IsFeatureAllowlisted(aFeature
)) {
1290 // This feature is actually using the allowlist; that means after we pass
1291 // the blocklist to prevent us explicitly from getting the feature, we now
1292 // need to check the allowlist to ensure we are allowed to get it in the
1294 if (aDriverInfo
.Length()) {
1295 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1296 aFeature
, aFailureId
, os
,
1297 /* aForAllowing */ true);
1299 status
= FindBlocklistedDeviceInList(
1300 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1301 /* aForAllowing */ true);
1304 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1305 status
= nsIGfxInfo::FEATURE_DENIED
;
1308 // It's now done being processed. It's safe to set the status to
1310 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1319 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1320 nsAString
& aVersion
) {
1322 if (GetPrefValueForDriverVersion(version
)) {
1323 aVersion
= NS_ConvertASCIItoUTF16(version
);
1328 nsCString discardFailureId
;
1329 nsTArray
<GfxDriverInfo
> driverInfo
;
1330 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1334 void GfxInfoBase::EvaluateDownloadedBlocklist(
1335 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1336 int32_t features
[] = {nsIGfxInfo::FEATURE_DIRECT2D
,
1337 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
,
1338 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
,
1339 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
,
1340 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
,
1341 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
,
1342 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
,
1343 nsIGfxInfo::FEATURE_OPENGL_LAYERS
,
1344 nsIGfxInfo::FEATURE_WEBGL_OPENGL
,
1345 nsIGfxInfo::FEATURE_WEBGL_ANGLE
,
1346 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
,
1347 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
,
1348 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
,
1349 nsIGfxInfo::FEATURE_STAGEFRIGHT
,
1350 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
,
1351 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
,
1352 nsIGfxInfo::FEATURE_VP8_HW_DECODE
,
1353 nsIGfxInfo::FEATURE_VP9_HW_DECODE
,
1354 nsIGfxInfo::FEATURE_DX_INTEROP2
,
1355 nsIGfxInfo::FEATURE_GPU_PROCESS
,
1356 nsIGfxInfo::FEATURE_WEBGL2
,
1357 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
1358 nsIGfxInfo::FEATURE_WEBRENDER
,
1359 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
,
1360 nsIGfxInfo::FEATURE_DX_NV12
,
1361 nsIGfxInfo::FEATURE_DX_P010
,
1362 nsIGfxInfo::FEATURE_DX_P016
,
1363 nsIGfxInfo::FEATURE_GL_SWIZZLE
,
1364 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
,
1365 nsIGfxInfo::FEATURE_X11_EGL
,
1366 nsIGfxInfo::FEATURE_DMABUF
,
1369 // For every feature we know about, we evaluate whether this blocklist has a
1370 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1371 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1372 // anywhere permanent.
1374 while (features
[i
]) {
1376 nsCString failureId
;
1377 nsAutoString suggestedVersion
;
1378 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1379 features
[i
], &status
, suggestedVersion
, aDriverInfo
, failureId
))) {
1382 case nsIGfxInfo::FEATURE_STATUS_OK
:
1383 RemovePrefForFeature(features
[i
]);
1386 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1387 if (!suggestedVersion
.IsEmpty()) {
1388 SetPrefValueForDriverVersion(suggestedVersion
);
1390 RemovePrefForDriverVersion();
1394 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1395 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1396 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1397 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1398 SetPrefValueForFeature(features
[i
], status
, failureId
);
1407 NS_IMETHODIMP_(void)
1408 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1409 // gfxCriticalError has a mutex lock of its own, so we may not actually
1410 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1411 // will not return the copy of the logs unless it can get the same lock
1412 // that gfxCriticalError uses. Still, that is so much of an implementation
1413 // detail that it's nicer to just add an extra lock here and in
1415 MutexAutoLock
lock(mMutex
);
1417 // By default, gfxCriticalError asserts; make it not assert in this case.
1418 gfxCriticalError(CriticalLog::DefaultOptions(false))
1419 << "(LF) " << failure
.BeginReading();
1422 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1423 nsTArray
<nsCString
>& failures
) {
1424 MutexAutoLock
lock(mMutex
);
1426 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1427 if (!logForwarder
) {
1428 return NS_ERROR_UNEXPECTED
;
1431 // There are two string copies in this method, starting with this one. We are
1432 // assuming this is not a big deal, as the size of the array should be small
1433 // and the strings in it should be small as well (the error messages in the
1434 // code.) The second copy happens with the AppendElement() calls.
1435 // Technically, we don't need the mutex lock after the StringVectorCopy()
1437 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1438 LoggingRecord::const_iterator it
;
1439 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1440 failures
.AppendElement(
1441 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1442 indices
.AppendElement(Get
<0>(*it
));
1448 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1450 static void InitCollectors() {
1451 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1454 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1455 JS::MutableHandle
<JS::Value
> aResult
) {
1457 InfoObject
obj(aCx
);
1459 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1460 (*sCollectors
)[i
]->GetInfo(obj
);
1463 // Some example property definitions
1464 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1465 // obj.DefineProperty("renderer", mRendererIDsString);
1466 // obj.DefineProperty("five", 5);
1469 return NS_ERROR_FAILURE
;
1472 aResult
.setObject(*obj
.mObj
);
1476 nsAutoCString gBaseAppVersion
;
1478 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1479 static bool versionInitialized
= false;
1480 if (!versionInitialized
) {
1481 // If we fail to get the version, we will not try again.
1482 versionInitialized
= true;
1484 // Get the version from xpcom/system/nsIXULAppInfo.idl
1485 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1487 app
->GetVersion(gBaseAppVersion
);
1490 return gBaseAppVersion
;
1493 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1495 sCollectors
->AppendElement(collector
);
1498 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1500 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1501 if ((*sCollectors
)[i
] == collector
) {
1502 sCollectors
->RemoveElementAt(i
);
1506 if (sCollectors
->IsEmpty()) {
1508 sCollectors
= nullptr;
1512 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
, JS::HandleObject aOutArray
) {
1513 // If we have no platform specific implementation for detecting monitors, we
1514 // can just get the screen size from gfxPlatform as the best guess.
1515 if (!gfxPlatform::Initialized()) {
1519 // If the screen size is empty, we are probably in xpcshell.
1520 gfx::IntSize screenSize
= gfxPlatform::GetPlatform()->GetScreenSize();
1522 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1524 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1525 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1527 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1528 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1530 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1531 JS_SetElement(aCx
, aOutArray
, 0, element
);
1537 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandleValue aResult
) {
1538 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1540 nsresult rv
= FindMonitors(aCx
, array
);
1541 if (NS_FAILED(rv
)) {
1545 aResult
.setObject(*array
);
1550 GfxInfoBase::RefreshMonitors() { return NS_ERROR_NOT_IMPLEMENTED
; }
1552 static inline bool SetJSPropertyString(JSContext
* aCx
,
1553 JS::Handle
<JSObject
*> aObj
,
1554 const char* aProp
, const char* aString
) {
1555 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1560 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1561 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1564 template <typename T
>
1565 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1568 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1571 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1574 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1575 JS::MutableHandle
<JS::Value
> aOut
) {
1576 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1578 return NS_ERROR_OUT_OF_MEMORY
;
1580 aOut
.setObject(*obj
);
1582 layers::LayersBackend backend
=
1583 gfxPlatform::Initialized()
1584 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1585 : layers::LayersBackend::LAYERS_NONE
;
1586 const char* backendName
= layers::GetLayersBackendName(backend
);
1587 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1589 // If graphics isn't initialized yet, just stop now.
1590 if (!gfxPlatform::Initialized()) {
1594 DescribeFeatures(aCx
, obj
);
1598 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1599 JS::MutableHandle
<JS::Value
> aOut
) {
1600 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1601 if (!containerObj
) {
1602 return NS_ERROR_OUT_OF_MEMORY
;
1604 aOut
.setObject(*containerObj
);
1606 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1607 if (!featureArray
) {
1608 return NS_ERROR_OUT_OF_MEMORY
;
1611 // Collect features.
1612 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1613 FeatureState
& aFeature
) -> void {
1614 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1618 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1619 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1620 !SetJSPropertyString(aCx
, obj
, "status",
1621 FeatureStatusToString(aFeature
.GetValue()))) {
1625 JS::Rooted
<JS::Value
> log(aCx
);
1626 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1629 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1633 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1638 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1639 if (!fallbackArray
) {
1640 return NS_ERROR_OUT_OF_MEMORY
;
1643 // Collect fallbacks.
1644 gfxConfig::ForEachFallback(
1645 [&](const char* aName
, const char* aMessage
) -> void {
1646 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1651 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1652 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1656 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1661 JS::Rooted
<JS::Value
> val(aCx
);
1663 val
= JS::ObjectValue(*featureArray
);
1664 JS_SetProperty(aCx
, containerObj
, "features", val
);
1666 val
= JS::ObjectValue(*fallbackArray
);
1667 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1672 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1673 const FeatureState
& aFeature
,
1674 JS::MutableHandle
<JS::Value
> aOut
) {
1675 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1679 aOut
.setObject(*log
);
1681 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1682 const char* aMessage
,
1683 const nsCString
& aFailureId
) -> void {
1684 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1689 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1690 !SetJSPropertyString(aCx
, obj
, "status",
1691 FeatureStatusToString(aStatus
)) ||
1692 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1696 if (!AppendJSElement(aCx
, log
, obj
)) {
1704 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1705 JS::Rooted
<JSObject
*> obj(aCx
);
1707 gfx::FeatureState
& hwCompositing
=
1708 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1709 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1711 gfx::FeatureState
& gpuProcess
=
1712 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1713 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1715 gfx::FeatureState
& wrQualified
=
1716 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_QUALIFIED
);
1717 InitFeatureObject(aCx
, aObj
, "wrQualified", wrQualified
, &obj
);
1719 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1720 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1722 gfx::FeatureState
& wrCompositor
=
1723 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1724 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1726 gfx::FeatureState
& wrSoftware
=
1727 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_SOFTWARE
);
1728 InitFeatureObject(aCx
, aObj
, "wrSoftware", wrSoftware
, &obj
);
1730 gfx::FeatureState
& openglCompositing
=
1731 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1732 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1734 gfx::FeatureState
& omtp
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1735 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1738 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1739 JS::Handle
<JSObject
*> aContainer
,
1741 mozilla::gfx::FeatureState
& aFeatureState
,
1742 JS::MutableHandle
<JSObject
*> aOutObj
) {
1743 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1748 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1750 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1751 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1752 JS_SetProperty(aCx
, obj
, "status", val
);
1754 // Add the feature object to the container.
1756 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1757 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1764 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1765 JS::MutableHandle
<JS::Value
> aOut
) {
1766 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1768 return NS_ERROR_OUT_OF_MEMORY
;
1770 aOut
.setObject(*array
);
1772 DriverCrashGuard::ForEachActiveCrashGuard(
1773 [&](const char* aName
, const char* aPrefName
) -> void {
1774 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1778 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1781 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1784 if (!AppendJSElement(aCx
, array
, obj
)) {
1793 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled
) {
1794 *aWebRenderEnabled
= gfxVars::UseWebRender();
1799 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1800 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1805 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1806 *aIsHeadless
= gfxPlatform::IsHeadless();
1811 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1812 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1816 case BackendType::DIRECT2D1_1
: {
1817 outStr
.AppendPrintf("Direct2D 1.1");
1820 case BackendType::SKIA
: {
1821 outStr
.AppendPrintf("Skia");
1824 case BackendType::CAIRO
: {
1825 outStr
.AppendPrintf("Cairo");
1829 return NS_ERROR_FAILURE
;
1832 aContentBackend
.Assign(outStr
);
1837 GfxInfoBase::GetAzureCanvasBackend(nsAString
& aBackend
) {
1838 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1839 gfxPlatform::GetPlatform()->GetAzureCanvasBackend()),
1845 GfxInfoBase::GetAzureContentBackend(nsAString
& aBackend
) {
1846 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1847 gfxPlatform::GetPlatform()->GetAzureContentBackend()),
1853 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1854 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1856 // Not supported in content processes.
1857 return NS_ERROR_FAILURE
;
1860 *aOutValue
= !!gpu
->GetGPUChild();
1865 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1866 gfxPlatform::GetPlatform();
1868 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1870 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1871 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1873 gpm
->LaunchGPUProcess();
1874 gpm
->EnsureGPUReady();
1876 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1884 NS_IMETHODIMP
GfxInfoBase::CrashGPUProcessForTests() {
1885 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1887 // gfxPlatform has not been initialized.
1888 return NS_ERROR_NOT_INITIALIZED
;
1891 gpm
->CrashProcess();
1895 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1896 GfxInfoBase::AddCollector(this);
1899 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1900 GfxInfoBase::RemoveCollector(this);