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 name
= BLOCKLIST_PREF_BRANCH
"vp8.hw-decode";
214 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
215 name
= BLOCKLIST_PREF_BRANCH
"vp9.hw-decode";
217 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
218 name
= BLOCKLIST_PREF_BRANCH
"gl.swizzle";
220 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
:
221 name
= BLOCKLIST_PREF_BRANCH
"webrender.scissored_cache_clears";
223 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
224 name
= BLOCKLIST_PREF_BRANCH
"webgl.allow-oop";
226 case nsIGfxInfo::FEATURE_THREADSAFE_GL
:
227 name
= BLOCKLIST_PREF_BRANCH
"gl.threadsafe";
229 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS
:
230 name
= BLOCKLIST_PREF_BRANCH
"webrender.optimized-shaders";
232 case nsIGfxInfo::FEATURE_X11_EGL
:
233 name
= BLOCKLIST_PREF_BRANCH
"x11.egl";
235 case nsIGfxInfo::FEATURE_DMABUF
:
236 name
= BLOCKLIST_PREF_BRANCH
"dmabuf";
238 case nsIGfxInfo::FEATURE_VAAPI
:
239 name
= BLOCKLIST_PREF_BRANCH
"vaapi";
241 case nsIGfxInfo::FEATURE_WEBGPU
:
242 name
= BLOCKLIST_PREF_BRANCH
"webgpu";
244 case nsIGfxInfo::FEATURE_VIDEO_OVERLAY
:
245 name
= BLOCKLIST_PREF_BRANCH
"video-overlay";
247 case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE
:
248 name
= BLOCKLIST_PREF_BRANCH
"webrender.program-binary-disk";
250 case nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
:
251 name
= BLOCKLIST_PREF_BRANCH
"webrender.partial-present";
254 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
261 // Returns the value of the pref for the relevant feature in aValue.
262 // If the pref doesn't exist, aValue is not touched, and returns false.
263 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
264 nsACString
& aFailureId
) {
265 const char* prefname
= GetPrefNameForFeature(aFeature
);
266 if (!prefname
) return false;
268 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
269 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
273 nsCString
failureprefname(prefname
);
274 failureprefname
+= ".failureid";
275 nsAutoCString failureValue
;
276 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
277 if (NS_SUCCEEDED(rv
)) {
278 aFailureId
= failureValue
.get();
280 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
286 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
287 const nsACString
& aFailureId
) {
288 const char* prefname
= GetPrefNameForFeature(aFeature
);
289 if (!prefname
) return;
290 if (XRE_IsParentProcess()) {
291 GfxInfoBase::sFeatureStatus
= nullptr;
294 Preferences::SetInt(prefname
, aValue
);
295 if (!aFailureId
.IsEmpty()) {
296 nsCString
failureprefname(prefname
);
297 failureprefname
+= ".failureid";
298 Preferences::SetCString(failureprefname
.get(), aFailureId
);
302 static void RemovePrefForFeature(int32_t aFeature
) {
303 const char* prefname
= GetPrefNameForFeature(aFeature
);
304 if (!prefname
) return;
306 if (XRE_IsParentProcess()) {
307 GfxInfoBase::sFeatureStatus
= nullptr;
309 Preferences::ClearUser(prefname
);
312 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
314 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
317 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
318 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
321 static void RemovePrefForDriverVersion() {
322 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
325 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
326 if (os
.EqualsLiteral("WINNT 6.1")) {
327 return OperatingSystem::Windows7
;
329 if (os
.EqualsLiteral("WINNT 6.2")) {
330 return OperatingSystem::Windows8
;
332 if (os
.EqualsLiteral("WINNT 6.3")) {
333 return OperatingSystem::Windows8_1
;
335 if (os
.EqualsLiteral("WINNT 10.0")) {
336 return OperatingSystem::Windows10
;
338 if (os
.EqualsLiteral("Linux")) {
339 return OperatingSystem::Linux
;
341 if (os
.EqualsLiteral("Darwin 9")) {
342 return OperatingSystem::OSX10_5
;
344 if (os
.EqualsLiteral("Darwin 10")) {
345 return OperatingSystem::OSX10_6
;
347 if (os
.EqualsLiteral("Darwin 11")) {
348 return OperatingSystem::OSX10_7
;
350 if (os
.EqualsLiteral("Darwin 12")) {
351 return OperatingSystem::OSX10_8
;
353 if (os
.EqualsLiteral("Darwin 13")) {
354 return OperatingSystem::OSX10_9
;
356 if (os
.EqualsLiteral("Darwin 14")) {
357 return OperatingSystem::OSX10_10
;
359 if (os
.EqualsLiteral("Darwin 15")) {
360 return OperatingSystem::OSX10_11
;
362 if (os
.EqualsLiteral("Darwin 16")) {
363 return OperatingSystem::OSX10_12
;
365 if (os
.EqualsLiteral("Darwin 17")) {
366 return OperatingSystem::OSX10_13
;
368 if (os
.EqualsLiteral("Darwin 18")) {
369 return OperatingSystem::OSX10_14
;
371 if (os
.EqualsLiteral("Darwin 19")) {
372 return OperatingSystem::OSX10_15
;
374 if (os
.EqualsLiteral("Darwin 20")) {
375 return OperatingSystem::OSX11_0
;
377 if (os
.EqualsLiteral("Android")) {
378 return OperatingSystem::Android
;
379 // For historical reasons, "All" in blocklist means "All Windows"
381 if (os
.EqualsLiteral("All")) {
382 return OperatingSystem::Windows
;
384 if (os
.EqualsLiteral("Darwin")) {
385 return OperatingSystem::OSX
;
388 return OperatingSystem::Unknown
;
391 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
392 nsTArray
<nsCString
>& devices
) {
393 if (devices
.Length() == 0) return nullptr;
395 // For each device, get its device ID, and return a freshly-allocated
396 // GfxDeviceFamily with the contents of that array.
397 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
399 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
400 // We make sure we don't add any "empty" device entries to the array, so
401 // we don't need to check if devices[i] is empty.
402 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
408 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
409 MOZ_ASSERT(!aFeature
.IsEmpty());
410 if (aFeature
.EqualsLiteral("DIRECT2D")) {
411 return nsIGfxInfo::FEATURE_DIRECT2D
;
413 if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS")) {
414 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
416 if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS")) {
417 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
419 if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
420 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
422 if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS")) {
423 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
425 if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE")) {
426 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
428 if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
429 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
431 if (aFeature
.EqualsLiteral("OPENGL_LAYERS")) {
432 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
434 if (aFeature
.EqualsLiteral("WEBGL_OPENGL")) {
435 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
437 if (aFeature
.EqualsLiteral("WEBGL_ANGLE")) {
438 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
440 if (aFeature
.EqualsLiteral("WEBGL_MSAA")) {
441 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
443 if (aFeature
.EqualsLiteral("STAGEFRIGHT")) {
444 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
446 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
447 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
449 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
450 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
452 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
453 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
455 if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION")) {
456 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
458 if (aFeature
.EqualsLiteral("DX_INTEROP2")) {
459 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
461 if (aFeature
.EqualsLiteral("GPU_PROCESS")) {
462 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
464 if (aFeature
.EqualsLiteral("WEBGL2")) {
465 return nsIGfxInfo::FEATURE_WEBGL2
;
467 if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX")) {
468 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
470 if (aFeature
.EqualsLiteral("WEBRENDER")) {
471 return nsIGfxInfo::FEATURE_WEBRENDER
;
473 if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
474 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
476 if (aFeature
.EqualsLiteral("DX_NV12")) {
477 return nsIGfxInfo::FEATURE_DX_NV12
;
479 if (aFeature
.EqualsLiteral("VP8_HW_DECODE")) {
480 return nsIGfxInfo::FEATURE_VP8_HW_DECODE
;
482 if (aFeature
.EqualsLiteral("VP9_HW_DECODE")) {
483 return nsIGfxInfo::FEATURE_VP9_HW_DECODE
;
485 if (aFeature
.EqualsLiteral("GL_SWIZZLE")) {
486 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
488 if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
489 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
491 if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
492 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
494 if (aFeature
.EqualsLiteral("THREADSAFE_GL")) {
495 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
497 if (aFeature
.EqualsLiteral("X11_EGL")) {
498 return nsIGfxInfo::FEATURE_X11_EGL
;
500 if (aFeature
.EqualsLiteral("DMABUF")) {
501 return nsIGfxInfo::FEATURE_DMABUF
;
503 if (aFeature
.EqualsLiteral("VAAPI")) {
504 return nsIGfxInfo::FEATURE_VAAPI
;
506 if (aFeature
.EqualsLiteral("WEBGPU")) {
507 return nsIGfxInfo::FEATURE_WEBGPU
;
509 if (aFeature
.EqualsLiteral("VIDEO_OVERLAY")) {
510 return nsIGfxInfo::FEATURE_VIDEO_OVERLAY
;
512 if (aFeature
.EqualsLiteral("WEBRENDER_PARTIAL_PRESENT")) {
513 return nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
;
516 // If we don't recognize the feature, it may be new, and something
517 // this version doesn't understand. So, nothing to do. This is
518 // different from feature not being specified at all, in which case
519 // this method should not get called and we should continue with the
520 // "all features" blocklisting.
524 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
525 const nsAString
& aStatus
) {
526 if (aStatus
.EqualsLiteral("STATUS_OK")) {
527 return nsIGfxInfo::FEATURE_STATUS_OK
;
529 if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
530 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
532 if (aStatus
.EqualsLiteral("BLOCKED_DEVICE")) {
533 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
535 if (aStatus
.EqualsLiteral("DISCOURAGED")) {
536 return nsIGfxInfo::FEATURE_DISCOURAGED
;
538 if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION")) {
539 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
541 if (aStatus
.EqualsLiteral("DENIED")) {
542 return nsIGfxInfo::FEATURE_DENIED
;
544 if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED")) {
545 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
547 if (aStatus
.EqualsLiteral("ALLOW_ALWAYS")) {
548 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
551 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
552 // expecting the "mismatch" status showing up here.
554 return nsIGfxInfo::FEATURE_STATUS_OK
;
557 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
558 const nsAString
& op
) {
559 if (op
.EqualsLiteral("LESS_THAN")) {
560 return DRIVER_LESS_THAN
;
562 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN")) {
563 return DRIVER_BUILD_ID_LESS_THAN
;
565 if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
566 return DRIVER_LESS_THAN_OR_EQUAL
;
568 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
569 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
571 if (op
.EqualsLiteral("GREATER_THAN")) {
572 return DRIVER_GREATER_THAN
;
574 if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
575 return DRIVER_GREATER_THAN_OR_EQUAL
;
577 if (op
.EqualsLiteral("EQUAL")) {
580 if (op
.EqualsLiteral("NOT_EQUAL")) {
581 return DRIVER_NOT_EQUAL
;
583 if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
584 return DRIVER_BETWEEN_EXCLUSIVE
;
586 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE")) {
587 return DRIVER_BETWEEN_INCLUSIVE
;
589 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
590 return DRIVER_BETWEEN_INCLUSIVE_START
;
593 return DRIVER_COMPARISON_IGNORED
;
597 Deserialize Blocklist entries from string.
599 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
601 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
602 GfxDriverInfo
& aDriverInfo
) {
603 // If we get an application version to be zero, something is not working
604 // and we are not going to bother checking the blocklist versions.
605 // See TestGfxWidgets.cpp for how version comparison works.
606 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
607 static mozilla::Version
zeroV("0");
608 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
610 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
611 << "Invalid application version "
612 << GfxInfoBase::GetApplicationVersion().get();
615 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
617 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
618 nsTArray
<nsCString
> splitted
;
619 ParseString(keyValue
, ':', splitted
);
620 if (splitted
.Length() != 2) {
621 // If we don't recognize the input data, we do not want to proceed.
622 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
623 << "Unrecognized data " << nsCString(keyValue
).get();
626 const nsCString
& key
= splitted
[0];
627 const nsCString
& value
= splitted
[1];
628 NS_ConvertUTF8toUTF16
dataValue(value
);
630 if (value
.Length() == 0) {
631 // Safety check for empty values.
632 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
633 << "Empty value for " << key
.get();
637 if (key
.EqualsLiteral("blockID")) {
638 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
639 aDriverInfo
.mRuleId
= blockIdStr
.get();
640 } else if (key
.EqualsLiteral("os")) {
641 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
642 } else if (key
.EqualsLiteral("osversion")) {
643 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
644 } else if (key
.EqualsLiteral("desktopEnvironment")) {
645 aDriverInfo
.mDesktopEnvironment
= dataValue
;
646 } else if (key
.EqualsLiteral("windowProtocol")) {
647 aDriverInfo
.mWindowProtocol
= dataValue
;
648 } else if (key
.EqualsLiteral("vendor")) {
649 aDriverInfo
.mAdapterVendor
= dataValue
;
650 } else if (key
.EqualsLiteral("driverVendor")) {
651 aDriverInfo
.mDriverVendor
= dataValue
;
652 } else if (key
.EqualsLiteral("feature")) {
653 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
654 if (aDriverInfo
.mFeature
< 0) {
655 // If we don't recognize the feature, we do not want to proceed.
656 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
657 << "Unrecognized feature " << value
.get();
660 } else if (key
.EqualsLiteral("featureStatus")) {
661 aDriverInfo
.mFeatureStatus
=
662 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
663 } else if (key
.EqualsLiteral("driverVersion")) {
665 if (ParseDriverVersion(dataValue
, &version
))
666 aDriverInfo
.mDriverVersion
= version
;
667 } else if (key
.EqualsLiteral("driverVersionMax")) {
669 if (ParseDriverVersion(dataValue
, &version
))
670 aDriverInfo
.mDriverVersionMax
= version
;
671 } else if (key
.EqualsLiteral("driverVersionComparator")) {
672 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
673 } else if (key
.EqualsLiteral("model")) {
674 aDriverInfo
.mModel
= dataValue
;
675 } else if (key
.EqualsLiteral("product")) {
676 aDriverInfo
.mProduct
= dataValue
;
677 } else if (key
.EqualsLiteral("manufacturer")) {
678 aDriverInfo
.mManufacturer
= dataValue
;
679 } else if (key
.EqualsLiteral("hardware")) {
680 aDriverInfo
.mHardware
= dataValue
;
681 } else if (key
.EqualsLiteral("versionRange")) {
682 nsTArray
<nsCString
> versionRange
;
683 ParseString(value
, ',', versionRange
);
684 if (versionRange
.Length() != 2) {
685 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
686 << "Unrecognized versionRange " << value
.get();
689 const nsCString
& minValue
= versionRange
[0];
690 const nsCString
& maxValue
= versionRange
[1];
692 mozilla::Version
minV(minValue
.get());
693 mozilla::Version
maxV(maxValue
.get());
695 if (minV
> zeroV
&& !(appV
>= minV
)) {
696 // The version of the application is less than the minimal version
697 // this blocklist entry applies to, so we can just ignore it by
698 // returning false and letting the caller deal with it.
701 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
702 // The version of the application is more than the maximal version
703 // this blocklist entry applies to, so we can just ignore it by
704 // returning false and letting the caller deal with it.
707 } else if (key
.EqualsLiteral("devices")) {
708 nsTArray
<nsCString
> devices
;
709 ParseString(value
, ',', devices
);
710 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
712 // Get GfxDriverInfo to adopt the devices array we created.
713 aDriverInfo
.mDeleteDevices
= true;
714 aDriverInfo
.mDevices
= deviceIds
;
717 // We explicitly ignore unknown elements.
724 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
725 const char16_t
* aData
) {
726 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
727 nsTArray
<GfxDriverInfo
> driverInfo
;
728 NS_ConvertUTF16toUTF8
utf8Data(aData
);
730 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
732 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
733 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
734 // Probably some non-standard semantics of the copy/move operations?
735 *driverInfo
.AppendElement() = di
;
736 // Prevent di falling out of scope from destroying the devices.
737 di
.mDeleteDevices
= false;
739 driverInfo
.AppendElement();
743 EvaluateDownloadedBlocklist(driverInfo
);
749 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
751 GfxInfoBase::~GfxInfoBase() = default;
753 nsresult
GfxInfoBase::Init() {
754 InitGfxDriverInfoShutdownObserver();
756 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
758 os
->AddObserver(this, "blocklist-data-gfxItems", true);
764 void GfxInfoBase::GetData() {
765 if (mScreenPixels
!= INT64_MAX
) {
766 // Already initialized.
770 nsCOMPtr
<nsIScreenManager
> manager
=
771 do_GetService("@mozilla.org/gfx/screenmanager;1");
773 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
777 manager
->GetTotalScreenPixels(&mScreenPixels
);
781 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
783 // Ignore the gfx.blocklist.all pref on release and beta.
784 #if defined(RELEASE_OR_BETA)
785 int32_t blocklistAll
= 0;
787 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
789 if (blocklistAll
> 0) {
790 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
791 << "Forcing blocklisting all features";
792 *aStatus
= FEATURE_BLOCKED_DEVICE
;
793 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
797 if (blocklistAll
< 0) {
798 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
799 << "Ignoring any feature blocklisting.";
800 *aStatus
= FEATURE_STATUS_OK
;
804 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
808 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
809 // Use the cached data received from the parent process.
810 MOZ_ASSERT(sFeatureStatus
);
811 bool success
= false;
812 for (const auto& fs
: *sFeatureStatus
) {
813 if (fs
.feature() == aFeature
) {
814 aFailureId
= fs
.failureId();
815 *aStatus
= fs
.status();
820 return success
? NS_OK
: NS_ERROR_FAILURE
;
824 nsTArray
<GfxDriverInfo
> driverInfo
;
826 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
830 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
831 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
832 if (!sFeatureStatus
) {
833 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
834 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
836 nsAutoCString failureId
;
837 GetFeatureStatus(i
, failureId
, &status
);
838 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
839 gfxFeatureStatus
.feature() = i
;
840 gfxFeatureStatus
.status() = status
;
841 gfxFeatureStatus
.failureId() = failureId
;
842 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
846 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
847 for (const auto& status
: *sFeatureStatus
) {
848 gfx::GfxInfoFeatureStatus copy
= status
;
849 features
.AppendElement(copy
);
854 inline bool MatchingAllowStatus(int32_t aStatus
) {
856 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
857 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
864 // Matching OS go somewhat beyond the simple equality check because of the
865 // "All Windows" and "All OS X" variations.
867 // aBlockedOS is describing the system(s) we are trying to block.
868 // aSystemOS is describing the system we are running on.
870 // aSystemOS should not be "Windows" or "OSX" - it should be set to
871 // a particular version instead.
872 // However, it is valid for aBlockedOS to be one of those generic values,
873 // as we could be blocking all of the versions.
874 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
875 OperatingSystem aSystemOS
,
876 uint32_t aSystemOSBuild
) {
877 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
878 aSystemOS
!= OperatingSystem::OSX
);
880 // If the block entry OS is unknown, it doesn't match
881 if (aBlockedOS
== OperatingSystem::Unknown
) {
886 if (aBlockedOS
== OperatingSystem::Windows
) {
887 // We do want even "unknown" aSystemOS to fall under "all windows"
891 constexpr uint32_t kMinWin10BuildNumber
= 18362;
892 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
893 aSystemOS
== OperatingSystem::Windows10
) {
894 // For allowlist purposes, we sometimes want to restrict to only recent
895 // versions of Windows 10. This is a bit of a kludge but easier than adding
896 // complicated blocklist infrastructure for build ID comparisons like driver
898 return aSystemOSBuild
>= kMinWin10BuildNumber
;
901 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
902 if (aSystemOS
== OperatingSystem::Windows10
) {
903 return aSystemOSBuild
< kMinWin10BuildNumber
;
910 #if defined(XP_MACOSX)
911 if (aBlockedOS
== OperatingSystem::OSX
) {
912 // We do want even "unknown" aSystemOS to fall under "all OS X"
917 return aSystemOS
== aBlockedOS
;
920 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
921 switch (aBatteryStatus
) {
922 case BatteryStatus::All
:
924 case BatteryStatus::None
:
926 case BatteryStatus::Present
:
930 MOZ_ASSERT_UNREACHABLE("bad battery status");
934 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
935 int64_t aScreenPixels
) {
936 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
937 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
939 switch (aScreenStatus
) {
940 case ScreenSizeStatus::All
:
942 case ScreenSizeStatus::Small
:
943 return aScreenPixels
<= kMaxSmallPixels
;
944 case ScreenSizeStatus::SmallAndMedium
:
945 return aScreenPixels
<= kMaxMediumPixels
;
946 case ScreenSizeStatus::Medium
:
947 return aScreenPixels
> kMaxSmallPixels
&&
948 aScreenPixels
<= kMaxMediumPixels
;
949 case ScreenSizeStatus::MediumAndLarge
:
950 return aScreenPixels
> kMaxSmallPixels
;
951 case ScreenSizeStatus::Large
:
952 return aScreenPixels
> kMaxMediumPixels
;
955 MOZ_ASSERT_UNREACHABLE("bad screen status");
959 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
960 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
961 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
963 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
965 // Some properties are not available on all platforms.
966 nsAutoString desktopEnvironment
;
967 nsresult rv
= GetDesktopEnvironment(desktopEnvironment
);
968 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
972 nsAutoString windowProtocol
;
973 rv
= GetWindowProtocol(windowProtocol
);
974 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
978 bool hasBattery
= false;
979 rv
= GetHasBattery(&hasBattery
);
980 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
984 uint32_t osBuild
= OperatingSystemBuild();
986 // Get the adapters once then reuse below
987 nsAutoString adapterVendorID
[2];
988 nsAutoString adapterDeviceID
[2];
989 nsAutoString adapterDriverVendor
[2];
990 nsAutoString adapterDriverVersionString
[2];
991 bool adapterInfoFailed
[2];
993 adapterInfoFailed
[0] =
994 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
995 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
996 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
997 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
998 adapterInfoFailed
[1] =
999 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
1000 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
1001 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
1002 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
1003 // No point in going on if we don't have adapter info
1004 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
1008 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1009 uint64_t driverVersion
[2] = {0, 0};
1010 if (!adapterInfoFailed
[0]) {
1011 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
1013 if (!adapterInfoFailed
[1]) {
1014 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
1019 for (; i
< info
.Length(); i
++) {
1020 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
1021 // blocklisting. Only consider entries for our search mode.
1022 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
1026 // If we don't have the info for this GPU, no need to check further.
1027 // It is unclear that we would ever have a mixture of 1st and 2nd
1028 // GPU, but leaving the code in for that possibility for now.
1029 // (Actually, currently mGpu2 will never be true, so this can
1030 // be optimized out.)
1031 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
1032 if (adapterInfoFailed
[infoIndex
]) {
1036 // Do the operating system check first, no point in getting the driver
1037 // info if we won't need to use it.
1038 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
1042 if (info
[i
].mOperatingSystemVersion
&&
1043 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
1047 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
1051 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
1055 if (!DoesDesktopEnvironmentMatch(info
[i
].mDesktopEnvironment
,
1056 desktopEnvironment
)) {
1060 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
1064 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
1068 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
1069 adapterDriverVendor
[infoIndex
])) {
1073 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
1074 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
1075 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
1080 // Failed to search, allowlist should not match, blocklist should match
1081 // for safety reasons
1091 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
1094 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
1097 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
1100 if (!info
[i
].mManufacturer
.IsEmpty() &&
1101 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1105 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1106 switch (info
[i
].mComparisonOp
) {
1107 case DRIVER_LESS_THAN
:
1108 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1110 case DRIVER_BUILD_ID_LESS_THAN
:
1111 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1113 case DRIVER_LESS_THAN_OR_EQUAL
:
1114 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1116 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1117 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1119 case DRIVER_GREATER_THAN
:
1120 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1122 case DRIVER_GREATER_THAN_OR_EQUAL
:
1123 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1126 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1128 case DRIVER_NOT_EQUAL
:
1129 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1131 case DRIVER_BETWEEN_EXCLUSIVE
:
1132 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1133 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1135 case DRIVER_BETWEEN_INCLUSIVE
:
1136 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1137 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1139 case DRIVER_BETWEEN_INCLUSIVE_START
:
1140 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1141 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1143 case DRIVER_COMPARISON_IGNORED
:
1144 // We don't have a comparison op, so we match everything.
1148 NS_WARNING("Bogus op in GfxDriverInfo");
1152 // We don't care what driver version it was. We only check OS version and if
1153 // the device matches.
1157 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1158 if (info
[i
].mFeature
== GfxDriverInfo::allFeatures
||
1159 info
[i
].mFeature
== aFeature
) {
1160 status
= info
[i
].mFeatureStatus
;
1161 if (!info
[i
].mRuleId
.IsEmpty()) {
1162 aFailureId
= info
[i
].mRuleId
.get();
1164 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1172 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1173 // as either the primary or secondary adapter. D2D is also blocked when the
1174 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1175 // If the primary GPU already matched something in the blocklist then we
1176 // ignore this special rule. See bug 1008759.
1177 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1178 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1179 if (!adapterInfoFailed
[1]) {
1180 nsAString
& nvVendorID
=
1181 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1182 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1183 if (nvVendorID
.Equals(adapterVendorID
[1],
1184 nsCaseInsensitiveStringComparator
) &&
1185 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1186 nsCaseInsensitiveStringComparator
)) {
1187 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1188 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1193 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1194 // back to the Windows handler, so we must handle this here.
1195 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1196 if (info
[i
].mSuggestedVersion
) {
1197 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1198 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1199 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1200 aSuggestedVersion
.AppendPrintf(
1201 "%lld.%lld.%lld.%lld",
1202 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1203 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1204 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1205 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1213 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1214 MOZ_ASSERT(!sFeatureStatus
);
1215 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1218 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1219 const nsAString
& aBlocklistDesktop
, const nsAString
& aDesktopEnv
) {
1220 return aBlocklistDesktop
.Equals(aDesktopEnv
,
1221 nsCaseInsensitiveStringComparator
) ||
1222 aBlocklistDesktop
.Equals(
1223 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All
),
1224 nsCaseInsensitiveStringComparator
);
1227 bool GfxInfoBase::DoesWindowProtocolMatch(
1228 const nsAString
& aBlocklistWindowProtocol
,
1229 const nsAString
& aWindowProtocol
) {
1230 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1231 nsCaseInsensitiveStringComparator
) ||
1232 aBlocklistWindowProtocol
.Equals(
1233 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1234 nsCaseInsensitiveStringComparator
);
1237 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1238 const nsAString
& aAdapterVendor
) {
1239 return aBlocklistVendor
.Equals(aAdapterVendor
,
1240 nsCaseInsensitiveStringComparator
) ||
1241 aBlocklistVendor
.Equals(
1242 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1243 nsCaseInsensitiveStringComparator
);
1246 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1247 const nsAString
& aDriverVendor
) {
1248 return aBlocklistVendor
.Equals(aDriverVendor
,
1249 nsCaseInsensitiveStringComparator
) ||
1250 aBlocklistVendor
.Equals(
1251 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1252 nsCaseInsensitiveStringComparator
);
1255 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1256 return aFeature
== nsIGfxInfo::FEATURE_WEBRENDER
||
1257 aFeature
== nsIGfxInfo::FEATURE_VIDEO_OVERLAY
;
1260 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1261 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1262 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1263 OperatingSystem
* aOS
/* = nullptr */) {
1264 if (aFeature
<= 0) {
1265 gfxWarning() << "Invalid feature <= 0";
1269 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1270 // Terminate now with the status determined by the derived type (OS-specific
1275 if (sShutdownOccurred
) {
1276 // This is futile; we've already commenced shutdown and our blocklists have
1277 // been deleted. We may want to look into resurrecting the blocklist instead
1278 // but for now, just don't even go there.
1282 // Ensure any additional initialization required is complete.
1285 // If an operating system was provided by the derived GetFeatureStatusImpl,
1286 // grab it here. Otherwise, the OS is unknown.
1287 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1289 nsAutoString adapterVendorID
;
1290 nsAutoString adapterDeviceID
;
1291 nsAutoString adapterDriverVersionString
;
1292 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1293 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1294 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1295 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1296 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1300 // Check if the device is blocked from the downloaded blocklist. If not, check
1301 // the static list after that. This order is used so that we can later escape
1302 // out of static blocks (i.e. if we were wrong or something was patched, we
1303 // can back out our static block without doing a release).
1305 if (aDriverInfo
.Length()) {
1307 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1308 aFailureId
, os
, /* aForAllowing */ false);
1311 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1313 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1314 aFeature
, aFailureId
, os
,
1315 /* aForAllowing */ false);
1318 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1319 if (IsFeatureAllowlisted(aFeature
)) {
1320 // This feature is actually using the allowlist; that means after we pass
1321 // the blocklist to prevent us explicitly from getting the feature, we now
1322 // need to check the allowlist to ensure we are allowed to get it in the
1324 if (aDriverInfo
.Length()) {
1325 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1326 aFeature
, aFailureId
, os
,
1327 /* aForAllowing */ true);
1329 status
= FindBlocklistedDeviceInList(
1330 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1331 /* aForAllowing */ true);
1334 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1335 status
= nsIGfxInfo::FEATURE_DENIED
;
1338 // It's now done being processed. It's safe to set the status to
1340 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1349 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1350 nsAString
& aVersion
) {
1352 if (GetPrefValueForDriverVersion(version
)) {
1353 aVersion
= NS_ConvertASCIItoUTF16(version
);
1358 nsCString discardFailureId
;
1359 nsTArray
<GfxDriverInfo
> driverInfo
;
1360 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1364 void GfxInfoBase::EvaluateDownloadedBlocklist(
1365 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1366 int32_t features
[] = {nsIGfxInfo::FEATURE_DIRECT2D
,
1367 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
,
1368 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
,
1369 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
,
1370 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
,
1371 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
,
1372 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
,
1373 nsIGfxInfo::FEATURE_OPENGL_LAYERS
,
1374 nsIGfxInfo::FEATURE_WEBGL_OPENGL
,
1375 nsIGfxInfo::FEATURE_WEBGL_ANGLE
,
1376 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
,
1377 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
,
1378 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
,
1379 nsIGfxInfo::FEATURE_STAGEFRIGHT
,
1380 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
,
1381 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
,
1382 nsIGfxInfo::FEATURE_VP8_HW_DECODE
,
1383 nsIGfxInfo::FEATURE_VP9_HW_DECODE
,
1384 nsIGfxInfo::FEATURE_DX_INTEROP2
,
1385 nsIGfxInfo::FEATURE_GPU_PROCESS
,
1386 nsIGfxInfo::FEATURE_WEBGL2
,
1387 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
1388 nsIGfxInfo::FEATURE_WEBRENDER
,
1389 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
,
1390 nsIGfxInfo::FEATURE_DX_NV12
,
1391 nsIGfxInfo::FEATURE_DX_P010
,
1392 nsIGfxInfo::FEATURE_DX_P016
,
1393 nsIGfxInfo::FEATURE_GL_SWIZZLE
,
1394 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
,
1395 nsIGfxInfo::FEATURE_X11_EGL
,
1396 nsIGfxInfo::FEATURE_DMABUF
,
1397 nsIGfxInfo::FEATURE_VAAPI
,
1398 nsIGfxInfo::FEATURE_WEBGPU
,
1399 nsIGfxInfo::FEATURE_VIDEO_OVERLAY
,
1400 nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
,
1403 // For every feature we know about, we evaluate whether this blocklist has a
1404 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1405 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1406 // anywhere permanent.
1408 while (features
[i
]) {
1410 nsCString failureId
;
1411 nsAutoString suggestedVersion
;
1412 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1413 features
[i
], &status
, suggestedVersion
, aDriverInfo
, failureId
))) {
1416 case nsIGfxInfo::FEATURE_STATUS_OK
:
1417 RemovePrefForFeature(features
[i
]);
1420 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1421 if (!suggestedVersion
.IsEmpty()) {
1422 SetPrefValueForDriverVersion(suggestedVersion
);
1424 RemovePrefForDriverVersion();
1428 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1429 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1430 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1431 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1432 SetPrefValueForFeature(features
[i
], status
, failureId
);
1441 NS_IMETHODIMP_(void)
1442 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1443 // gfxCriticalError has a mutex lock of its own, so we may not actually
1444 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1445 // will not return the copy of the logs unless it can get the same lock
1446 // that gfxCriticalError uses. Still, that is so much of an implementation
1447 // detail that it's nicer to just add an extra lock here and in
1449 MutexAutoLock
lock(mMutex
);
1451 // By default, gfxCriticalError asserts; make it not assert in this case.
1452 gfxCriticalError(CriticalLog::DefaultOptions(false))
1453 << "(LF) " << failure
.BeginReading();
1456 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1457 nsTArray
<nsCString
>& failures
) {
1458 MutexAutoLock
lock(mMutex
);
1460 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1461 if (!logForwarder
) {
1462 return NS_ERROR_UNEXPECTED
;
1465 // There are two string copies in this method, starting with this one. We are
1466 // assuming this is not a big deal, as the size of the array should be small
1467 // and the strings in it should be small as well (the error messages in the
1468 // code.) The second copy happens with the AppendElement() calls.
1469 // Technically, we don't need the mutex lock after the StringVectorCopy()
1471 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1472 LoggingRecord::const_iterator it
;
1473 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1474 failures
.AppendElement(
1475 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1476 indices
.AppendElement(Get
<0>(*it
));
1482 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1484 static void InitCollectors() {
1485 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1488 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1489 JS::MutableHandle
<JS::Value
> aResult
) {
1491 InfoObject
obj(aCx
);
1493 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1494 (*sCollectors
)[i
]->GetInfo(obj
);
1497 // Some example property definitions
1498 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1499 // obj.DefineProperty("renderer", mRendererIDsString);
1500 // obj.DefineProperty("five", 5);
1503 return NS_ERROR_FAILURE
;
1506 aResult
.setObject(*obj
.mObj
);
1510 nsAutoCString gBaseAppVersion
;
1512 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1513 static bool versionInitialized
= false;
1514 if (!versionInitialized
) {
1515 // If we fail to get the version, we will not try again.
1516 versionInitialized
= true;
1518 // Get the version from xpcom/system/nsIXULAppInfo.idl
1519 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1521 app
->GetVersion(gBaseAppVersion
);
1524 return gBaseAppVersion
;
1527 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1529 sCollectors
->AppendElement(collector
);
1532 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1534 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1535 if ((*sCollectors
)[i
] == collector
) {
1536 sCollectors
->RemoveElementAt(i
);
1540 if (sCollectors
->IsEmpty()) {
1542 sCollectors
= nullptr;
1546 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
, JS::HandleObject aOutArray
) {
1547 // If we have no platform specific implementation for detecting monitors, we
1548 // can just get the screen size from gfxPlatform as the best guess.
1549 if (!gfxPlatform::Initialized()) {
1553 // If the screen size is empty, we are probably in xpcshell.
1554 gfx::IntSize screenSize
= gfxPlatform::GetPlatform()->GetScreenSize();
1556 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1558 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1559 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1561 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1562 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1564 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1565 JS_SetElement(aCx
, aOutArray
, 0, element
);
1571 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandleValue aResult
) {
1572 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1574 nsresult rv
= FindMonitors(aCx
, array
);
1575 if (NS_FAILED(rv
)) {
1579 aResult
.setObject(*array
);
1584 GfxInfoBase::RefreshMonitors() { return NS_ERROR_NOT_IMPLEMENTED
; }
1586 static inline bool SetJSPropertyString(JSContext
* aCx
,
1587 JS::Handle
<JSObject
*> aObj
,
1588 const char* aProp
, const char* aString
) {
1589 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1594 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1595 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1598 template <typename T
>
1599 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1602 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1605 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1608 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1609 JS::MutableHandle
<JS::Value
> aOut
) {
1610 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1612 return NS_ERROR_OUT_OF_MEMORY
;
1614 aOut
.setObject(*obj
);
1616 layers::LayersBackend backend
=
1617 gfxPlatform::Initialized()
1618 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1619 : layers::LayersBackend::LAYERS_NONE
;
1620 const char* backendName
= layers::GetLayersBackendName(backend
);
1621 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1623 // If graphics isn't initialized yet, just stop now.
1624 if (!gfxPlatform::Initialized()) {
1628 DescribeFeatures(aCx
, obj
);
1632 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1633 JS::MutableHandle
<JS::Value
> aOut
) {
1634 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1635 if (!containerObj
) {
1636 return NS_ERROR_OUT_OF_MEMORY
;
1638 aOut
.setObject(*containerObj
);
1640 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1641 if (!featureArray
) {
1642 return NS_ERROR_OUT_OF_MEMORY
;
1645 // Collect features.
1646 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1647 FeatureState
& aFeature
) -> void {
1648 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1652 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1653 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1654 !SetJSPropertyString(aCx
, obj
, "status",
1655 FeatureStatusToString(aFeature
.GetValue()))) {
1659 JS::Rooted
<JS::Value
> log(aCx
);
1660 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1663 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1667 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1672 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1673 if (!fallbackArray
) {
1674 return NS_ERROR_OUT_OF_MEMORY
;
1677 // Collect fallbacks.
1678 gfxConfig::ForEachFallback(
1679 [&](const char* aName
, const char* aMessage
) -> void {
1680 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1685 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1686 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1690 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1695 JS::Rooted
<JS::Value
> val(aCx
);
1697 val
= JS::ObjectValue(*featureArray
);
1698 JS_SetProperty(aCx
, containerObj
, "features", val
);
1700 val
= JS::ObjectValue(*fallbackArray
);
1701 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1706 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1707 const FeatureState
& aFeature
,
1708 JS::MutableHandle
<JS::Value
> aOut
) {
1709 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1713 aOut
.setObject(*log
);
1715 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1716 const char* aMessage
,
1717 const nsCString
& aFailureId
) -> void {
1718 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1723 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1724 !SetJSPropertyString(aCx
, obj
, "status",
1725 FeatureStatusToString(aStatus
)) ||
1726 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1730 if (!AppendJSElement(aCx
, log
, obj
)) {
1738 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1739 JS::Rooted
<JSObject
*> obj(aCx
);
1741 gfx::FeatureState
& hwCompositing
=
1742 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1743 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1745 gfx::FeatureState
& gpuProcess
=
1746 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1747 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1749 gfx::FeatureState
& wrQualified
=
1750 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_QUALIFIED
);
1751 InitFeatureObject(aCx
, aObj
, "wrQualified", wrQualified
, &obj
);
1753 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1754 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1756 gfx::FeatureState
& wrCompositor
=
1757 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1758 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1760 gfx::FeatureState
& wrSoftware
=
1761 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_SOFTWARE
);
1762 InitFeatureObject(aCx
, aObj
, "wrSoftware", wrSoftware
, &obj
);
1764 gfx::FeatureState
& openglCompositing
=
1765 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1766 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1768 gfx::FeatureState
& omtp
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1769 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1772 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1773 JS::Handle
<JSObject
*> aContainer
,
1775 mozilla::gfx::FeatureState
& aFeatureState
,
1776 JS::MutableHandle
<JSObject
*> aOutObj
) {
1777 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1782 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1784 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1785 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1786 JS_SetProperty(aCx
, obj
, "status", val
);
1788 // Add the feature object to the container.
1790 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1791 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1798 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1799 JS::MutableHandle
<JS::Value
> aOut
) {
1800 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1802 return NS_ERROR_OUT_OF_MEMORY
;
1804 aOut
.setObject(*array
);
1806 DriverCrashGuard::ForEachActiveCrashGuard(
1807 [&](const char* aName
, const char* aPrefName
) -> void {
1808 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1812 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1815 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1818 if (!AppendJSElement(aCx
, array
, obj
)) {
1827 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled
) {
1828 *aWebRenderEnabled
= gfxVars::UseWebRender();
1833 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1834 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1839 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1840 *aIsHeadless
= gfxPlatform::IsHeadless();
1845 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1846 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1850 case BackendType::DIRECT2D1_1
: {
1851 outStr
.AppendPrintf("Direct2D 1.1");
1854 case BackendType::SKIA
: {
1855 outStr
.AppendPrintf("Skia");
1858 case BackendType::CAIRO
: {
1859 outStr
.AppendPrintf("Cairo");
1863 return NS_ERROR_FAILURE
;
1866 aContentBackend
.Assign(outStr
);
1871 GfxInfoBase::GetAzureCanvasBackend(nsAString
& aBackend
) {
1872 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1873 gfxPlatform::GetPlatform()->GetAzureCanvasBackend()),
1879 GfxInfoBase::GetAzureContentBackend(nsAString
& aBackend
) {
1880 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1881 gfxPlatform::GetPlatform()->GetAzureContentBackend()),
1887 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1888 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1890 // Not supported in content processes.
1891 return NS_ERROR_FAILURE
;
1894 *aOutValue
= !!gpu
->GetGPUChild();
1899 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1900 gfxPlatform::GetPlatform();
1902 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1904 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1905 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1907 gpm
->LaunchGPUProcess();
1908 gpm
->EnsureGPUReady();
1910 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1918 NS_IMETHODIMP
GfxInfoBase::KillGPUProcessForTests() {
1919 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1921 // gfxPlatform has not been initialized.
1922 return NS_ERROR_NOT_INITIALIZED
;
1929 NS_IMETHODIMP
GfxInfoBase::CrashGPUProcessForTests() {
1930 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1932 // gfxPlatform has not been initialized.
1933 return NS_ERROR_NOT_INITIALIZED
;
1936 gpm
->CrashProcess();
1940 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1941 GfxInfoBase::AddCollector(this);
1944 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1945 GfxInfoBase::RemoveCollector(this);