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/BinarySearch.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/BuildConstants.h"
35 #include "mozilla/gfx/GPUProcessManager.h"
36 #include "mozilla/gfx/Logging.h"
37 #include "mozilla/gfx/gfxVars.h"
38 #include "mozilla/widget/ScreenManager.h"
39 #include "mozilla/widget/Screen.h"
43 #include "gfxPlatform.h"
44 #include "gfxConfig.h"
45 #include "DriverCrashGuard.h"
47 #ifdef MOZ_WIDGET_ANDROID
49 # include "AndroidBuild.h"
52 using namespace mozilla::widget
;
53 using namespace mozilla
;
54 using mozilla::MutexAutoLock
;
56 nsTArray
<GfxDriverInfo
>* GfxInfoBase::sDriverInfo
;
57 StaticAutoPtr
<nsTArray
<gfx::GfxInfoFeatureStatus
>> GfxInfoBase::sFeatureStatus
;
58 bool GfxInfoBase::sDriverInfoObserverInitialized
;
59 bool GfxInfoBase::sShutdownOccurred
;
61 // Call this when setting sFeatureStatus to a non-null pointer to
62 // ensure destruction even if the GfxInfo component is never instantiated.
63 static void InitFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>* aPtr
) {
64 static std::once_flag sOnce
;
65 std::call_once(sOnce
, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus
); });
66 GfxInfoBase::sFeatureStatus
= aPtr
;
69 // Observes for shutdown so that the child GfxDriverInfo list is freed.
70 class ShutdownObserver
: public nsIObserver
{
71 virtual ~ShutdownObserver() = default;
74 ShutdownObserver() = default;
78 NS_IMETHOD
Observe(nsISupports
* subject
, const char* aTopic
,
79 const char16_t
* aData
) override
{
80 MOZ_ASSERT(strcmp(aTopic
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
) == 0);
82 delete GfxInfoBase::sDriverInfo
;
83 GfxInfoBase::sDriverInfo
= nullptr;
85 for (auto& deviceFamily
: GfxDriverInfo::sDeviceFamilies
) {
87 deviceFamily
= nullptr;
90 for (auto& windowProtocol
: GfxDriverInfo::sWindowProtocol
) {
91 delete windowProtocol
;
92 windowProtocol
= nullptr;
95 for (auto& deviceVendor
: GfxDriverInfo::sDeviceVendors
) {
97 deviceVendor
= nullptr;
100 for (auto& driverVendor
: GfxDriverInfo::sDriverVendors
) {
102 driverVendor
= nullptr;
105 GfxInfoBase::sShutdownOccurred
= true;
111 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
113 static void InitGfxDriverInfoShutdownObserver() {
114 if (GfxInfoBase::sDriverInfoObserverInitialized
) return;
116 GfxInfoBase::sDriverInfoObserverInitialized
= true;
118 nsCOMPtr
<nsIObserverService
> observerService
= services::GetObserverService();
119 if (!observerService
) {
120 NS_WARNING("Could not get observer service!");
124 ShutdownObserver
* obs
= new ShutdownObserver();
125 observerService
->AddObserver(obs
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
, false);
128 using namespace mozilla::widget
;
129 using namespace mozilla::gfx
;
130 using namespace mozilla
;
132 NS_IMPL_ISUPPORTS(GfxInfoBase
, nsIGfxInfo
, nsIObserver
,
133 nsISupportsWeakReference
)
135 #define BLOCKLIST_PREF_BRANCH "gfx.blacklist."
136 #define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
138 static const char* GetPrefNameForFeature(int32_t aFeature
) {
139 const char* name
= nullptr;
141 case nsIGfxInfo::FEATURE_DIRECT2D
:
142 name
= BLOCKLIST_PREF_BRANCH
"direct2d";
144 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
:
145 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d9";
147 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
:
148 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10";
150 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
:
151 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10-1";
153 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
:
154 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d11";
156 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
157 name
= BLOCKLIST_PREF_BRANCH
"direct3d11angle";
159 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
:
160 name
= BLOCKLIST_PREF_BRANCH
"hardwarevideodecoding";
162 case nsIGfxInfo::FEATURE_OPENGL_LAYERS
:
163 name
= BLOCKLIST_PREF_BRANCH
"layers.opengl";
165 case nsIGfxInfo::FEATURE_WEBGL_OPENGL
:
166 name
= BLOCKLIST_PREF_BRANCH
"webgl.opengl";
168 case nsIGfxInfo::FEATURE_WEBGL_ANGLE
:
169 name
= BLOCKLIST_PREF_BRANCH
"webgl.angle";
171 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
:
172 name
= BLOCKLIST_PREF_BRANCH
"webgl.msaa";
174 case nsIGfxInfo::FEATURE_STAGEFRIGHT
:
175 name
= BLOCKLIST_PREF_BRANCH
"stagefright";
177 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
:
178 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.h264";
180 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
:
181 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.encode";
183 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
:
184 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.decode";
186 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
:
187 name
= BLOCKLIST_PREF_BRANCH
"canvas2d.acceleration";
189 case nsIGfxInfo::FEATURE_DX_INTEROP2
:
190 name
= BLOCKLIST_PREF_BRANCH
"dx.interop2";
192 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
193 name
= BLOCKLIST_PREF_BRANCH
"gpu.process";
195 case nsIGfxInfo::FEATURE_WEBGL2
:
196 name
= BLOCKLIST_PREF_BRANCH
"webgl2";
198 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
:
199 name
= BLOCKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
201 case nsIGfxInfo::FEATURE_WEBRENDER
:
202 name
= BLOCKLIST_PREF_BRANCH
"webrender";
204 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
205 name
= BLOCKLIST_PREF_BRANCH
"webrender.compositor";
207 case nsIGfxInfo::FEATURE_DX_NV12
:
208 name
= BLOCKLIST_PREF_BRANCH
"dx.nv12";
210 case nsIGfxInfo::FEATURE_DX_P010
:
211 name
= BLOCKLIST_PREF_BRANCH
"dx.p010";
213 case nsIGfxInfo::FEATURE_DX_P016
:
214 name
= BLOCKLIST_PREF_BRANCH
"dx.p016";
216 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
217 name
= BLOCKLIST_PREF_BRANCH
"vp8.hw-decode";
219 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
220 name
= BLOCKLIST_PREF_BRANCH
"vp9.hw-decode";
222 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
223 name
= BLOCKLIST_PREF_BRANCH
"gl.swizzle";
225 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
:
226 name
= BLOCKLIST_PREF_BRANCH
"webrender.scissored_cache_clears";
228 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
229 name
= BLOCKLIST_PREF_BRANCH
"webgl.allow-oop";
231 case nsIGfxInfo::FEATURE_THREADSAFE_GL
:
232 name
= BLOCKLIST_PREF_BRANCH
"gl.threadsafe";
234 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS
:
235 name
= BLOCKLIST_PREF_BRANCH
"webrender.optimized-shaders";
237 case nsIGfxInfo::FEATURE_X11_EGL
:
238 name
= BLOCKLIST_PREF_BRANCH
"x11.egl";
240 case nsIGfxInfo::FEATURE_DMABUF
:
241 name
= BLOCKLIST_PREF_BRANCH
"dmabuf";
243 case nsIGfxInfo::FEATURE_WEBGPU
:
244 name
= BLOCKLIST_PREF_BRANCH
"webgpu";
246 case nsIGfxInfo::FEATURE_VIDEO_OVERLAY
:
247 name
= BLOCKLIST_PREF_BRANCH
"video-overlay";
249 case nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
:
250 name
= BLOCKLIST_PREF_BRANCH
"hw-video-zero-copy";
252 case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE
:
253 name
= BLOCKLIST_PREF_BRANCH
"webrender.program-binary-disk";
255 case nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
:
256 name
= BLOCKLIST_PREF_BRANCH
"webrender.partial-present";
258 case nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT
:
259 name
= BLOCKLIST_PREF_BRANCH
"dmabuf.surface-export";
261 case nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
:
262 name
= BLOCKLIST_PREF_BRANCH
"reuse-decoder-device";
264 case nsIGfxInfo::FEATURE_BACKDROP_FILTER
:
265 name
= BLOCKLIST_PREF_BRANCH
"backdrop.filter";
267 case nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D
:
268 name
= BLOCKLIST_PREF_BRANCH
"accelerated-canvas2d";
270 case nsIGfxInfo::FEATURE_H264_HW_DECODE
:
271 name
= BLOCKLIST_PREF_BRANCH
"h264.hw-decode";
273 case nsIGfxInfo::FEATURE_AV1_HW_DECODE
:
274 name
= BLOCKLIST_PREF_BRANCH
"av1.hw-decode";
276 case nsIGfxInfo::FEATURE_VIDEO_SOFTWARE_OVERLAY
:
277 name
= BLOCKLIST_PREF_BRANCH
"video-software-overlay";
279 case nsIGfxInfo::FEATURE_WEBGL_USE_HARDWARE
:
280 name
= BLOCKLIST_PREF_BRANCH
"webgl-use-hardware";
283 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
290 // Returns the value of the pref for the relevant feature in aValue.
291 // If the pref doesn't exist, aValue is not touched, and returns false.
292 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
293 nsACString
& aFailureId
) {
294 const char* prefname
= GetPrefNameForFeature(aFeature
);
295 if (!prefname
) return false;
297 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
298 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
302 if (aValue
== nsIGfxInfo::FEATURE_DENIED
) {
303 // We should never see the DENIED status with the downloadable blocklist.
307 nsCString
failureprefname(prefname
);
308 failureprefname
+= ".failureid";
309 nsAutoCString failureValue
;
310 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
311 if (NS_SUCCEEDED(rv
)) {
312 aFailureId
= failureValue
.get();
314 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
320 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
321 const nsACString
& aFailureId
) {
322 const char* prefname
= GetPrefNameForFeature(aFeature
);
323 if (!prefname
) return;
324 if (XRE_IsParentProcess()) {
325 GfxInfoBase::sFeatureStatus
= nullptr;
328 Preferences::SetInt(prefname
, aValue
);
329 if (!aFailureId
.IsEmpty()) {
330 nsAutoCString
failureprefname(prefname
);
331 failureprefname
+= ".failureid";
332 Preferences::SetCString(failureprefname
.get(), aFailureId
);
336 static void RemovePrefForFeature(int32_t aFeature
) {
337 const char* prefname
= GetPrefNameForFeature(aFeature
);
338 if (!prefname
) return;
340 if (XRE_IsParentProcess()) {
341 GfxInfoBase::sFeatureStatus
= nullptr;
343 Preferences::ClearUser(prefname
);
346 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
348 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
351 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
352 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
355 static void RemovePrefForDriverVersion() {
356 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
359 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
360 if (os
.EqualsLiteral("WINNT 6.1")) {
361 return OperatingSystem::Windows7
;
363 if (os
.EqualsLiteral("WINNT 6.2")) {
364 return OperatingSystem::Windows8
;
366 if (os
.EqualsLiteral("WINNT 6.3")) {
367 return OperatingSystem::Windows8_1
;
369 if (os
.EqualsLiteral("WINNT 10.0")) {
370 return OperatingSystem::Windows10
;
372 if (os
.EqualsLiteral("Linux")) {
373 return OperatingSystem::Linux
;
375 if (os
.EqualsLiteral("Darwin 9")) {
376 return OperatingSystem::OSX10_5
;
378 if (os
.EqualsLiteral("Darwin 10")) {
379 return OperatingSystem::OSX10_6
;
381 if (os
.EqualsLiteral("Darwin 11")) {
382 return OperatingSystem::OSX10_7
;
384 if (os
.EqualsLiteral("Darwin 12")) {
385 return OperatingSystem::OSX10_8
;
387 if (os
.EqualsLiteral("Darwin 13")) {
388 return OperatingSystem::OSX10_9
;
390 if (os
.EqualsLiteral("Darwin 14")) {
391 return OperatingSystem::OSX10_10
;
393 if (os
.EqualsLiteral("Darwin 15")) {
394 return OperatingSystem::OSX10_11
;
396 if (os
.EqualsLiteral("Darwin 16")) {
397 return OperatingSystem::OSX10_12
;
399 if (os
.EqualsLiteral("Darwin 17")) {
400 return OperatingSystem::OSX10_13
;
402 if (os
.EqualsLiteral("Darwin 18")) {
403 return OperatingSystem::OSX10_14
;
405 if (os
.EqualsLiteral("Darwin 19")) {
406 return OperatingSystem::OSX10_15
;
408 if (os
.EqualsLiteral("Darwin 20")) {
409 return OperatingSystem::OSX11_0
;
411 if (os
.EqualsLiteral("Android")) {
412 return OperatingSystem::Android
;
413 // For historical reasons, "All" in blocklist means "All Windows"
415 if (os
.EqualsLiteral("All")) {
416 return OperatingSystem::Windows
;
418 if (os
.EqualsLiteral("Darwin")) {
419 return OperatingSystem::OSX
;
422 return OperatingSystem::Unknown
;
425 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
426 nsTArray
<nsCString
>& devices
) {
427 if (devices
.Length() == 0) return nullptr;
429 // For each device, get its device ID, and return a freshly-allocated
430 // GfxDeviceFamily with the contents of that array.
431 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
433 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
434 // We make sure we don't add any "empty" device entries to the array, so
435 // we don't need to check if devices[i] is empty.
436 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
442 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
443 MOZ_ASSERT(!aFeature
.IsEmpty());
444 if (aFeature
.EqualsLiteral("DIRECT2D")) {
445 return nsIGfxInfo::FEATURE_DIRECT2D
;
447 if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS")) {
448 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
450 if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS")) {
451 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
453 if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
454 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
456 if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS")) {
457 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
459 if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE")) {
460 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
462 if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
463 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
465 if (aFeature
.EqualsLiteral("OPENGL_LAYERS")) {
466 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
468 if (aFeature
.EqualsLiteral("WEBGL_OPENGL")) {
469 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
471 if (aFeature
.EqualsLiteral("WEBGL_ANGLE")) {
472 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
474 if (aFeature
.EqualsLiteral("WEBGL_MSAA")) {
475 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
477 if (aFeature
.EqualsLiteral("STAGEFRIGHT")) {
478 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
480 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
481 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
483 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
484 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
486 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
487 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
489 if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION")) {
490 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
492 if (aFeature
.EqualsLiteral("DX_INTEROP2")) {
493 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
495 if (aFeature
.EqualsLiteral("GPU_PROCESS")) {
496 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
498 if (aFeature
.EqualsLiteral("WEBGL2")) {
499 return nsIGfxInfo::FEATURE_WEBGL2
;
501 if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX")) {
502 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
504 if (aFeature
.EqualsLiteral("WEBRENDER")) {
505 return nsIGfxInfo::FEATURE_WEBRENDER
;
507 if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
508 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
510 if (aFeature
.EqualsLiteral("DX_NV12")) {
511 return nsIGfxInfo::FEATURE_DX_NV12
;
513 if (aFeature
.EqualsLiteral("VP8_HW_DECODE")) {
514 return nsIGfxInfo::FEATURE_VP8_HW_DECODE
;
516 if (aFeature
.EqualsLiteral("VP9_HW_DECODE")) {
517 return nsIGfxInfo::FEATURE_VP9_HW_DECODE
;
519 if (aFeature
.EqualsLiteral("GL_SWIZZLE")) {
520 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
522 if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
523 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
525 if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
526 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
528 if (aFeature
.EqualsLiteral("THREADSAFE_GL")) {
529 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
531 if (aFeature
.EqualsLiteral("X11_EGL")) {
532 return nsIGfxInfo::FEATURE_X11_EGL
;
534 if (aFeature
.EqualsLiteral("DMABUF")) {
535 return nsIGfxInfo::FEATURE_DMABUF
;
537 if (aFeature
.EqualsLiteral("WEBGPU")) {
538 return nsIGfxInfo::FEATURE_WEBGPU
;
540 if (aFeature
.EqualsLiteral("VIDEO_OVERLAY")) {
541 return nsIGfxInfo::FEATURE_VIDEO_OVERLAY
;
543 if (aFeature
.EqualsLiteral("HW_DECODED_VIDEO_ZERO_COPY")) {
544 return nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
;
546 if (aFeature
.EqualsLiteral("REUSE_DECODER_DEVICE")) {
547 return nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
;
549 if (aFeature
.EqualsLiteral("WEBRENDER_PARTIAL_PRESENT")) {
550 return nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
;
552 if (aFeature
.EqualsLiteral("BACKDROP_FILTER")) {
553 return nsIGfxInfo::FEATURE_BACKDROP_FILTER
;
555 if (aFeature
.EqualsLiteral("ACCELERATED_CANVAS2D")) {
556 return nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D
;
558 if (aFeature
.EqualsLiteral("ALL")) {
559 return GfxDriverInfo::allFeatures
;
561 if (aFeature
.EqualsLiteral("OPTIONAL")) {
562 return GfxDriverInfo::optionalFeatures
;
565 // If we don't recognize the feature, it may be new, and something
566 // this version doesn't understand. So, nothing to do. This is
567 // different from feature not being specified at all, in which case
568 // this method should not get called and we should continue with the
569 // "optional features" blocklisting.
573 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
574 const nsAString
& aStatus
) {
575 if (aStatus
.EqualsLiteral("STATUS_OK")) {
576 return nsIGfxInfo::FEATURE_STATUS_OK
;
578 if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
579 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
581 if (aStatus
.EqualsLiteral("BLOCKED_DEVICE")) {
582 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
584 if (aStatus
.EqualsLiteral("DISCOURAGED")) {
585 return nsIGfxInfo::FEATURE_DISCOURAGED
;
587 if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION")) {
588 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
590 if (aStatus
.EqualsLiteral("DENIED")) {
591 return nsIGfxInfo::FEATURE_DENIED
;
593 if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED")) {
594 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
596 if (aStatus
.EqualsLiteral("ALLOW_ALWAYS")) {
597 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
600 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
601 // expecting the "mismatch" status showing up here.
603 return nsIGfxInfo::FEATURE_STATUS_OK
;
606 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
607 const nsAString
& op
) {
608 if (op
.EqualsLiteral("LESS_THAN")) {
609 return DRIVER_LESS_THAN
;
611 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN")) {
612 return DRIVER_BUILD_ID_LESS_THAN
;
614 if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
615 return DRIVER_LESS_THAN_OR_EQUAL
;
617 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
618 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
620 if (op
.EqualsLiteral("GREATER_THAN")) {
621 return DRIVER_GREATER_THAN
;
623 if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
624 return DRIVER_GREATER_THAN_OR_EQUAL
;
626 if (op
.EqualsLiteral("EQUAL")) {
629 if (op
.EqualsLiteral("NOT_EQUAL")) {
630 return DRIVER_NOT_EQUAL
;
632 if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
633 return DRIVER_BETWEEN_EXCLUSIVE
;
635 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE")) {
636 return DRIVER_BETWEEN_INCLUSIVE
;
638 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
639 return DRIVER_BETWEEN_INCLUSIVE_START
;
642 return DRIVER_COMPARISON_IGNORED
;
646 Deserialize Blocklist entries from string.
648 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
650 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
651 GfxDriverInfo
& aDriverInfo
) {
652 // If we get an application version to be zero, something is not working
653 // and we are not going to bother checking the blocklist versions.
654 // See TestGfxWidgets.cpp for how version comparison works.
655 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
656 static mozilla::Version
zeroV("0");
657 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
659 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
660 << "Invalid application version "
661 << GfxInfoBase::GetApplicationVersion().get();
664 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
666 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
667 nsTArray
<nsCString
> splitted
;
668 ParseString(keyValue
, ':', splitted
);
669 if (splitted
.Length() != 2) {
670 // If we don't recognize the input data, we do not want to proceed.
671 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
672 << "Unrecognized data " << nsCString(keyValue
).get();
675 const nsCString
& key
= splitted
[0];
676 const nsCString
& value
= splitted
[1];
677 NS_ConvertUTF8toUTF16
dataValue(value
);
679 if (value
.Length() == 0) {
680 // Safety check for empty values.
681 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
682 << "Empty value for " << key
.get();
686 if (key
.EqualsLiteral("blockID")) {
687 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
688 aDriverInfo
.mRuleId
= blockIdStr
.get();
689 } else if (key
.EqualsLiteral("os")) {
690 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
691 } else if (key
.EqualsLiteral("osversion")) {
692 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
693 } else if (key
.EqualsLiteral("windowProtocol")) {
694 aDriverInfo
.mWindowProtocol
= dataValue
;
695 } else if (key
.EqualsLiteral("vendor")) {
696 aDriverInfo
.mAdapterVendor
= dataValue
;
697 } else if (key
.EqualsLiteral("driverVendor")) {
698 aDriverInfo
.mDriverVendor
= dataValue
;
699 } else if (key
.EqualsLiteral("feature")) {
700 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
701 if (aDriverInfo
.mFeature
== 0) {
702 // If we don't recognize the feature, we do not want to proceed.
703 gfxWarning() << "Unrecognized feature " << value
.get();
706 } else if (key
.EqualsLiteral("featureStatus")) {
707 aDriverInfo
.mFeatureStatus
=
708 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
709 } else if (key
.EqualsLiteral("driverVersion")) {
711 if (ParseDriverVersion(dataValue
, &version
))
712 aDriverInfo
.mDriverVersion
= version
;
713 } else if (key
.EqualsLiteral("driverVersionMax")) {
715 if (ParseDriverVersion(dataValue
, &version
))
716 aDriverInfo
.mDriverVersionMax
= version
;
717 } else if (key
.EqualsLiteral("driverVersionComparator")) {
718 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
719 } else if (key
.EqualsLiteral("model")) {
720 aDriverInfo
.mModel
= dataValue
;
721 } else if (key
.EqualsLiteral("product")) {
722 aDriverInfo
.mProduct
= dataValue
;
723 } else if (key
.EqualsLiteral("manufacturer")) {
724 aDriverInfo
.mManufacturer
= dataValue
;
725 } else if (key
.EqualsLiteral("hardware")) {
726 aDriverInfo
.mHardware
= dataValue
;
727 } else if (key
.EqualsLiteral("versionRange")) {
728 nsTArray
<nsCString
> versionRange
;
729 ParseString(value
, ',', versionRange
);
730 if (versionRange
.Length() != 2) {
731 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
732 << "Unrecognized versionRange " << value
.get();
735 const nsCString
& minValue
= versionRange
[0];
736 const nsCString
& maxValue
= versionRange
[1];
738 mozilla::Version
minV(minValue
.get());
739 mozilla::Version
maxV(maxValue
.get());
741 if (minV
> zeroV
&& !(appV
>= minV
)) {
742 // The version of the application is less than the minimal version
743 // this blocklist entry applies to, so we can just ignore it by
744 // returning false and letting the caller deal with it.
747 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
748 // The version of the application is more than the maximal version
749 // this blocklist entry applies to, so we can just ignore it by
750 // returning false and letting the caller deal with it.
753 } else if (key
.EqualsLiteral("devices")) {
754 nsTArray
<nsCString
> devices
;
755 ParseString(value
, ',', devices
);
756 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
758 // Get GfxDriverInfo to adopt the devices array we created.
759 aDriverInfo
.mDeleteDevices
= true;
760 aDriverInfo
.mDevices
= deviceIds
;
763 // We explicitly ignore unknown elements.
770 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
771 const char16_t
* aData
) {
772 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
773 nsTArray
<GfxDriverInfo
> driverInfo
;
774 NS_ConvertUTF16toUTF8
utf8Data(aData
);
776 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
778 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
779 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
780 // Probably some non-standard semantics of the copy/move operations?
781 *driverInfo
.AppendElement() = di
;
782 // Prevent di falling out of scope from destroying the devices.
783 di
.mDeleteDevices
= false;
785 driverInfo
.AppendElement();
789 EvaluateDownloadedBlocklist(driverInfo
);
795 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
797 GfxInfoBase::~GfxInfoBase() = default;
799 nsresult
GfxInfoBase::Init() {
800 InitGfxDriverInfoShutdownObserver();
802 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
804 os
->AddObserver(this, "blocklist-data-gfxItems", true);
810 void GfxInfoBase::GetData() {
811 if (mScreenPixels
!= INT64_MAX
) {
812 // Already initialized.
816 ScreenManager::GetSingleton().GetTotalScreenPixels(&mScreenPixels
);
820 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
822 // Ignore the gfx.blocklist.all pref on release and beta.
823 #if defined(RELEASE_OR_BETA)
824 int32_t blocklistAll
= 0;
826 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
828 if (blocklistAll
> 0) {
829 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
830 << "Forcing blocklisting all features";
831 *aStatus
= FEATURE_BLOCKED_DEVICE
;
832 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
836 if (blocklistAll
< 0) {
837 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
838 << "Ignoring any feature blocklisting.";
839 *aStatus
= FEATURE_STATUS_OK
;
843 // This is how we evaluate the downloadable blocklist. If there is no pref,
844 // then we will fallback to checking the static blocklist.
845 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
849 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
850 // Use the cached data received from the parent process.
851 MOZ_ASSERT(sFeatureStatus
);
852 bool success
= false;
853 for (const auto& fs
: *sFeatureStatus
) {
854 if (fs
.feature() == aFeature
) {
855 aFailureId
= fs
.failureId();
856 *aStatus
= fs
.status();
861 return success
? NS_OK
: NS_ERROR_FAILURE
;
865 nsTArray
<GfxDriverInfo
> driverInfo
;
867 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
871 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
872 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
873 if (!sFeatureStatus
) {
874 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
875 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
877 nsAutoCString failureId
;
878 GetFeatureStatus(i
, failureId
, &status
);
879 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
880 gfxFeatureStatus
.feature() = i
;
881 gfxFeatureStatus
.status() = status
;
882 gfxFeatureStatus
.failureId() = failureId
;
883 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
887 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
888 for (const auto& status
: *sFeatureStatus
) {
889 gfx::GfxInfoFeatureStatus copy
= status
;
890 features
.AppendElement(copy
);
895 inline bool MatchingAllowStatus(int32_t aStatus
) {
897 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
898 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
905 // Matching OS go somewhat beyond the simple equality check because of the
906 // "All Windows" and "All OS X" variations.
908 // aBlockedOS is describing the system(s) we are trying to block.
909 // aSystemOS is describing the system we are running on.
911 // aSystemOS should not be "Windows" or "OSX" - it should be set to
912 // a particular version instead.
913 // However, it is valid for aBlockedOS to be one of those generic values,
914 // as we could be blocking all of the versions.
915 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
916 OperatingSystem aSystemOS
,
917 uint32_t aSystemOSBuild
) {
918 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
919 aSystemOS
!= OperatingSystem::OSX
);
921 // If the block entry OS is unknown, it doesn't match
922 if (aBlockedOS
== OperatingSystem::Unknown
) {
927 if (aBlockedOS
== OperatingSystem::Windows
) {
928 // We do want even "unknown" aSystemOS to fall under "all windows"
932 constexpr uint32_t kMinWin10BuildNumber
= 18362;
933 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
934 aSystemOS
== OperatingSystem::Windows10
) {
935 // For allowlist purposes, we sometimes want to restrict to only recent
936 // versions of Windows 10. This is a bit of a kludge but easier than adding
937 // complicated blocklist infrastructure for build ID comparisons like driver
939 return aSystemOSBuild
>= kMinWin10BuildNumber
;
942 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
943 if (aSystemOS
== OperatingSystem::Windows10
) {
944 return aSystemOSBuild
< kMinWin10BuildNumber
;
951 #if defined(XP_MACOSX)
952 if (aBlockedOS
== OperatingSystem::OSX
) {
953 // We do want even "unknown" aSystemOS to fall under "all OS X"
958 return aSystemOS
== aBlockedOS
;
961 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
962 switch (aBatteryStatus
) {
963 case BatteryStatus::All
:
965 case BatteryStatus::None
:
967 case BatteryStatus::Present
:
971 MOZ_ASSERT_UNREACHABLE("bad battery status");
975 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
976 int64_t aScreenPixels
) {
977 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
978 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
980 switch (aScreenStatus
) {
981 case ScreenSizeStatus::All
:
983 case ScreenSizeStatus::Small
:
984 return aScreenPixels
<= kMaxSmallPixels
;
985 case ScreenSizeStatus::SmallAndMedium
:
986 return aScreenPixels
<= kMaxMediumPixels
;
987 case ScreenSizeStatus::Medium
:
988 return aScreenPixels
> kMaxSmallPixels
&&
989 aScreenPixels
<= kMaxMediumPixels
;
990 case ScreenSizeStatus::MediumAndLarge
:
991 return aScreenPixels
> kMaxSmallPixels
;
992 case ScreenSizeStatus::Large
:
993 return aScreenPixels
> kMaxMediumPixels
;
996 MOZ_ASSERT_UNREACHABLE("bad screen status");
1000 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
1001 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
1002 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
1003 bool aForAllowing
) {
1004 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
1006 // Some properties are not available on all platforms.
1007 nsAutoString windowProtocol
;
1008 nsresult rv
= GetWindowProtocol(windowProtocol
);
1009 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
1013 bool hasBattery
= false;
1014 rv
= GetHasBattery(&hasBattery
);
1015 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
1019 uint32_t osBuild
= OperatingSystemBuild();
1021 // Get the adapters once then reuse below
1022 nsAutoString adapterVendorID
[2];
1023 nsAutoString adapterDeviceID
[2];
1024 nsAutoString adapterDriverVendor
[2];
1025 nsAutoString adapterDriverVersionString
[2];
1026 bool adapterInfoFailed
[2];
1028 adapterInfoFailed
[0] =
1029 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
1030 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
1031 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
1032 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
1033 adapterInfoFailed
[1] =
1034 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
1035 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
1036 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
1037 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
1038 // No point in going on if we don't have adapter info
1039 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
1043 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1044 uint64_t driverVersion
[2] = {0, 0};
1045 if (!adapterInfoFailed
[0]) {
1046 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
1048 if (!adapterInfoFailed
[1]) {
1049 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
1054 for (; i
< info
.Length(); i
++) {
1055 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
1056 // blocklisting. Only consider entries for our search mode.
1057 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
1061 // If we don't have the info for this GPU, no need to check further.
1062 // It is unclear that we would ever have a mixture of 1st and 2nd
1063 // GPU, but leaving the code in for that possibility for now.
1064 // (Actually, currently mGpu2 will never be true, so this can
1065 // be optimized out.)
1066 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
1067 if (adapterInfoFailed
[infoIndex
]) {
1071 // Do the operating system check first, no point in getting the driver
1072 // info if we won't need to use it.
1073 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
1077 if (info
[i
].mOperatingSystemVersion
&&
1078 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
1082 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
1086 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
1090 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
1094 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
1098 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
1099 adapterDriverVendor
[infoIndex
])) {
1103 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
1104 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
1105 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
1110 // Failed to search, allowlist should not match, blocklist should match
1111 // for safety reasons
1121 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
1124 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
1127 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
1130 if (!info
[i
].mManufacturer
.IsEmpty() &&
1131 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1135 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1136 switch (info
[i
].mComparisonOp
) {
1137 case DRIVER_LESS_THAN
:
1138 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1140 case DRIVER_BUILD_ID_LESS_THAN
:
1141 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1143 case DRIVER_LESS_THAN_OR_EQUAL
:
1144 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1146 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1147 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1149 case DRIVER_GREATER_THAN
:
1150 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1152 case DRIVER_GREATER_THAN_OR_EQUAL
:
1153 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1156 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1158 case DRIVER_NOT_EQUAL
:
1159 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1161 case DRIVER_BETWEEN_EXCLUSIVE
:
1162 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1163 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1165 case DRIVER_BETWEEN_INCLUSIVE
:
1166 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1167 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1169 case DRIVER_BETWEEN_INCLUSIVE_START
:
1170 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1171 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1173 case DRIVER_COMPARISON_IGNORED
:
1174 // We don't have a comparison op, so we match everything.
1178 NS_WARNING("Bogus op in GfxDriverInfo");
1182 // We don't care what driver version it was. We only check OS version and if
1183 // the device matches.
1187 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1188 if (info
[i
].mFeature
== GfxDriverInfo::allFeatures
||
1189 info
[i
].mFeature
== aFeature
||
1190 (info
[i
].mFeature
== GfxDriverInfo::optionalFeatures
&&
1191 OnlyAllowFeatureOnKnownConfig(aFeature
))) {
1192 status
= info
[i
].mFeatureStatus
;
1193 if (!info
[i
].mRuleId
.IsEmpty()) {
1194 aFailureId
= info
[i
].mRuleId
.get();
1196 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1204 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1205 // as either the primary or secondary adapter. D2D is also blocked when the
1206 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1207 // If the primary GPU already matched something in the blocklist then we
1208 // ignore this special rule. See bug 1008759.
1209 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1210 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1211 if (!adapterInfoFailed
[1]) {
1212 nsAString
& nvVendorID
=
1213 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1214 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1215 if (nvVendorID
.Equals(adapterVendorID
[1],
1216 nsCaseInsensitiveStringComparator
) &&
1217 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1218 nsCaseInsensitiveStringComparator
)) {
1219 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1220 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1225 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1226 // back to the Windows handler, so we must handle this here.
1227 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1228 if (info
[i
].mSuggestedVersion
) {
1229 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1230 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1231 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1232 aSuggestedVersion
.AppendPrintf(
1233 "%lld.%lld.%lld.%lld",
1234 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1235 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1236 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1237 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1245 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1246 MOZ_ASSERT(!sFeatureStatus
);
1247 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1250 bool GfxInfoBase::DoesWindowProtocolMatch(
1251 const nsAString
& aBlocklistWindowProtocol
,
1252 const nsAString
& aWindowProtocol
) {
1253 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1254 nsCaseInsensitiveStringComparator
) ||
1255 aBlocklistWindowProtocol
.Equals(
1256 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1257 nsCaseInsensitiveStringComparator
);
1260 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1261 const nsAString
& aAdapterVendor
) {
1262 return aBlocklistVendor
.Equals(aAdapterVendor
,
1263 nsCaseInsensitiveStringComparator
) ||
1264 aBlocklistVendor
.Equals(
1265 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1266 nsCaseInsensitiveStringComparator
);
1269 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1270 const nsAString
& aDriverVendor
) {
1271 return aBlocklistVendor
.Equals(aDriverVendor
,
1272 nsCaseInsensitiveStringComparator
) ||
1273 aBlocklistVendor
.Equals(
1274 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1275 nsCaseInsensitiveStringComparator
);
1278 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1279 return aFeature
== nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
;
1282 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1283 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1284 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1285 OperatingSystem
* aOS
/* = nullptr */) {
1286 if (aFeature
<= 0) {
1287 gfxWarning() << "Invalid feature <= 0";
1291 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1292 // Terminate now with the status determined by the derived type (OS-specific
1297 if (sShutdownOccurred
) {
1298 // This is futile; we've already commenced shutdown and our blocklists have
1299 // been deleted. We may want to look into resurrecting the blocklist instead
1300 // but for now, just don't even go there.
1304 // Ensure any additional initialization required is complete.
1307 // If an operating system was provided by the derived GetFeatureStatusImpl,
1308 // grab it here. Otherwise, the OS is unknown.
1309 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1311 nsAutoString adapterVendorID
;
1312 nsAutoString adapterDeviceID
;
1313 nsAutoString adapterDriverVersionString
;
1314 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1315 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1316 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1317 if (OnlyAllowFeatureOnKnownConfig(aFeature
)) {
1318 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1319 *aStatus
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1321 *aStatus
= nsIGfxInfo::FEATURE_STATUS_OK
;
1326 // We only check either the given blocklist, or the static list, as given.
1328 if (aDriverInfo
.Length()) {
1330 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1331 aFailureId
, os
, /* aForAllowing */ false);
1334 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1336 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1337 aFeature
, aFailureId
, os
,
1338 /* aForAllowing */ false);
1341 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1342 if (IsFeatureAllowlisted(aFeature
)) {
1343 // This feature is actually using the allowlist; that means after we pass
1344 // the blocklist to prevent us explicitly from getting the feature, we now
1345 // need to check the allowlist to ensure we are allowed to get it in the
1347 if (aDriverInfo
.Length()) {
1348 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1349 aFeature
, aFailureId
, os
,
1350 /* aForAllowing */ true);
1352 status
= FindBlocklistedDeviceInList(
1353 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1354 /* aForAllowing */ true);
1357 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1358 status
= nsIGfxInfo::FEATURE_DENIED
;
1361 // It's now done being processed. It's safe to set the status to
1363 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1372 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1373 nsAString
& aVersion
) {
1375 if (GetPrefValueForDriverVersion(version
)) {
1376 aVersion
= NS_ConvertASCIItoUTF16(version
);
1381 nsCString discardFailureId
;
1382 nsTArray
<GfxDriverInfo
> driverInfo
;
1383 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1387 void GfxInfoBase::EvaluateDownloadedBlocklist(
1388 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1389 // If the list is empty, then we don't actually want to call
1390 // GetFeatureStatusImpl since we will use the static list instead. In that
1391 // case, all we want to do is make sure the pref is removed.
1392 if (aDriverInfo
.IsEmpty()) {
1393 gfxCriticalNoteOnce
<< "Evaluate empty downloaded blocklist";
1397 OperatingSystem os
= GetOperatingSystem();
1399 // For every feature we know about, we evaluate whether this blocklist has a
1400 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1401 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1402 // anywhere permanent.
1403 for (int feature
= 1; feature
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++feature
) {
1404 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
1405 nsCString failureId
;
1406 nsAutoString suggestedVersion
;
1408 // Note that we are careful to call the base class method since we only want
1409 // to evaluate the downloadable blocklist for these prefs.
1410 MOZ_ALWAYS_TRUE(NS_SUCCEEDED(GfxInfoBase::GetFeatureStatusImpl(
1411 feature
, &status
, suggestedVersion
, aDriverInfo
, failureId
, &os
)));
1415 MOZ_FALLTHROUGH_ASSERT("Unhandled feature status!");
1416 case nsIGfxInfo::FEATURE_STATUS_UNKNOWN
:
1417 // This may be returned during shutdown or for invalid features.
1418 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
1419 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
1420 case nsIGfxInfo::FEATURE_DENIED
:
1421 // We cannot use the downloadable blocklist to control the allowlist.
1422 // If a feature is allowlisted, then we should also ignore DENIED
1423 // statuses from GetFeatureStatusImpl because we don't check the
1424 // static list when and this is an expected value. If we wish to
1425 // override the allowlist, it is as simple as creating a normal
1426 // blocklist rule with a BLOCKED* status code.
1427 case nsIGfxInfo::FEATURE_STATUS_OK
:
1428 RemovePrefForFeature(feature
);
1431 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1432 if (!suggestedVersion
.IsEmpty()) {
1433 SetPrefValueForDriverVersion(suggestedVersion
);
1435 RemovePrefForDriverVersion();
1439 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1440 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1441 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1442 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1443 case nsIGfxInfo::FEATURE_BLOCKED_PLATFORM_TEST
:
1444 SetPrefValueForFeature(feature
, status
, failureId
);
1450 NS_IMETHODIMP_(void)
1451 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1452 // gfxCriticalError has a mutex lock of its own, so we may not actually
1453 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1454 // will not return the copy of the logs unless it can get the same lock
1455 // that gfxCriticalError uses. Still, that is so much of an implementation
1456 // detail that it's nicer to just add an extra lock here and in
1458 MutexAutoLock
lock(mMutex
);
1460 // By default, gfxCriticalError asserts; make it not assert in this case.
1461 gfxCriticalError(CriticalLog::DefaultOptions(false))
1462 << "(LF) " << failure
.BeginReading();
1465 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1466 nsTArray
<nsCString
>& failures
) {
1467 MutexAutoLock
lock(mMutex
);
1469 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1470 if (!logForwarder
) {
1471 return NS_ERROR_UNEXPECTED
;
1474 // There are two string copies in this method, starting with this one. We are
1475 // assuming this is not a big deal, as the size of the array should be small
1476 // and the strings in it should be small as well (the error messages in the
1477 // code.) The second copy happens with the AppendElement() calls.
1478 // Technically, we don't need the mutex lock after the StringVectorCopy()
1480 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1481 LoggingRecord::const_iterator it
;
1482 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1483 failures
.AppendElement(nsDependentCSubstring(std::get
<1>(*it
).c_str(),
1484 std::get
<1>(*it
).size()));
1485 indices
.AppendElement(std::get
<0>(*it
));
1491 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1493 static void InitCollectors() {
1494 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1497 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1498 JS::MutableHandle
<JS::Value
> aResult
) {
1500 InfoObject
obj(aCx
);
1502 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1503 (*sCollectors
)[i
]->GetInfo(obj
);
1506 // Some example property definitions
1507 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1508 // obj.DefineProperty("renderer", mRendererIDsString);
1509 // obj.DefineProperty("five", 5);
1512 return NS_ERROR_FAILURE
;
1515 aResult
.setObject(*obj
.mObj
);
1519 nsAutoCString gBaseAppVersion
;
1521 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1522 static bool versionInitialized
= false;
1523 if (!versionInitialized
) {
1524 // If we fail to get the version, we will not try again.
1525 versionInitialized
= true;
1527 // Get the version from xpcom/system/nsIXULAppInfo.idl
1528 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1530 app
->GetVersion(gBaseAppVersion
);
1533 return gBaseAppVersion
;
1536 /* static */ bool GfxInfoBase::OnlyAllowFeatureOnKnownConfig(int32_t aFeature
) {
1538 // The GPU process doesn't need hardware acceleration and can run on
1539 // devices that we normally block from not being on our whitelist.
1540 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
1542 // We can mostly assume that ANGLE will work
1543 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
1544 // Remote WebGL is needed for Win32k Lockdown, so it should be enabled
1545 // regardless of HW support or not
1546 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
1547 // Backdrop filter should generally work, especially if we fall back to
1548 // Software WebRender because of an unknown vendor.
1549 case nsIGfxInfo::FEATURE_BACKDROP_FILTER
:
1556 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1558 sCollectors
->AppendElement(collector
);
1561 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1563 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1564 if ((*sCollectors
)[i
] == collector
) {
1565 sCollectors
->RemoveElementAt(i
);
1569 if (sCollectors
->IsEmpty()) {
1571 sCollectors
= nullptr;
1575 static void AppendMonitor(JSContext
* aCx
, widget::Screen
& aScreen
,
1576 JS::Handle
<JSObject
*> aOutArray
, int32_t aIndex
) {
1577 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1579 auto screenSize
= aScreen
.GetRect().Size();
1581 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1582 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1584 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1585 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1587 // XXX Just preserving behavior since this is exposed to telemetry, but we
1588 // could consider including this everywhere.
1590 JS::Rooted
<JS::Value
> scale(
1591 aCx
, JS::NumberValue(aScreen
.GetContentsScaleFactor()));
1592 JS_SetProperty(aCx
, obj
, "scale", scale
);
1596 JS::Rooted
<JS::Value
> refreshRate(aCx
,
1597 JS::Int32Value(aScreen
.GetRefreshRate()));
1598 JS_SetProperty(aCx
, obj
, "refreshRate", refreshRate
);
1600 JS::Rooted
<JS::Value
> pseudoDisplay(
1601 aCx
, JS::BooleanValue(aScreen
.GetIsPseudoDisplay()));
1602 JS_SetProperty(aCx
, obj
, "pseudoDisplay", pseudoDisplay
);
1605 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1606 JS_SetElement(aCx
, aOutArray
, aIndex
, element
);
1609 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
,
1610 JS::Handle
<JSObject
*> aOutArray
) {
1612 auto& sm
= ScreenManager::GetSingleton();
1613 for (auto& screen
: sm
.CurrentScreenList()) {
1614 AppendMonitor(aCx
, *screen
, aOutArray
, index
++);
1618 // Ensure we return at least one monitor, this is needed for xpcshell.
1619 RefPtr
<Screen
> screen
= sm
.GetPrimaryScreen();
1620 AppendMonitor(aCx
, *screen
, aOutArray
, index
++);
1627 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
) {
1628 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1630 nsresult rv
= FindMonitors(aCx
, array
);
1631 if (NS_FAILED(rv
)) {
1635 aResult
.setObject(*array
);
1639 static inline bool SetJSPropertyString(JSContext
* aCx
,
1640 JS::Handle
<JSObject
*> aObj
,
1641 const char* aProp
, const char* aString
) {
1642 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1647 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1648 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1651 template <typename T
>
1652 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1655 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1658 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1661 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1662 JS::MutableHandle
<JS::Value
> aOut
) {
1663 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1665 return NS_ERROR_OUT_OF_MEMORY
;
1667 aOut
.setObject(*obj
);
1669 layers::LayersBackend backend
=
1670 gfxPlatform::Initialized()
1671 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1672 : layers::LayersBackend::LAYERS_NONE
;
1673 const char* backendName
= layers::GetLayersBackendName(backend
);
1674 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1676 // If graphics isn't initialized yet, just stop now.
1677 if (!gfxPlatform::Initialized()) {
1681 DescribeFeatures(aCx
, obj
);
1685 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1686 JS::MutableHandle
<JS::Value
> aOut
) {
1687 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1688 if (!containerObj
) {
1689 return NS_ERROR_OUT_OF_MEMORY
;
1691 aOut
.setObject(*containerObj
);
1693 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1694 if (!featureArray
) {
1695 return NS_ERROR_OUT_OF_MEMORY
;
1698 // Collect features.
1699 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1700 FeatureState
& aFeature
) -> void {
1701 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1705 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1706 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1707 !SetJSPropertyString(aCx
, obj
, "status",
1708 FeatureStatusToString(aFeature
.GetValue()))) {
1712 JS::Rooted
<JS::Value
> log(aCx
);
1713 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1716 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1720 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1725 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1726 if (!fallbackArray
) {
1727 return NS_ERROR_OUT_OF_MEMORY
;
1730 // Collect fallbacks.
1731 gfxConfig::ForEachFallback(
1732 [&](const char* aName
, const char* aMessage
) -> void {
1733 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1738 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1739 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1743 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1748 JS::Rooted
<JS::Value
> val(aCx
);
1750 val
= JS::ObjectValue(*featureArray
);
1751 JS_SetProperty(aCx
, containerObj
, "features", val
);
1753 val
= JS::ObjectValue(*fallbackArray
);
1754 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1759 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1760 const FeatureState
& aFeature
,
1761 JS::MutableHandle
<JS::Value
> aOut
) {
1762 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1766 aOut
.setObject(*log
);
1768 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1769 const char* aMessage
,
1770 const nsCString
& aFailureId
) -> void {
1771 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1776 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1777 !SetJSPropertyString(aCx
, obj
, "status",
1778 FeatureStatusToString(aStatus
)) ||
1779 (!aFailureId
.IsEmpty() &&
1780 !SetJSPropertyString(aCx
, obj
, "failureId", aFailureId
.get())) ||
1781 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1785 if (!AppendJSElement(aCx
, log
, obj
)) {
1793 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1794 JS::Rooted
<JSObject
*> obj(aCx
);
1796 gfx::FeatureState
& hwCompositing
=
1797 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1798 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1800 gfx::FeatureState
& gpuProcess
=
1801 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1802 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1804 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1805 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1807 gfx::FeatureState
& wrCompositor
=
1808 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1809 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1811 gfx::FeatureState
& openglCompositing
=
1812 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1813 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1815 gfx::FeatureState
& omtp
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1816 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1819 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1820 JS::Handle
<JSObject
*> aContainer
,
1822 mozilla::gfx::FeatureState
& aFeatureState
,
1823 JS::MutableHandle
<JSObject
*> aOutObj
) {
1824 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1829 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1831 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1832 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1833 JS_SetProperty(aCx
, obj
, "status", val
);
1835 // Add the feature object to the container.
1837 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1838 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1845 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1846 JS::MutableHandle
<JS::Value
> aOut
) {
1847 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1849 return NS_ERROR_OUT_OF_MEMORY
;
1851 aOut
.setObject(*array
);
1853 DriverCrashGuard::ForEachActiveCrashGuard(
1854 [&](const char* aName
, const char* aPrefName
) -> void {
1855 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1859 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1862 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1865 if (!AppendJSElement(aCx
, array
, obj
)) {
1874 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1875 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1880 GfxInfoBase::GetCodecSupportInfo(nsACString
& aCodecSupportInfo
) {
1881 aCodecSupportInfo
.Assign(gfx::gfxVars::CodecSupportInfo());
1886 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1887 *aIsHeadless
= gfxPlatform::IsHeadless();
1891 #if defined(MOZ_WIDGET_ANDROID)
1893 const char* chromebookProductList
[] = {
1894 "asuka", "asurada", "atlas", "auron", "banjo", "banon",
1895 "bob", "brask", "brya", "buddy", "butterfly", "candy",
1896 "caroline", "cave", "celes", "chell", "cherry", "clapper",
1897 "coral", "corsola", "cyan", "daisy", "dedede", "drallion",
1898 "edgar", "elm", "enguarde", "eve", "expresso", "falco",
1899 "fizz", "gandof", "glimmer", "gnawty", "grunt", "guado",
1900 "guybrush", "hana", "hatch", "heli", "jacuzzi", "kalista",
1901 "kefka", "kevin", "kip", "kukui", "lars", "leon",
1902 "link", "lulu", "lumpy", "mccloud", "monroe", "nami",
1903 "nautilus", "ninja", "nissa", "nocturne", "nyan", "octopus",
1904 "orco", "panther", "parrot", "peach", "peppy", "puff",
1905 "pyro", "quawks", "rammus", "reef", "reks", "relm",
1906 "rikku", "samus", "sand", "sarien", "scarlet", "sentry",
1907 "setzer", "skyrim", "snappy", "soraka", "squawks", "staryu",
1908 "stout", "strongbad", "stumpy", "sumo", "swanky", "terra",
1909 "tidus", "tricky", "trogdor", "ultima", "veyron", "volteer",
1910 "winky", "wizpig", "wolf", "x86", "zako", "zork"};
1912 bool ProductIsChromebook(nsCString product
) {
1914 return BinarySearchIf(
1915 chromebookProductList
, 0, ArrayLength(chromebookProductList
),
1916 [&](const char* const aValue
) -> int {
1917 return strcmp(product
.get(), aValue
);
1923 using Device
= nsIGfxInfo::FontVisibilityDeviceDetermination
;
1924 static StaticAutoPtr
<std::pair
<Device
, nsString
>> ret
;
1926 std::pair
<Device
, nsString
>* GfxInfoBase::GetFontVisibilityDeterminationPair() {
1928 ret
= new std::pair
<Device
, nsString
>();
1929 ret
->first
= Device::Unassigned
;
1930 ret
->second
= u
""_ns
;
1931 ClearOnShutdown(&ret
);
1934 if (ret
->first
!= Device::Unassigned
) {
1938 #if defined(MOZ_WIDGET_ANDROID)
1939 auto androidReleaseVersion
= strtol(
1940 java::sdk::Build::VERSION::RELEASE()->ToCString().get(), nullptr, 10);
1942 auto androidManufacturer
= java::sdk::Build::MANUFACTURER()->ToCString();
1943 nsContentUtils::ASCIIToLower(androidManufacturer
);
1945 auto androidBrand
= java::sdk::Build::BRAND()->ToCString();
1946 nsContentUtils::ASCIIToLower(androidBrand
);
1948 auto androidModel
= java::sdk::Build::MODEL()->ToCString();
1949 nsContentUtils::ASCIIToLower(androidModel
);
1951 auto androidProduct
= java::sdk::Build::PRODUCT()->ToCString();
1952 nsContentUtils::ASCIIToLower(androidProduct
);
1954 auto androidProductIsChromebook
= ProductIsChromebook(androidProduct
);
1956 if (androidReleaseVersion
< 4 || androidReleaseVersion
> 20) {
1957 // Something is screwy, oh well.
1958 ret
->second
.AppendASCII("Unknown Release Version - ");
1959 ret
->first
= Device::Android_Unknown_Release_Version
;
1960 } else if (androidReleaseVersion
<= 8) {
1961 ret
->second
.AppendASCII("Android <9 - ");
1962 ret
->first
= Device::Android_sub_9
;
1963 } else if (androidReleaseVersion
<= 11) {
1964 ret
->second
.AppendASCII("Android 9-11 - ");
1965 ret
->first
= Device::Android_9_11
;
1966 } else if (androidReleaseVersion
> 11) {
1967 ret
->second
.AppendASCII("Android 12+ - ");
1968 ret
->first
= Device::Android_12_plus
;
1970 MOZ_CRASH_UNSAFE_PRINTF(
1971 "Somehow wound up in GetFontVisibilityDeterminationPair with a release "
1973 androidReleaseVersion
);
1976 if (androidManufacturer
== "google" && androidModel
== androidProduct
&&
1977 androidProductIsChromebook
) {
1978 // Chromebook font set coming later
1979 ret
->second
.AppendASCII("Chromebook - ");
1980 ret
->first
= Device::Android_Chromebook
;
1982 if (androidBrand
== "amazon") {
1983 // Amazon Fire font set coming later
1984 ret
->second
.AppendASCII("Amazon - ");
1985 ret
->first
= Device::Android_Amazon
;
1987 if (androidBrand
== "peloton") {
1988 // We don't know how to categorize fonts on this system
1989 ret
->second
.AppendASCII("Peloton - ");
1990 ret
->first
= Device::Android_Unknown_Peloton
;
1992 if (androidProduct
== "vbox86p") {
1993 ret
->second
.AppendASCII("vbox - ");
1994 // We can't categorize fonts when running in an emulator on a Desktop
1995 ret
->first
= Device::Android_Unknown_vbox
;
1997 if (androidModel
.Find("mitv"_ns
) != kNotFound
&& androidBrand
== "xiaomi") {
1998 // We don't know how to categorize fonts on this system
1999 ret
->second
.AppendASCII("mitv - ");
2000 ret
->first
= Device::Android_Unknown_mitv
;
2003 ret
->second
.AppendPrintf(
2004 "release_version_str=%s, release_version=%li",
2005 java::sdk::Build::VERSION::RELEASE()->ToCString().get(),
2006 androidReleaseVersion
);
2007 ret
->second
.AppendPrintf(
2008 ", manufacturer=%s, brand=%s, model=%s, product=%s, chromebook=%s",
2009 androidManufacturer
.get(), androidBrand
.get(), androidModel
.get(),
2010 androidProduct
.get(), androidProductIsChromebook
? "yes" : "no");
2012 #elif defined(XP_LINUX)
2013 ret
->first
= Device::Linux_Unknown
;
2015 long versionMajor
= 0;
2016 FILE* fp
= fopen("/etc/os-release", "r");
2019 while (fgets(buf
, sizeof(buf
), fp
)) {
2020 if (strncmp(buf
, "VERSION_ID=\"", 12) == 0) {
2021 ret
->second
.AppendPrintf("VERSION_ID=%.11s", buf
+ 11);
2022 versionMajor
= strtol(buf
+ 12, nullptr, 10);
2023 if (ret
->first
!= Device::Linux_Unknown
) {
2028 if (strncmp(buf
, "ID=", 3) == 0) {
2029 ret
->second
.AppendPrintf("ID=%.6s", buf
+ 3);
2030 if (strncmp(buf
+ 3, "ubuntu", 6) == 0) {
2031 ret
->first
= Device::Linux_Ubuntu_any
;
2032 } else if (strncmp(buf
+ 3, "fedora", 6) == 0) {
2033 ret
->first
= Device::Linux_Fedora_any
;
2043 if (ret
->first
== Device::Linux_Ubuntu_any
) {
2044 if (versionMajor
== 20) {
2045 ret
->first
= Device::Linux_Ubuntu_20
;
2046 ret
->second
.Insert(u
"Ubuntu 20 - ", 0);
2047 } else if (versionMajor
== 22) {
2048 ret
->first
= Device::Linux_Ubuntu_22
;
2049 ret
->second
.Insert(u
"Ubuntu 22 - ", 0);
2051 ret
->second
.Insert(u
"Ubuntu Unknown - ", 0);
2053 } else if (ret
->first
== Device::Linux_Fedora_any
) {
2054 if (versionMajor
== 38) {
2055 ret
->first
= Device::Linux_Fedora_38
;
2056 ret
->second
.Insert(u
"Fedora 38 - ", 0);
2057 } else if (versionMajor
== 39) {
2058 ret
->first
= Device::Linux_Fedora_39
;
2059 ret
->second
.Insert(u
"Fedora 39 - ", 0);
2061 ret
->second
.Insert(u
"Fedora Unknown - ", 0);
2064 ret
->second
.Insert(u
"Linux Unknown - ", 0);
2067 #elif defined(XP_MACOSX)
2068 ret
->first
= Device::MacOS_Platform
;
2069 ret
->second
.AppendASCII("macOS Platform");
2070 #elif defined(XP_WIN)
2071 ret
->first
= Device::Windows_Platform
;
2072 ret
->second
.AppendASCII("Windows Platform");
2074 ret
->first
= Device::Unknown_Platform
;
2075 ret
->second
.AppendASCII("Unknown Platform");
2082 GfxInfoBase::GetFontVisibilityDetermination(
2083 Device
* aFontVisibilityDetermination
) {
2084 auto ret
= GetFontVisibilityDeterminationPair();
2086 *aFontVisibilityDetermination
= ret
->first
;
2091 GfxInfoBase::GetFontVisibilityDeterminationStr(
2092 nsAString
& aFontVisibilityDeterminationStr
) {
2093 auto ret
= GetFontVisibilityDeterminationPair();
2094 aFontVisibilityDeterminationStr
.Assign(ret
->second
);
2099 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
2100 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
2104 case BackendType::DIRECT2D1_1
: {
2105 outStr
.AppendPrintf("Direct2D 1.1");
2108 case BackendType::SKIA
: {
2109 outStr
.AppendPrintf("Skia");
2112 case BackendType::CAIRO
: {
2113 outStr
.AppendPrintf("Cairo");
2117 return NS_ERROR_FAILURE
;
2120 aContentBackend
.Assign(outStr
);
2125 GfxInfoBase::GetAzureCanvasBackend(nsAString
& aBackend
) {
2126 CopyASCIItoUTF16(mozilla::MakeStringSpan(
2127 gfxPlatform::GetPlatform()->GetAzureCanvasBackend()),
2133 GfxInfoBase::GetAzureContentBackend(nsAString
& aBackend
) {
2134 CopyASCIItoUTF16(mozilla::MakeStringSpan(
2135 gfxPlatform::GetPlatform()->GetAzureContentBackend()),
2141 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
2142 GPUProcessManager
* gpu
= GPUProcessManager::Get();
2144 // Not supported in content processes.
2145 return NS_ERROR_FAILURE
;
2148 *aOutValue
= !!gpu
->GetGPUChild();
2152 NS_IMETHODIMP_(int32_t)
2153 GfxInfoBase::GetMaxRefreshRate(bool* aMixed
) {
2158 int32_t maxRefreshRate
= 0;
2159 for (auto& screen
: ScreenManager::GetSingleton().CurrentScreenList()) {
2160 int32_t refreshRate
= screen
->GetRefreshRate();
2161 if (aMixed
&& maxRefreshRate
> 0 && maxRefreshRate
!= refreshRate
) {
2164 maxRefreshRate
= std::max(maxRefreshRate
, refreshRate
);
2167 return maxRefreshRate
> 0 ? maxRefreshRate
: -1;
2171 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
2172 gfxPlatform::GetPlatform();
2174 GPUProcessManager
* gpm
= GPUProcessManager::Get();
2176 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
2177 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
2179 DebugOnly
<nsresult
> rv
= gpm
->EnsureGPUReady();
2180 MOZ_ASSERT(rv
!= NS_ERROR_ILLEGAL_DURING_SHUTDOWN
);
2182 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
2190 NS_IMETHODIMP
GfxInfoBase::KillGPUProcessForTests() {
2191 GPUProcessManager
* gpm
= GPUProcessManager::Get();
2193 // gfxPlatform has not been initialized.
2194 return NS_ERROR_NOT_INITIALIZED
;
2201 NS_IMETHODIMP
GfxInfoBase::CrashGPUProcessForTests() {
2202 GPUProcessManager
* gpm
= GPUProcessManager::Get();
2204 // gfxPlatform has not been initialized.
2205 return NS_ERROR_NOT_INITIALIZED
;
2208 gpm
->CrashProcess();
2212 GfxInfoCollectorBase::GfxInfoCollectorBase() {
2213 GfxInfoBase::AddCollector(this);
2216 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
2217 GfxInfoBase::RemoveCollector(this);