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"
27 #include "nsXULAppAPI.h"
28 #include "nsIXULAppInfo.h"
29 #include "mozilla/ClearOnShutdown.h"
30 #include "mozilla/Preferences.h"
31 #include "mozilla/StaticPrefs_gfx.h"
32 #include "mozilla/gfx/2D.h"
33 #include "mozilla/gfx/GPUProcessManager.h"
34 #include "mozilla/gfx/Logging.h"
35 #include "mozilla/gfx/gfxVars.h"
36 #include "mozilla/widget/ScreenManager.h"
37 #include "mozilla/widget/Screen.h"
39 #include "gfxPlatform.h"
40 #include "gfxConfig.h"
41 #include "DriverCrashGuard.h"
43 using namespace mozilla::widget
;
44 using namespace mozilla
;
45 using mozilla::MutexAutoLock
;
47 nsTArray
<GfxDriverInfo
>* GfxInfoBase::sDriverInfo
;
48 StaticAutoPtr
<nsTArray
<gfx::GfxInfoFeatureStatus
>> GfxInfoBase::sFeatureStatus
;
49 bool GfxInfoBase::sDriverInfoObserverInitialized
;
50 bool GfxInfoBase::sShutdownOccurred
;
52 // Call this when setting sFeatureStatus to a non-null pointer to
53 // ensure destruction even if the GfxInfo component is never instantiated.
54 static void InitFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>* aPtr
) {
55 static std::once_flag sOnce
;
56 std::call_once(sOnce
, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus
); });
57 GfxInfoBase::sFeatureStatus
= aPtr
;
60 // Observes for shutdown so that the child GfxDriverInfo list is freed.
61 class ShutdownObserver
: public nsIObserver
{
62 virtual ~ShutdownObserver() = default;
65 ShutdownObserver() = default;
69 NS_IMETHOD
Observe(nsISupports
* subject
, const char* aTopic
,
70 const char16_t
* aData
) override
{
71 MOZ_ASSERT(strcmp(aTopic
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
) == 0);
73 delete GfxInfoBase::sDriverInfo
;
74 GfxInfoBase::sDriverInfo
= nullptr;
76 for (auto& deviceFamily
: GfxDriverInfo::sDeviceFamilies
) {
78 deviceFamily
= nullptr;
81 for (auto& desktop
: GfxDriverInfo::sDesktopEnvironment
) {
86 for (auto& windowProtocol
: GfxDriverInfo::sWindowProtocol
) {
87 delete windowProtocol
;
88 windowProtocol
= nullptr;
91 for (auto& deviceVendor
: GfxDriverInfo::sDeviceVendors
) {
93 deviceVendor
= nullptr;
96 for (auto& driverVendor
: GfxDriverInfo::sDriverVendors
) {
98 driverVendor
= nullptr;
101 GfxInfoBase::sShutdownOccurred
= true;
107 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
109 static void InitGfxDriverInfoShutdownObserver() {
110 if (GfxInfoBase::sDriverInfoObserverInitialized
) return;
112 GfxInfoBase::sDriverInfoObserverInitialized
= true;
114 nsCOMPtr
<nsIObserverService
> observerService
= services::GetObserverService();
115 if (!observerService
) {
116 NS_WARNING("Could not get observer service!");
120 ShutdownObserver
* obs
= new ShutdownObserver();
121 observerService
->AddObserver(obs
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
, false);
124 using namespace mozilla::widget
;
125 using namespace mozilla::gfx
;
126 using namespace mozilla
;
128 NS_IMPL_ISUPPORTS(GfxInfoBase
, nsIGfxInfo
, nsIObserver
,
129 nsISupportsWeakReference
)
131 #define BLOCKLIST_PREF_BRANCH "gfx.blacklist."
132 #define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
134 static const char* GetPrefNameForFeature(int32_t aFeature
) {
135 const char* name
= nullptr;
137 case nsIGfxInfo::FEATURE_DIRECT2D
:
138 name
= BLOCKLIST_PREF_BRANCH
"direct2d";
140 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
:
141 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d9";
143 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
:
144 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10";
146 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
:
147 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10-1";
149 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
:
150 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d11";
152 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
153 name
= BLOCKLIST_PREF_BRANCH
"direct3d11angle";
155 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
:
156 name
= BLOCKLIST_PREF_BRANCH
"hardwarevideodecoding";
158 case nsIGfxInfo::FEATURE_OPENGL_LAYERS
:
159 name
= BLOCKLIST_PREF_BRANCH
"layers.opengl";
161 case nsIGfxInfo::FEATURE_WEBGL_OPENGL
:
162 name
= BLOCKLIST_PREF_BRANCH
"webgl.opengl";
164 case nsIGfxInfo::FEATURE_WEBGL_ANGLE
:
165 name
= BLOCKLIST_PREF_BRANCH
"webgl.angle";
167 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
:
168 name
= BLOCKLIST_PREF_BRANCH
"webgl.msaa";
170 case nsIGfxInfo::FEATURE_STAGEFRIGHT
:
171 name
= BLOCKLIST_PREF_BRANCH
"stagefright";
173 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
:
174 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.h264";
176 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
:
177 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.encode";
179 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
:
180 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.decode";
182 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
:
183 name
= BLOCKLIST_PREF_BRANCH
"canvas2d.acceleration";
185 case nsIGfxInfo::FEATURE_DX_INTEROP2
:
186 name
= BLOCKLIST_PREF_BRANCH
"dx.interop2";
188 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
189 name
= BLOCKLIST_PREF_BRANCH
"gpu.process";
191 case nsIGfxInfo::FEATURE_WEBGL2
:
192 name
= BLOCKLIST_PREF_BRANCH
"webgl2";
194 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
:
195 name
= BLOCKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
197 case nsIGfxInfo::FEATURE_WEBRENDER
:
198 name
= BLOCKLIST_PREF_BRANCH
"webrender";
200 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
201 name
= BLOCKLIST_PREF_BRANCH
"webrender.compositor";
203 case nsIGfxInfo::FEATURE_DX_NV12
:
204 name
= BLOCKLIST_PREF_BRANCH
"dx.nv12";
206 case nsIGfxInfo::FEATURE_DX_P010
:
207 name
= BLOCKLIST_PREF_BRANCH
"dx.p010";
209 case nsIGfxInfo::FEATURE_DX_P016
:
210 name
= BLOCKLIST_PREF_BRANCH
"dx.p016";
212 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
213 name
= BLOCKLIST_PREF_BRANCH
"vp8.hw-decode";
215 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
216 name
= BLOCKLIST_PREF_BRANCH
"vp9.hw-decode";
218 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
219 name
= BLOCKLIST_PREF_BRANCH
"gl.swizzle";
221 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
:
222 name
= BLOCKLIST_PREF_BRANCH
"webrender.scissored_cache_clears";
224 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
225 name
= BLOCKLIST_PREF_BRANCH
"webgl.allow-oop";
227 case nsIGfxInfo::FEATURE_THREADSAFE_GL
:
228 name
= BLOCKLIST_PREF_BRANCH
"gl.threadsafe";
230 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS
:
231 name
= BLOCKLIST_PREF_BRANCH
"webrender.optimized-shaders";
233 case nsIGfxInfo::FEATURE_X11_EGL
:
234 name
= BLOCKLIST_PREF_BRANCH
"x11.egl";
236 case nsIGfxInfo::FEATURE_DMABUF
:
237 name
= BLOCKLIST_PREF_BRANCH
"dmabuf";
239 case nsIGfxInfo::FEATURE_WEBGPU
:
240 name
= BLOCKLIST_PREF_BRANCH
"webgpu";
242 case nsIGfxInfo::FEATURE_VIDEO_OVERLAY
:
243 name
= BLOCKLIST_PREF_BRANCH
"video-overlay";
245 case nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
:
246 name
= BLOCKLIST_PREF_BRANCH
"hw-video-zero-copy";
248 case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE
:
249 name
= BLOCKLIST_PREF_BRANCH
"webrender.program-binary-disk";
251 case nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
:
252 name
= BLOCKLIST_PREF_BRANCH
"webrender.partial-present";
254 case nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT
:
255 name
= BLOCKLIST_PREF_BRANCH
"dmabuf.surface-export";
257 case nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
:
258 name
= BLOCKLIST_PREF_BRANCH
"reuse-decoder-device";
260 case nsIGfxInfo::FEATURE_BACKDROP_FILTER
:
261 name
= BLOCKLIST_PREF_BRANCH
"backdrop.filter";
264 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
271 // Returns the value of the pref for the relevant feature in aValue.
272 // If the pref doesn't exist, aValue is not touched, and returns false.
273 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
274 nsACString
& aFailureId
) {
275 const char* prefname
= GetPrefNameForFeature(aFeature
);
276 if (!prefname
) return false;
278 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
279 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
283 if (aValue
== nsIGfxInfo::FEATURE_DENIED
) {
284 // We should never see the DENIED status with the downloadable blocklist.
288 nsCString
failureprefname(prefname
);
289 failureprefname
+= ".failureid";
290 nsAutoCString failureValue
;
291 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
292 if (NS_SUCCEEDED(rv
)) {
293 aFailureId
= failureValue
.get();
295 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
301 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
302 const nsACString
& aFailureId
) {
303 const char* prefname
= GetPrefNameForFeature(aFeature
);
304 if (!prefname
) return;
305 if (XRE_IsParentProcess()) {
306 GfxInfoBase::sFeatureStatus
= nullptr;
309 Preferences::SetInt(prefname
, aValue
);
310 if (!aFailureId
.IsEmpty()) {
311 nsAutoCString
failureprefname(prefname
);
312 failureprefname
+= ".failureid";
313 Preferences::SetCString(failureprefname
.get(), aFailureId
);
317 static void RemovePrefForFeature(int32_t aFeature
) {
318 const char* prefname
= GetPrefNameForFeature(aFeature
);
319 if (!prefname
) return;
321 if (XRE_IsParentProcess()) {
322 GfxInfoBase::sFeatureStatus
= nullptr;
324 Preferences::ClearUser(prefname
);
327 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
329 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
332 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
333 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
336 static void RemovePrefForDriverVersion() {
337 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
340 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
341 if (os
.EqualsLiteral("WINNT 6.1")) {
342 return OperatingSystem::Windows7
;
344 if (os
.EqualsLiteral("WINNT 6.2")) {
345 return OperatingSystem::Windows8
;
347 if (os
.EqualsLiteral("WINNT 6.3")) {
348 return OperatingSystem::Windows8_1
;
350 if (os
.EqualsLiteral("WINNT 10.0")) {
351 return OperatingSystem::Windows10
;
353 if (os
.EqualsLiteral("Linux")) {
354 return OperatingSystem::Linux
;
356 if (os
.EqualsLiteral("Darwin 9")) {
357 return OperatingSystem::OSX10_5
;
359 if (os
.EqualsLiteral("Darwin 10")) {
360 return OperatingSystem::OSX10_6
;
362 if (os
.EqualsLiteral("Darwin 11")) {
363 return OperatingSystem::OSX10_7
;
365 if (os
.EqualsLiteral("Darwin 12")) {
366 return OperatingSystem::OSX10_8
;
368 if (os
.EqualsLiteral("Darwin 13")) {
369 return OperatingSystem::OSX10_9
;
371 if (os
.EqualsLiteral("Darwin 14")) {
372 return OperatingSystem::OSX10_10
;
374 if (os
.EqualsLiteral("Darwin 15")) {
375 return OperatingSystem::OSX10_11
;
377 if (os
.EqualsLiteral("Darwin 16")) {
378 return OperatingSystem::OSX10_12
;
380 if (os
.EqualsLiteral("Darwin 17")) {
381 return OperatingSystem::OSX10_13
;
383 if (os
.EqualsLiteral("Darwin 18")) {
384 return OperatingSystem::OSX10_14
;
386 if (os
.EqualsLiteral("Darwin 19")) {
387 return OperatingSystem::OSX10_15
;
389 if (os
.EqualsLiteral("Darwin 20")) {
390 return OperatingSystem::OSX11_0
;
392 if (os
.EqualsLiteral("Android")) {
393 return OperatingSystem::Android
;
394 // For historical reasons, "All" in blocklist means "All Windows"
396 if (os
.EqualsLiteral("All")) {
397 return OperatingSystem::Windows
;
399 if (os
.EqualsLiteral("Darwin")) {
400 return OperatingSystem::OSX
;
403 return OperatingSystem::Unknown
;
406 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
407 nsTArray
<nsCString
>& devices
) {
408 if (devices
.Length() == 0) return nullptr;
410 // For each device, get its device ID, and return a freshly-allocated
411 // GfxDeviceFamily with the contents of that array.
412 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
414 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
415 // We make sure we don't add any "empty" device entries to the array, so
416 // we don't need to check if devices[i] is empty.
417 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
423 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
424 MOZ_ASSERT(!aFeature
.IsEmpty());
425 if (aFeature
.EqualsLiteral("DIRECT2D")) {
426 return nsIGfxInfo::FEATURE_DIRECT2D
;
428 if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS")) {
429 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
431 if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS")) {
432 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
434 if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
435 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
437 if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS")) {
438 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
440 if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE")) {
441 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
443 if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
444 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
446 if (aFeature
.EqualsLiteral("OPENGL_LAYERS")) {
447 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
449 if (aFeature
.EqualsLiteral("WEBGL_OPENGL")) {
450 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
452 if (aFeature
.EqualsLiteral("WEBGL_ANGLE")) {
453 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
455 if (aFeature
.EqualsLiteral("WEBGL_MSAA")) {
456 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
458 if (aFeature
.EqualsLiteral("STAGEFRIGHT")) {
459 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
461 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
462 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
464 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
465 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
467 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
468 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
470 if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION")) {
471 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
473 if (aFeature
.EqualsLiteral("DX_INTEROP2")) {
474 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
476 if (aFeature
.EqualsLiteral("GPU_PROCESS")) {
477 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
479 if (aFeature
.EqualsLiteral("WEBGL2")) {
480 return nsIGfxInfo::FEATURE_WEBGL2
;
482 if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX")) {
483 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
485 if (aFeature
.EqualsLiteral("WEBRENDER")) {
486 return nsIGfxInfo::FEATURE_WEBRENDER
;
488 if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
489 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
491 if (aFeature
.EqualsLiteral("DX_NV12")) {
492 return nsIGfxInfo::FEATURE_DX_NV12
;
494 if (aFeature
.EqualsLiteral("VP8_HW_DECODE")) {
495 return nsIGfxInfo::FEATURE_VP8_HW_DECODE
;
497 if (aFeature
.EqualsLiteral("VP9_HW_DECODE")) {
498 return nsIGfxInfo::FEATURE_VP9_HW_DECODE
;
500 if (aFeature
.EqualsLiteral("GL_SWIZZLE")) {
501 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
503 if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
504 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
506 if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
507 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
509 if (aFeature
.EqualsLiteral("THREADSAFE_GL")) {
510 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
512 if (aFeature
.EqualsLiteral("X11_EGL")) {
513 return nsIGfxInfo::FEATURE_X11_EGL
;
515 if (aFeature
.EqualsLiteral("DMABUF")) {
516 return nsIGfxInfo::FEATURE_DMABUF
;
518 if (aFeature
.EqualsLiteral("WEBGPU")) {
519 return nsIGfxInfo::FEATURE_WEBGPU
;
521 if (aFeature
.EqualsLiteral("VIDEO_OVERLAY")) {
522 return nsIGfxInfo::FEATURE_VIDEO_OVERLAY
;
524 if (aFeature
.EqualsLiteral("HW_DECODED_VIDEO_ZERO_COPY")) {
525 return nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
;
527 if (aFeature
.EqualsLiteral("REUSE_DECODER_DEVICE")) {
528 return nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
;
530 if (aFeature
.EqualsLiteral("WEBRENDER_PARTIAL_PRESENT")) {
531 return nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
;
533 if (aFeature
.EqualsLiteral("BACKDROP_FILTER")) {
534 return nsIGfxInfo::FEATURE_BACKDROP_FILTER
;
537 // If we don't recognize the feature, it may be new, and something
538 // this version doesn't understand. So, nothing to do. This is
539 // different from feature not being specified at all, in which case
540 // this method should not get called and we should continue with the
541 // "all features" blocklisting.
545 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
546 const nsAString
& aStatus
) {
547 if (aStatus
.EqualsLiteral("STATUS_OK")) {
548 return nsIGfxInfo::FEATURE_STATUS_OK
;
550 if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
551 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
553 if (aStatus
.EqualsLiteral("BLOCKED_DEVICE")) {
554 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
556 if (aStatus
.EqualsLiteral("DISCOURAGED")) {
557 return nsIGfxInfo::FEATURE_DISCOURAGED
;
559 if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION")) {
560 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
562 if (aStatus
.EqualsLiteral("DENIED")) {
563 return nsIGfxInfo::FEATURE_DENIED
;
565 if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED")) {
566 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
568 if (aStatus
.EqualsLiteral("ALLOW_ALWAYS")) {
569 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
572 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
573 // expecting the "mismatch" status showing up here.
575 return nsIGfxInfo::FEATURE_STATUS_OK
;
578 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
579 const nsAString
& op
) {
580 if (op
.EqualsLiteral("LESS_THAN")) {
581 return DRIVER_LESS_THAN
;
583 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN")) {
584 return DRIVER_BUILD_ID_LESS_THAN
;
586 if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
587 return DRIVER_LESS_THAN_OR_EQUAL
;
589 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
590 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
592 if (op
.EqualsLiteral("GREATER_THAN")) {
593 return DRIVER_GREATER_THAN
;
595 if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
596 return DRIVER_GREATER_THAN_OR_EQUAL
;
598 if (op
.EqualsLiteral("EQUAL")) {
601 if (op
.EqualsLiteral("NOT_EQUAL")) {
602 return DRIVER_NOT_EQUAL
;
604 if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
605 return DRIVER_BETWEEN_EXCLUSIVE
;
607 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE")) {
608 return DRIVER_BETWEEN_INCLUSIVE
;
610 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
611 return DRIVER_BETWEEN_INCLUSIVE_START
;
614 return DRIVER_COMPARISON_IGNORED
;
618 Deserialize Blocklist entries from string.
620 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
622 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
623 GfxDriverInfo
& aDriverInfo
) {
624 // If we get an application version to be zero, something is not working
625 // and we are not going to bother checking the blocklist versions.
626 // See TestGfxWidgets.cpp for how version comparison works.
627 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
628 static mozilla::Version
zeroV("0");
629 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
631 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
632 << "Invalid application version "
633 << GfxInfoBase::GetApplicationVersion().get();
636 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
638 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
639 nsTArray
<nsCString
> splitted
;
640 ParseString(keyValue
, ':', splitted
);
641 if (splitted
.Length() != 2) {
642 // If we don't recognize the input data, we do not want to proceed.
643 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
644 << "Unrecognized data " << nsCString(keyValue
).get();
647 const nsCString
& key
= splitted
[0];
648 const nsCString
& value
= splitted
[1];
649 NS_ConvertUTF8toUTF16
dataValue(value
);
651 if (value
.Length() == 0) {
652 // Safety check for empty values.
653 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
654 << "Empty value for " << key
.get();
658 if (key
.EqualsLiteral("blockID")) {
659 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
660 aDriverInfo
.mRuleId
= blockIdStr
.get();
661 } else if (key
.EqualsLiteral("os")) {
662 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
663 } else if (key
.EqualsLiteral("osversion")) {
664 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
665 } else if (key
.EqualsLiteral("desktopEnvironment")) {
666 aDriverInfo
.mDesktopEnvironment
= dataValue
;
667 } else if (key
.EqualsLiteral("windowProtocol")) {
668 aDriverInfo
.mWindowProtocol
= dataValue
;
669 } else if (key
.EqualsLiteral("vendor")) {
670 aDriverInfo
.mAdapterVendor
= dataValue
;
671 } else if (key
.EqualsLiteral("driverVendor")) {
672 aDriverInfo
.mDriverVendor
= dataValue
;
673 } else if (key
.EqualsLiteral("feature")) {
674 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
675 if (aDriverInfo
.mFeature
< 0) {
676 // If we don't recognize the feature, we do not want to proceed.
677 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
678 << "Unrecognized feature " << value
.get();
681 } else if (key
.EqualsLiteral("featureStatus")) {
682 aDriverInfo
.mFeatureStatus
=
683 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
684 } else if (key
.EqualsLiteral("driverVersion")) {
686 if (ParseDriverVersion(dataValue
, &version
))
687 aDriverInfo
.mDriverVersion
= version
;
688 } else if (key
.EqualsLiteral("driverVersionMax")) {
690 if (ParseDriverVersion(dataValue
, &version
))
691 aDriverInfo
.mDriverVersionMax
= version
;
692 } else if (key
.EqualsLiteral("driverVersionComparator")) {
693 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
694 } else if (key
.EqualsLiteral("model")) {
695 aDriverInfo
.mModel
= dataValue
;
696 } else if (key
.EqualsLiteral("product")) {
697 aDriverInfo
.mProduct
= dataValue
;
698 } else if (key
.EqualsLiteral("manufacturer")) {
699 aDriverInfo
.mManufacturer
= dataValue
;
700 } else if (key
.EqualsLiteral("hardware")) {
701 aDriverInfo
.mHardware
= dataValue
;
702 } else if (key
.EqualsLiteral("versionRange")) {
703 nsTArray
<nsCString
> versionRange
;
704 ParseString(value
, ',', versionRange
);
705 if (versionRange
.Length() != 2) {
706 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
707 << "Unrecognized versionRange " << value
.get();
710 const nsCString
& minValue
= versionRange
[0];
711 const nsCString
& maxValue
= versionRange
[1];
713 mozilla::Version
minV(minValue
.get());
714 mozilla::Version
maxV(maxValue
.get());
716 if (minV
> zeroV
&& !(appV
>= minV
)) {
717 // The version of the application is less than the minimal version
718 // this blocklist entry applies to, so we can just ignore it by
719 // returning false and letting the caller deal with it.
722 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
723 // The version of the application is more than the maximal version
724 // this blocklist entry applies to, so we can just ignore it by
725 // returning false and letting the caller deal with it.
728 } else if (key
.EqualsLiteral("devices")) {
729 nsTArray
<nsCString
> devices
;
730 ParseString(value
, ',', devices
);
731 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
733 // Get GfxDriverInfo to adopt the devices array we created.
734 aDriverInfo
.mDeleteDevices
= true;
735 aDriverInfo
.mDevices
= deviceIds
;
738 // We explicitly ignore unknown elements.
745 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
746 const char16_t
* aData
) {
747 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
748 nsTArray
<GfxDriverInfo
> driverInfo
;
749 NS_ConvertUTF16toUTF8
utf8Data(aData
);
751 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
753 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
754 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
755 // Probably some non-standard semantics of the copy/move operations?
756 *driverInfo
.AppendElement() = di
;
757 // Prevent di falling out of scope from destroying the devices.
758 di
.mDeleteDevices
= false;
760 driverInfo
.AppendElement();
764 EvaluateDownloadedBlocklist(driverInfo
);
770 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
772 GfxInfoBase::~GfxInfoBase() = default;
774 nsresult
GfxInfoBase::Init() {
775 InitGfxDriverInfoShutdownObserver();
777 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
779 os
->AddObserver(this, "blocklist-data-gfxItems", true);
785 void GfxInfoBase::GetData() {
786 if (mScreenPixels
!= INT64_MAX
) {
787 // Already initialized.
791 ScreenManager::GetSingleton().GetTotalScreenPixels(&mScreenPixels
);
795 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
797 // Ignore the gfx.blocklist.all pref on release and beta.
798 #if defined(RELEASE_OR_BETA)
799 int32_t blocklistAll
= 0;
801 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
803 if (blocklistAll
> 0) {
804 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
805 << "Forcing blocklisting all features";
806 *aStatus
= FEATURE_BLOCKED_DEVICE
;
807 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
811 if (blocklistAll
< 0) {
812 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
813 << "Ignoring any feature blocklisting.";
814 *aStatus
= FEATURE_STATUS_OK
;
818 // This is how we evaluate the downloadable blocklist. If there is no pref,
819 // then we will fallback to checking the static blocklist.
820 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
824 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
825 // Use the cached data received from the parent process.
826 MOZ_ASSERT(sFeatureStatus
);
827 bool success
= false;
828 for (const auto& fs
: *sFeatureStatus
) {
829 if (fs
.feature() == aFeature
) {
830 aFailureId
= fs
.failureId();
831 *aStatus
= fs
.status();
836 return success
? NS_OK
: NS_ERROR_FAILURE
;
840 nsTArray
<GfxDriverInfo
> driverInfo
;
842 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
846 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
847 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
848 if (!sFeatureStatus
) {
849 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
850 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
852 nsAutoCString failureId
;
853 GetFeatureStatus(i
, failureId
, &status
);
854 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
855 gfxFeatureStatus
.feature() = i
;
856 gfxFeatureStatus
.status() = status
;
857 gfxFeatureStatus
.failureId() = failureId
;
858 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
862 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
863 for (const auto& status
: *sFeatureStatus
) {
864 gfx::GfxInfoFeatureStatus copy
= status
;
865 features
.AppendElement(copy
);
870 inline bool MatchingAllowStatus(int32_t aStatus
) {
872 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
873 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
880 // Matching OS go somewhat beyond the simple equality check because of the
881 // "All Windows" and "All OS X" variations.
883 // aBlockedOS is describing the system(s) we are trying to block.
884 // aSystemOS is describing the system we are running on.
886 // aSystemOS should not be "Windows" or "OSX" - it should be set to
887 // a particular version instead.
888 // However, it is valid for aBlockedOS to be one of those generic values,
889 // as we could be blocking all of the versions.
890 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
891 OperatingSystem aSystemOS
,
892 uint32_t aSystemOSBuild
) {
893 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
894 aSystemOS
!= OperatingSystem::OSX
);
896 // If the block entry OS is unknown, it doesn't match
897 if (aBlockedOS
== OperatingSystem::Unknown
) {
902 if (aBlockedOS
== OperatingSystem::Windows
) {
903 // We do want even "unknown" aSystemOS to fall under "all windows"
907 constexpr uint32_t kMinWin10BuildNumber
= 18362;
908 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
909 aSystemOS
== OperatingSystem::Windows10
) {
910 // For allowlist purposes, we sometimes want to restrict to only recent
911 // versions of Windows 10. This is a bit of a kludge but easier than adding
912 // complicated blocklist infrastructure for build ID comparisons like driver
914 return aSystemOSBuild
>= kMinWin10BuildNumber
;
917 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
918 if (aSystemOS
== OperatingSystem::Windows10
) {
919 return aSystemOSBuild
< kMinWin10BuildNumber
;
926 #if defined(XP_MACOSX)
927 if (aBlockedOS
== OperatingSystem::OSX
) {
928 // We do want even "unknown" aSystemOS to fall under "all OS X"
933 return aSystemOS
== aBlockedOS
;
936 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
937 switch (aBatteryStatus
) {
938 case BatteryStatus::All
:
940 case BatteryStatus::None
:
942 case BatteryStatus::Present
:
946 MOZ_ASSERT_UNREACHABLE("bad battery status");
950 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
951 int64_t aScreenPixels
) {
952 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
953 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
955 switch (aScreenStatus
) {
956 case ScreenSizeStatus::All
:
958 case ScreenSizeStatus::Small
:
959 return aScreenPixels
<= kMaxSmallPixels
;
960 case ScreenSizeStatus::SmallAndMedium
:
961 return aScreenPixels
<= kMaxMediumPixels
;
962 case ScreenSizeStatus::Medium
:
963 return aScreenPixels
> kMaxSmallPixels
&&
964 aScreenPixels
<= kMaxMediumPixels
;
965 case ScreenSizeStatus::MediumAndLarge
:
966 return aScreenPixels
> kMaxSmallPixels
;
967 case ScreenSizeStatus::Large
:
968 return aScreenPixels
> kMaxMediumPixels
;
971 MOZ_ASSERT_UNREACHABLE("bad screen status");
975 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
976 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
977 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
979 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
981 // Some properties are not available on all platforms.
982 nsAutoString desktopEnvironment
;
983 nsresult rv
= GetDesktopEnvironment(desktopEnvironment
);
984 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
988 nsAutoString windowProtocol
;
989 rv
= GetWindowProtocol(windowProtocol
);
990 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
994 bool hasBattery
= false;
995 rv
= GetHasBattery(&hasBattery
);
996 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
1000 uint32_t osBuild
= OperatingSystemBuild();
1002 // Get the adapters once then reuse below
1003 nsAutoString adapterVendorID
[2];
1004 nsAutoString adapterDeviceID
[2];
1005 nsAutoString adapterDriverVendor
[2];
1006 nsAutoString adapterDriverVersionString
[2];
1007 bool adapterInfoFailed
[2];
1009 adapterInfoFailed
[0] =
1010 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
1011 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
1012 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
1013 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
1014 adapterInfoFailed
[1] =
1015 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
1016 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
1017 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
1018 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
1019 // No point in going on if we don't have adapter info
1020 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
1024 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1025 uint64_t driverVersion
[2] = {0, 0};
1026 if (!adapterInfoFailed
[0]) {
1027 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
1029 if (!adapterInfoFailed
[1]) {
1030 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
1035 for (; i
< info
.Length(); i
++) {
1036 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
1037 // blocklisting. Only consider entries for our search mode.
1038 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
1042 // If we don't have the info for this GPU, no need to check further.
1043 // It is unclear that we would ever have a mixture of 1st and 2nd
1044 // GPU, but leaving the code in for that possibility for now.
1045 // (Actually, currently mGpu2 will never be true, so this can
1046 // be optimized out.)
1047 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
1048 if (adapterInfoFailed
[infoIndex
]) {
1052 // Do the operating system check first, no point in getting the driver
1053 // info if we won't need to use it.
1054 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
1058 if (info
[i
].mOperatingSystemVersion
&&
1059 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
1063 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
1067 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
1071 if (!DoesDesktopEnvironmentMatch(info
[i
].mDesktopEnvironment
,
1072 desktopEnvironment
)) {
1076 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
1080 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
1084 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
1085 adapterDriverVendor
[infoIndex
])) {
1089 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
1090 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
1091 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
1096 // Failed to search, allowlist should not match, blocklist should match
1097 // for safety reasons
1107 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
1110 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
1113 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
1116 if (!info
[i
].mManufacturer
.IsEmpty() &&
1117 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1121 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1122 switch (info
[i
].mComparisonOp
) {
1123 case DRIVER_LESS_THAN
:
1124 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1126 case DRIVER_BUILD_ID_LESS_THAN
:
1127 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1129 case DRIVER_LESS_THAN_OR_EQUAL
:
1130 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1132 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1133 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1135 case DRIVER_GREATER_THAN
:
1136 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1138 case DRIVER_GREATER_THAN_OR_EQUAL
:
1139 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1142 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1144 case DRIVER_NOT_EQUAL
:
1145 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1147 case DRIVER_BETWEEN_EXCLUSIVE
:
1148 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1149 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1151 case DRIVER_BETWEEN_INCLUSIVE
:
1152 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1153 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1155 case DRIVER_BETWEEN_INCLUSIVE_START
:
1156 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1157 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1159 case DRIVER_COMPARISON_IGNORED
:
1160 // We don't have a comparison op, so we match everything.
1164 NS_WARNING("Bogus op in GfxDriverInfo");
1168 // We don't care what driver version it was. We only check OS version and if
1169 // the device matches.
1173 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1174 if (info
[i
].mFeature
== GfxDriverInfo::allFeatures
||
1175 info
[i
].mFeature
== aFeature
) {
1176 status
= info
[i
].mFeatureStatus
;
1177 if (!info
[i
].mRuleId
.IsEmpty()) {
1178 aFailureId
= info
[i
].mRuleId
.get();
1180 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1188 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1189 // as either the primary or secondary adapter. D2D is also blocked when the
1190 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1191 // If the primary GPU already matched something in the blocklist then we
1192 // ignore this special rule. See bug 1008759.
1193 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1194 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1195 if (!adapterInfoFailed
[1]) {
1196 nsAString
& nvVendorID
=
1197 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1198 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1199 if (nvVendorID
.Equals(adapterVendorID
[1],
1200 nsCaseInsensitiveStringComparator
) &&
1201 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1202 nsCaseInsensitiveStringComparator
)) {
1203 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1204 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1209 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1210 // back to the Windows handler, so we must handle this here.
1211 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1212 if (info
[i
].mSuggestedVersion
) {
1213 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1214 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1215 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1216 aSuggestedVersion
.AppendPrintf(
1217 "%lld.%lld.%lld.%lld",
1218 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1219 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1220 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1221 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1229 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1230 MOZ_ASSERT(!sFeatureStatus
);
1231 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1234 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1235 const nsAString
& aBlocklistDesktop
, const nsAString
& aDesktopEnv
) {
1236 return aBlocklistDesktop
.Equals(aDesktopEnv
,
1237 nsCaseInsensitiveStringComparator
) ||
1238 aBlocklistDesktop
.Equals(
1239 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All
),
1240 nsCaseInsensitiveStringComparator
);
1243 bool GfxInfoBase::DoesWindowProtocolMatch(
1244 const nsAString
& aBlocklistWindowProtocol
,
1245 const nsAString
& aWindowProtocol
) {
1246 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1247 nsCaseInsensitiveStringComparator
) ||
1248 aBlocklistWindowProtocol
.Equals(
1249 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1250 nsCaseInsensitiveStringComparator
);
1253 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1254 const nsAString
& aAdapterVendor
) {
1255 return aBlocklistVendor
.Equals(aAdapterVendor
,
1256 nsCaseInsensitiveStringComparator
) ||
1257 aBlocklistVendor
.Equals(
1258 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1259 nsCaseInsensitiveStringComparator
);
1262 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1263 const nsAString
& aDriverVendor
) {
1264 return aBlocklistVendor
.Equals(aDriverVendor
,
1265 nsCaseInsensitiveStringComparator
) ||
1266 aBlocklistVendor
.Equals(
1267 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1268 nsCaseInsensitiveStringComparator
);
1271 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1272 return aFeature
== nsIGfxInfo::FEATURE_VIDEO_OVERLAY
||
1273 aFeature
== nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
;
1276 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1277 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1278 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1279 OperatingSystem
* aOS
/* = nullptr */) {
1280 if (aFeature
<= 0) {
1281 gfxWarning() << "Invalid feature <= 0";
1285 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1286 // Terminate now with the status determined by the derived type (OS-specific
1291 if (sShutdownOccurred
) {
1292 // This is futile; we've already commenced shutdown and our blocklists have
1293 // been deleted. We may want to look into resurrecting the blocklist instead
1294 // but for now, just don't even go there.
1298 // Ensure any additional initialization required is complete.
1301 // If an operating system was provided by the derived GetFeatureStatusImpl,
1302 // grab it here. Otherwise, the OS is unknown.
1303 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1305 nsAutoString adapterVendorID
;
1306 nsAutoString adapterDeviceID
;
1307 nsAutoString adapterDriverVersionString
;
1308 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1309 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1310 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1311 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1312 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1316 // We only check either the given blocklist, or the static list, as given.
1318 if (aDriverInfo
.Length()) {
1320 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1321 aFailureId
, os
, /* aForAllowing */ false);
1324 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1326 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1327 aFeature
, aFailureId
, os
,
1328 /* aForAllowing */ false);
1331 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1332 if (IsFeatureAllowlisted(aFeature
)) {
1333 // This feature is actually using the allowlist; that means after we pass
1334 // the blocklist to prevent us explicitly from getting the feature, we now
1335 // need to check the allowlist to ensure we are allowed to get it in the
1337 if (aDriverInfo
.Length()) {
1338 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1339 aFeature
, aFailureId
, os
,
1340 /* aForAllowing */ true);
1342 status
= FindBlocklistedDeviceInList(
1343 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1344 /* aForAllowing */ true);
1347 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1348 status
= nsIGfxInfo::FEATURE_DENIED
;
1351 // It's now done being processed. It's safe to set the status to
1353 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1362 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1363 nsAString
& aVersion
) {
1365 if (GetPrefValueForDriverVersion(version
)) {
1366 aVersion
= NS_ConvertASCIItoUTF16(version
);
1371 nsCString discardFailureId
;
1372 nsTArray
<GfxDriverInfo
> driverInfo
;
1373 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1377 void GfxInfoBase::EvaluateDownloadedBlocklist(
1378 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1379 // If the list is empty, then we don't actually want to call
1380 // GetFeatureStatusImpl since we will use the static list instead. In that
1381 // case, all we want to do is make sure the pref is removed.
1382 if (aDriverInfo
.IsEmpty()) {
1383 gfxCriticalNoteOnce
<< "Evaluate empty downloaded blocklist";
1387 OperatingSystem os
= GetOperatingSystem();
1389 // For every feature we know about, we evaluate whether this blocklist has a
1390 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1391 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1392 // anywhere permanent.
1393 for (int feature
= 1; feature
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++feature
) {
1394 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
1395 nsCString failureId
;
1396 nsAutoString suggestedVersion
;
1398 // Note that we are careful to call the base class method since we only want
1399 // to evaluate the downloadable blocklist for these prefs.
1400 MOZ_ALWAYS_TRUE(NS_SUCCEEDED(GfxInfoBase::GetFeatureStatusImpl(
1401 feature
, &status
, suggestedVersion
, aDriverInfo
, failureId
, &os
)));
1405 MOZ_FALLTHROUGH_ASSERT("Unhandled feature status!");
1406 case nsIGfxInfo::FEATURE_STATUS_UNKNOWN
:
1407 // This may be returned during shutdown or for invalid features.
1408 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
1409 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
1410 case nsIGfxInfo::FEATURE_DENIED
:
1411 // We cannot use the downloadable blocklist to control the allowlist.
1412 // If a feature is allowlisted, then we should also ignore DENIED
1413 // statuses from GetFeatureStatusImpl because we don't check the
1414 // static list when and this is an expected value. If we wish to
1415 // override the allowlist, it is as simple as creating a normal
1416 // blocklist rule with a BLOCKED* status code.
1417 case nsIGfxInfo::FEATURE_STATUS_OK
:
1418 RemovePrefForFeature(feature
);
1421 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1422 if (!suggestedVersion
.IsEmpty()) {
1423 SetPrefValueForDriverVersion(suggestedVersion
);
1425 RemovePrefForDriverVersion();
1429 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1430 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1431 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1432 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1433 case nsIGfxInfo::FEATURE_BLOCKED_PLATFORM_TEST
:
1434 SetPrefValueForFeature(feature
, status
, failureId
);
1440 NS_IMETHODIMP_(void)
1441 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1442 // gfxCriticalError has a mutex lock of its own, so we may not actually
1443 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1444 // will not return the copy of the logs unless it can get the same lock
1445 // that gfxCriticalError uses. Still, that is so much of an implementation
1446 // detail that it's nicer to just add an extra lock here and in
1448 MutexAutoLock
lock(mMutex
);
1450 // By default, gfxCriticalError asserts; make it not assert in this case.
1451 gfxCriticalError(CriticalLog::DefaultOptions(false))
1452 << "(LF) " << failure
.BeginReading();
1455 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1456 nsTArray
<nsCString
>& failures
) {
1457 MutexAutoLock
lock(mMutex
);
1459 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1460 if (!logForwarder
) {
1461 return NS_ERROR_UNEXPECTED
;
1464 // There are two string copies in this method, starting with this one. We are
1465 // assuming this is not a big deal, as the size of the array should be small
1466 // and the strings in it should be small as well (the error messages in the
1467 // code.) The second copy happens with the AppendElement() calls.
1468 // Technically, we don't need the mutex lock after the StringVectorCopy()
1470 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1471 LoggingRecord::const_iterator it
;
1472 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1473 failures
.AppendElement(
1474 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1475 indices
.AppendElement(Get
<0>(*it
));
1481 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1483 static void InitCollectors() {
1484 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1487 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1488 JS::MutableHandle
<JS::Value
> aResult
) {
1490 InfoObject
obj(aCx
);
1492 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1493 (*sCollectors
)[i
]->GetInfo(obj
);
1496 // Some example property definitions
1497 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1498 // obj.DefineProperty("renderer", mRendererIDsString);
1499 // obj.DefineProperty("five", 5);
1502 return NS_ERROR_FAILURE
;
1505 aResult
.setObject(*obj
.mObj
);
1509 nsAutoCString gBaseAppVersion
;
1511 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1512 static bool versionInitialized
= false;
1513 if (!versionInitialized
) {
1514 // If we fail to get the version, we will not try again.
1515 versionInitialized
= true;
1517 // Get the version from xpcom/system/nsIXULAppInfo.idl
1518 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1520 app
->GetVersion(gBaseAppVersion
);
1523 return gBaseAppVersion
;
1526 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1528 sCollectors
->AppendElement(collector
);
1531 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1533 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1534 if ((*sCollectors
)[i
] == collector
) {
1535 sCollectors
->RemoveElementAt(i
);
1539 if (sCollectors
->IsEmpty()) {
1541 sCollectors
= nullptr;
1545 static void AppendMonitor(JSContext
* aCx
, widget::Screen
& aScreen
,
1546 JS::Handle
<JSObject
*> aOutArray
, int32_t aIndex
) {
1547 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1549 auto screenSize
= aScreen
.GetRect().Size();
1551 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1552 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1554 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1555 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1557 // XXX Just preserving behavior since this is exposed to telemetry, but we
1558 // could consider including this everywhere.
1560 JS::Rooted
<JS::Value
> scale(
1561 aCx
, JS::NumberValue(aScreen
.GetContentsScaleFactor()));
1562 JS_SetProperty(aCx
, obj
, "scale", scale
);
1566 JS::Rooted
<JS::Value
> refreshRate(aCx
,
1567 JS::Int32Value(aScreen
.GetRefreshRate()));
1568 JS_SetProperty(aCx
, obj
, "refreshRate", refreshRate
);
1570 JS::Rooted
<JS::Value
> pseudoDisplay(
1571 aCx
, JS::BooleanValue(aScreen
.GetIsPseudoDisplay()));
1572 JS_SetProperty(aCx
, obj
, "pseudoDisplay", pseudoDisplay
);
1575 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1576 JS_SetElement(aCx
, aOutArray
, aIndex
, element
);
1579 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
,
1580 JS::Handle
<JSObject
*> aOutArray
) {
1582 auto& sm
= ScreenManager::GetSingleton();
1583 for (auto& screen
: sm
.CurrentScreenList()) {
1584 AppendMonitor(aCx
, *screen
, aOutArray
, index
++);
1588 // Ensure we return at least one monitor, this is needed for xpcshell.
1589 RefPtr
<Screen
> screen
= sm
.GetPrimaryScreen();
1590 AppendMonitor(aCx
, *screen
, aOutArray
, index
++);
1597 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
) {
1598 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1600 nsresult rv
= FindMonitors(aCx
, array
);
1601 if (NS_FAILED(rv
)) {
1605 aResult
.setObject(*array
);
1609 static inline bool SetJSPropertyString(JSContext
* aCx
,
1610 JS::Handle
<JSObject
*> aObj
,
1611 const char* aProp
, const char* aString
) {
1612 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1617 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1618 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1621 template <typename T
>
1622 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1625 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1628 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1631 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1632 JS::MutableHandle
<JS::Value
> aOut
) {
1633 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1635 return NS_ERROR_OUT_OF_MEMORY
;
1637 aOut
.setObject(*obj
);
1639 layers::LayersBackend backend
=
1640 gfxPlatform::Initialized()
1641 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1642 : layers::LayersBackend::LAYERS_NONE
;
1643 const char* backendName
= layers::GetLayersBackendName(backend
);
1644 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1646 // If graphics isn't initialized yet, just stop now.
1647 if (!gfxPlatform::Initialized()) {
1651 DescribeFeatures(aCx
, obj
);
1655 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1656 JS::MutableHandle
<JS::Value
> aOut
) {
1657 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1658 if (!containerObj
) {
1659 return NS_ERROR_OUT_OF_MEMORY
;
1661 aOut
.setObject(*containerObj
);
1663 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1664 if (!featureArray
) {
1665 return NS_ERROR_OUT_OF_MEMORY
;
1668 // Collect features.
1669 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1670 FeatureState
& aFeature
) -> void {
1671 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1675 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1676 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1677 !SetJSPropertyString(aCx
, obj
, "status",
1678 FeatureStatusToString(aFeature
.GetValue()))) {
1682 JS::Rooted
<JS::Value
> log(aCx
);
1683 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1686 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1690 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1695 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1696 if (!fallbackArray
) {
1697 return NS_ERROR_OUT_OF_MEMORY
;
1700 // Collect fallbacks.
1701 gfxConfig::ForEachFallback(
1702 [&](const char* aName
, const char* aMessage
) -> void {
1703 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1708 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1709 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1713 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1718 JS::Rooted
<JS::Value
> val(aCx
);
1720 val
= JS::ObjectValue(*featureArray
);
1721 JS_SetProperty(aCx
, containerObj
, "features", val
);
1723 val
= JS::ObjectValue(*fallbackArray
);
1724 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1729 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1730 const FeatureState
& aFeature
,
1731 JS::MutableHandle
<JS::Value
> aOut
) {
1732 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1736 aOut
.setObject(*log
);
1738 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1739 const char* aMessage
,
1740 const nsCString
& aFailureId
) -> void {
1741 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1746 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1747 !SetJSPropertyString(aCx
, obj
, "status",
1748 FeatureStatusToString(aStatus
)) ||
1749 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1753 if (!AppendJSElement(aCx
, log
, obj
)) {
1761 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1762 JS::Rooted
<JSObject
*> obj(aCx
);
1764 gfx::FeatureState
& hwCompositing
=
1765 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1766 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1768 gfx::FeatureState
& gpuProcess
=
1769 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1770 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1772 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1773 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1775 gfx::FeatureState
& wrCompositor
=
1776 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1777 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1779 gfx::FeatureState
& openglCompositing
=
1780 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1781 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1783 gfx::FeatureState
& omtp
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1784 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1787 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1788 JS::Handle
<JSObject
*> aContainer
,
1790 mozilla::gfx::FeatureState
& aFeatureState
,
1791 JS::MutableHandle
<JSObject
*> aOutObj
) {
1792 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1797 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1799 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1800 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1801 JS_SetProperty(aCx
, obj
, "status", val
);
1803 // Add the feature object to the container.
1805 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1806 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1813 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1814 JS::MutableHandle
<JS::Value
> aOut
) {
1815 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1817 return NS_ERROR_OUT_OF_MEMORY
;
1819 aOut
.setObject(*array
);
1821 DriverCrashGuard::ForEachActiveCrashGuard(
1822 [&](const char* aName
, const char* aPrefName
) -> void {
1823 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1827 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1830 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1833 if (!AppendJSElement(aCx
, array
, obj
)) {
1842 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1843 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1848 GfxInfoBase::GetCodecSupportInfo(nsACString
& aCodecSupportInfo
) {
1849 aCodecSupportInfo
.Assign(gfx::gfxVars::CodecSupportInfo());
1854 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1855 *aIsHeadless
= gfxPlatform::IsHeadless();
1860 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1861 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1865 case BackendType::DIRECT2D1_1
: {
1866 outStr
.AppendPrintf("Direct2D 1.1");
1869 case BackendType::SKIA
: {
1870 outStr
.AppendPrintf("Skia");
1873 case BackendType::CAIRO
: {
1874 outStr
.AppendPrintf("Cairo");
1878 return NS_ERROR_FAILURE
;
1881 aContentBackend
.Assign(outStr
);
1886 GfxInfoBase::GetAzureCanvasBackend(nsAString
& aBackend
) {
1887 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1888 gfxPlatform::GetPlatform()->GetAzureCanvasBackend()),
1894 GfxInfoBase::GetAzureContentBackend(nsAString
& aBackend
) {
1895 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1896 gfxPlatform::GetPlatform()->GetAzureContentBackend()),
1902 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1903 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1905 // Not supported in content processes.
1906 return NS_ERROR_FAILURE
;
1909 *aOutValue
= !!gpu
->GetGPUChild();
1913 NS_IMETHODIMP_(int32_t)
1914 GfxInfoBase::GetMaxRefreshRate(bool* aMixed
) {
1919 int32_t maxRefreshRate
= 0;
1920 for (auto& screen
: ScreenManager::GetSingleton().CurrentScreenList()) {
1921 int32_t refreshRate
= screen
->GetRefreshRate();
1922 if (aMixed
&& maxRefreshRate
> 0 && maxRefreshRate
!= refreshRate
) {
1925 maxRefreshRate
= std::max(maxRefreshRate
, refreshRate
);
1928 return maxRefreshRate
> 0 ? maxRefreshRate
: -1;
1932 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1933 gfxPlatform::GetPlatform();
1935 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1937 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1938 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1940 gpm
->EnsureGPUReady();
1942 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1950 NS_IMETHODIMP
GfxInfoBase::KillGPUProcessForTests() {
1951 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1953 // gfxPlatform has not been initialized.
1954 return NS_ERROR_NOT_INITIALIZED
;
1961 NS_IMETHODIMP
GfxInfoBase::CrashGPUProcessForTests() {
1962 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1964 // gfxPlatform has not been initialized.
1965 return NS_ERROR_NOT_INITIALIZED
;
1968 gpm
->CrashProcess();
1972 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1973 GfxInfoBase::AddCollector(this);
1976 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1977 GfxInfoBase::RemoveCollector(this);