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/BuildConstants.h"
34 #include "mozilla/gfx/GPUProcessManager.h"
35 #include "mozilla/gfx/Logging.h"
36 #include "mozilla/gfx/gfxVars.h"
37 #include "mozilla/widget/ScreenManager.h"
38 #include "mozilla/widget/Screen.h"
42 #include "gfxPlatform.h"
43 #include "gfxConfig.h"
44 #include "DriverCrashGuard.h"
46 using namespace mozilla::widget
;
47 using namespace mozilla
;
48 using mozilla::MutexAutoLock
;
50 nsTArray
<GfxDriverInfo
>* GfxInfoBase::sDriverInfo
;
51 StaticAutoPtr
<nsTArray
<gfx::GfxInfoFeatureStatus
>> GfxInfoBase::sFeatureStatus
;
52 bool GfxInfoBase::sDriverInfoObserverInitialized
;
53 bool GfxInfoBase::sShutdownOccurred
;
55 // Call this when setting sFeatureStatus to a non-null pointer to
56 // ensure destruction even if the GfxInfo component is never instantiated.
57 static void InitFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>* aPtr
) {
58 static std::once_flag sOnce
;
59 std::call_once(sOnce
, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus
); });
60 GfxInfoBase::sFeatureStatus
= aPtr
;
63 // Observes for shutdown so that the child GfxDriverInfo list is freed.
64 class ShutdownObserver
: public nsIObserver
{
65 virtual ~ShutdownObserver() = default;
68 ShutdownObserver() = default;
72 NS_IMETHOD
Observe(nsISupports
* subject
, const char* aTopic
,
73 const char16_t
* aData
) override
{
74 MOZ_ASSERT(strcmp(aTopic
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
) == 0);
76 delete GfxInfoBase::sDriverInfo
;
77 GfxInfoBase::sDriverInfo
= nullptr;
79 for (auto& deviceFamily
: GfxDriverInfo::sDeviceFamilies
) {
81 deviceFamily
= nullptr;
84 for (auto& windowProtocol
: GfxDriverInfo::sWindowProtocol
) {
85 delete windowProtocol
;
86 windowProtocol
= nullptr;
89 for (auto& deviceVendor
: GfxDriverInfo::sDeviceVendors
) {
91 deviceVendor
= nullptr;
94 for (auto& driverVendor
: GfxDriverInfo::sDriverVendors
) {
96 driverVendor
= nullptr;
99 GfxInfoBase::sShutdownOccurred
= true;
105 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
107 static void InitGfxDriverInfoShutdownObserver() {
108 if (GfxInfoBase::sDriverInfoObserverInitialized
) return;
110 GfxInfoBase::sDriverInfoObserverInitialized
= true;
112 nsCOMPtr
<nsIObserverService
> observerService
= services::GetObserverService();
113 if (!observerService
) {
114 NS_WARNING("Could not get observer service!");
118 ShutdownObserver
* obs
= new ShutdownObserver();
119 observerService
->AddObserver(obs
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
, false);
122 using namespace mozilla::widget
;
123 using namespace mozilla::gfx
;
124 using namespace mozilla
;
126 NS_IMPL_ISUPPORTS(GfxInfoBase
, nsIGfxInfo
, nsIObserver
,
127 nsISupportsWeakReference
)
129 #define BLOCKLIST_PREF_BRANCH "gfx.blacklist."
130 #define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
132 static const char* GetPrefNameForFeature(int32_t aFeature
) {
133 const char* name
= nullptr;
135 case nsIGfxInfo::FEATURE_DIRECT2D
:
136 name
= BLOCKLIST_PREF_BRANCH
"direct2d";
138 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
:
139 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d9";
141 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
:
142 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10";
144 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
:
145 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10-1";
147 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
:
148 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d11";
150 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
151 name
= BLOCKLIST_PREF_BRANCH
"direct3d11angle";
153 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
:
154 name
= BLOCKLIST_PREF_BRANCH
"hardwarevideodecoding";
156 case nsIGfxInfo::FEATURE_OPENGL_LAYERS
:
157 name
= BLOCKLIST_PREF_BRANCH
"layers.opengl";
159 case nsIGfxInfo::FEATURE_WEBGL_OPENGL
:
160 name
= BLOCKLIST_PREF_BRANCH
"webgl.opengl";
162 case nsIGfxInfo::FEATURE_WEBGL_ANGLE
:
163 name
= BLOCKLIST_PREF_BRANCH
"webgl.angle";
165 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
:
166 name
= BLOCKLIST_PREF_BRANCH
"webgl.msaa";
168 case nsIGfxInfo::FEATURE_STAGEFRIGHT
:
169 name
= BLOCKLIST_PREF_BRANCH
"stagefright";
171 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
:
172 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.h264";
174 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
:
175 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.encode";
177 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
:
178 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.decode";
180 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
:
181 name
= BLOCKLIST_PREF_BRANCH
"canvas2d.acceleration";
183 case nsIGfxInfo::FEATURE_DX_INTEROP2
:
184 name
= BLOCKLIST_PREF_BRANCH
"dx.interop2";
186 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
187 name
= BLOCKLIST_PREF_BRANCH
"gpu.process";
189 case nsIGfxInfo::FEATURE_WEBGL2
:
190 name
= BLOCKLIST_PREF_BRANCH
"webgl2";
192 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
:
193 name
= BLOCKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
195 case nsIGfxInfo::FEATURE_WEBRENDER
:
196 name
= BLOCKLIST_PREF_BRANCH
"webrender";
198 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
199 name
= BLOCKLIST_PREF_BRANCH
"webrender.compositor";
201 case nsIGfxInfo::FEATURE_DX_NV12
:
202 name
= BLOCKLIST_PREF_BRANCH
"dx.nv12";
204 case nsIGfxInfo::FEATURE_DX_P010
:
205 name
= BLOCKLIST_PREF_BRANCH
"dx.p010";
207 case nsIGfxInfo::FEATURE_DX_P016
:
208 name
= BLOCKLIST_PREF_BRANCH
"dx.p016";
210 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
211 name
= BLOCKLIST_PREF_BRANCH
"vp8.hw-decode";
213 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
214 name
= BLOCKLIST_PREF_BRANCH
"vp9.hw-decode";
216 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
217 name
= BLOCKLIST_PREF_BRANCH
"gl.swizzle";
219 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
:
220 name
= BLOCKLIST_PREF_BRANCH
"webrender.scissored_cache_clears";
222 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
223 name
= BLOCKLIST_PREF_BRANCH
"webgl.allow-oop";
225 case nsIGfxInfo::FEATURE_THREADSAFE_GL
:
226 name
= BLOCKLIST_PREF_BRANCH
"gl.threadsafe";
228 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS
:
229 name
= BLOCKLIST_PREF_BRANCH
"webrender.optimized-shaders";
231 case nsIGfxInfo::FEATURE_X11_EGL
:
232 name
= BLOCKLIST_PREF_BRANCH
"x11.egl";
234 case nsIGfxInfo::FEATURE_DMABUF
:
235 name
= BLOCKLIST_PREF_BRANCH
"dmabuf";
237 case nsIGfxInfo::FEATURE_WEBGPU
:
238 name
= BLOCKLIST_PREF_BRANCH
"webgpu";
240 case nsIGfxInfo::FEATURE_VIDEO_OVERLAY
:
241 name
= BLOCKLIST_PREF_BRANCH
"video-overlay";
243 case nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
:
244 name
= BLOCKLIST_PREF_BRANCH
"hw-video-zero-copy";
246 case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE
:
247 name
= BLOCKLIST_PREF_BRANCH
"webrender.program-binary-disk";
249 case nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
:
250 name
= BLOCKLIST_PREF_BRANCH
"webrender.partial-present";
252 case nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT
:
253 name
= BLOCKLIST_PREF_BRANCH
"dmabuf.surface-export";
255 case nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
:
256 name
= BLOCKLIST_PREF_BRANCH
"reuse-decoder-device";
258 case nsIGfxInfo::FEATURE_BACKDROP_FILTER
:
259 name
= BLOCKLIST_PREF_BRANCH
"backdrop.filter";
261 case nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D
:
262 name
= BLOCKLIST_PREF_BRANCH
"accelerated-canvas2d";
264 case nsIGfxInfo::FEATURE_H264_HW_DECODE
:
265 name
= BLOCKLIST_PREF_BRANCH
"h264.hw-decode";
267 case nsIGfxInfo::FEATURE_AV1_HW_DECODE
:
268 name
= BLOCKLIST_PREF_BRANCH
"av1.hw-decode";
270 case nsIGfxInfo::FEATURE_VIDEO_SOFTWARE_OVERLAY
:
271 name
= BLOCKLIST_PREF_BRANCH
"video-software-overlay";
273 case nsIGfxInfo::FEATURE_WEBGL_USE_HARDWARE
:
274 name
= BLOCKLIST_PREF_BRANCH
"webgl-use-hardware";
277 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
284 // Returns the value of the pref for the relevant feature in aValue.
285 // If the pref doesn't exist, aValue is not touched, and returns false.
286 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
287 nsACString
& aFailureId
) {
288 const char* prefname
= GetPrefNameForFeature(aFeature
);
289 if (!prefname
) return false;
291 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
292 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
296 if (aValue
== nsIGfxInfo::FEATURE_DENIED
) {
297 // We should never see the DENIED status with the downloadable blocklist.
301 nsCString
failureprefname(prefname
);
302 failureprefname
+= ".failureid";
303 nsAutoCString failureValue
;
304 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
305 if (NS_SUCCEEDED(rv
)) {
306 aFailureId
= failureValue
.get();
308 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
314 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
315 const nsACString
& aFailureId
) {
316 const char* prefname
= GetPrefNameForFeature(aFeature
);
317 if (!prefname
) return;
318 if (XRE_IsParentProcess()) {
319 GfxInfoBase::sFeatureStatus
= nullptr;
322 Preferences::SetInt(prefname
, aValue
);
323 if (!aFailureId
.IsEmpty()) {
324 nsAutoCString
failureprefname(prefname
);
325 failureprefname
+= ".failureid";
326 Preferences::SetCString(failureprefname
.get(), aFailureId
);
330 static void RemovePrefForFeature(int32_t aFeature
) {
331 const char* prefname
= GetPrefNameForFeature(aFeature
);
332 if (!prefname
) return;
334 if (XRE_IsParentProcess()) {
335 GfxInfoBase::sFeatureStatus
= nullptr;
337 Preferences::ClearUser(prefname
);
340 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
342 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
345 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
346 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
349 static void RemovePrefForDriverVersion() {
350 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
353 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
354 if (os
.EqualsLiteral("WINNT 6.1")) {
355 return OperatingSystem::Windows7
;
357 if (os
.EqualsLiteral("WINNT 6.2")) {
358 return OperatingSystem::Windows8
;
360 if (os
.EqualsLiteral("WINNT 6.3")) {
361 return OperatingSystem::Windows8_1
;
363 if (os
.EqualsLiteral("WINNT 10.0")) {
364 return OperatingSystem::Windows10
;
366 if (os
.EqualsLiteral("Linux")) {
367 return OperatingSystem::Linux
;
369 if (os
.EqualsLiteral("Darwin 9")) {
370 return OperatingSystem::OSX10_5
;
372 if (os
.EqualsLiteral("Darwin 10")) {
373 return OperatingSystem::OSX10_6
;
375 if (os
.EqualsLiteral("Darwin 11")) {
376 return OperatingSystem::OSX10_7
;
378 if (os
.EqualsLiteral("Darwin 12")) {
379 return OperatingSystem::OSX10_8
;
381 if (os
.EqualsLiteral("Darwin 13")) {
382 return OperatingSystem::OSX10_9
;
384 if (os
.EqualsLiteral("Darwin 14")) {
385 return OperatingSystem::OSX10_10
;
387 if (os
.EqualsLiteral("Darwin 15")) {
388 return OperatingSystem::OSX10_11
;
390 if (os
.EqualsLiteral("Darwin 16")) {
391 return OperatingSystem::OSX10_12
;
393 if (os
.EqualsLiteral("Darwin 17")) {
394 return OperatingSystem::OSX10_13
;
396 if (os
.EqualsLiteral("Darwin 18")) {
397 return OperatingSystem::OSX10_14
;
399 if (os
.EqualsLiteral("Darwin 19")) {
400 return OperatingSystem::OSX10_15
;
402 if (os
.EqualsLiteral("Darwin 20")) {
403 return OperatingSystem::OSX11_0
;
405 if (os
.EqualsLiteral("Android")) {
406 return OperatingSystem::Android
;
407 // For historical reasons, "All" in blocklist means "All Windows"
409 if (os
.EqualsLiteral("All")) {
410 return OperatingSystem::Windows
;
412 if (os
.EqualsLiteral("Darwin")) {
413 return OperatingSystem::OSX
;
416 return OperatingSystem::Unknown
;
419 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
420 nsTArray
<nsCString
>& devices
) {
421 if (devices
.Length() == 0) return nullptr;
423 // For each device, get its device ID, and return a freshly-allocated
424 // GfxDeviceFamily with the contents of that array.
425 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
427 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
428 // We make sure we don't add any "empty" device entries to the array, so
429 // we don't need to check if devices[i] is empty.
430 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
436 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
437 MOZ_ASSERT(!aFeature
.IsEmpty());
438 if (aFeature
.EqualsLiteral("DIRECT2D")) {
439 return nsIGfxInfo::FEATURE_DIRECT2D
;
441 if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS")) {
442 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
444 if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS")) {
445 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
447 if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
448 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
450 if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS")) {
451 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
453 if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE")) {
454 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
456 if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
457 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
459 if (aFeature
.EqualsLiteral("OPENGL_LAYERS")) {
460 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
462 if (aFeature
.EqualsLiteral("WEBGL_OPENGL")) {
463 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
465 if (aFeature
.EqualsLiteral("WEBGL_ANGLE")) {
466 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
468 if (aFeature
.EqualsLiteral("WEBGL_MSAA")) {
469 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
471 if (aFeature
.EqualsLiteral("STAGEFRIGHT")) {
472 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
474 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
475 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
477 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
478 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
480 if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
481 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
483 if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION")) {
484 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
486 if (aFeature
.EqualsLiteral("DX_INTEROP2")) {
487 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
489 if (aFeature
.EqualsLiteral("GPU_PROCESS")) {
490 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
492 if (aFeature
.EqualsLiteral("WEBGL2")) {
493 return nsIGfxInfo::FEATURE_WEBGL2
;
495 if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX")) {
496 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
498 if (aFeature
.EqualsLiteral("WEBRENDER")) {
499 return nsIGfxInfo::FEATURE_WEBRENDER
;
501 if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
502 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
504 if (aFeature
.EqualsLiteral("DX_NV12")) {
505 return nsIGfxInfo::FEATURE_DX_NV12
;
507 if (aFeature
.EqualsLiteral("VP8_HW_DECODE")) {
508 return nsIGfxInfo::FEATURE_VP8_HW_DECODE
;
510 if (aFeature
.EqualsLiteral("VP9_HW_DECODE")) {
511 return nsIGfxInfo::FEATURE_VP9_HW_DECODE
;
513 if (aFeature
.EqualsLiteral("GL_SWIZZLE")) {
514 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
516 if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
517 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
519 if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
520 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
522 if (aFeature
.EqualsLiteral("THREADSAFE_GL")) {
523 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
525 if (aFeature
.EqualsLiteral("X11_EGL")) {
526 return nsIGfxInfo::FEATURE_X11_EGL
;
528 if (aFeature
.EqualsLiteral("DMABUF")) {
529 return nsIGfxInfo::FEATURE_DMABUF
;
531 if (aFeature
.EqualsLiteral("WEBGPU")) {
532 return nsIGfxInfo::FEATURE_WEBGPU
;
534 if (aFeature
.EqualsLiteral("VIDEO_OVERLAY")) {
535 return nsIGfxInfo::FEATURE_VIDEO_OVERLAY
;
537 if (aFeature
.EqualsLiteral("HW_DECODED_VIDEO_ZERO_COPY")) {
538 return nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
;
540 if (aFeature
.EqualsLiteral("REUSE_DECODER_DEVICE")) {
541 return nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
;
543 if (aFeature
.EqualsLiteral("WEBRENDER_PARTIAL_PRESENT")) {
544 return nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT
;
546 if (aFeature
.EqualsLiteral("BACKDROP_FILTER")) {
547 return nsIGfxInfo::FEATURE_BACKDROP_FILTER
;
549 if (aFeature
.EqualsLiteral("ACCELERATED_CANVAS2D")) {
550 return nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D
;
552 if (aFeature
.EqualsLiteral("ALL")) {
553 return GfxDriverInfo::allFeatures
;
555 if (aFeature
.EqualsLiteral("OPTIONAL")) {
556 return GfxDriverInfo::optionalFeatures
;
559 // If we don't recognize the feature, it may be new, and something
560 // this version doesn't understand. So, nothing to do. This is
561 // different from feature not being specified at all, in which case
562 // this method should not get called and we should continue with the
563 // "optional features" blocklisting.
567 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
568 const nsAString
& aStatus
) {
569 if (aStatus
.EqualsLiteral("STATUS_OK")) {
570 return nsIGfxInfo::FEATURE_STATUS_OK
;
572 if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
573 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
575 if (aStatus
.EqualsLiteral("BLOCKED_DEVICE")) {
576 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
578 if (aStatus
.EqualsLiteral("DISCOURAGED")) {
579 return nsIGfxInfo::FEATURE_DISCOURAGED
;
581 if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION")) {
582 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
584 if (aStatus
.EqualsLiteral("DENIED")) {
585 return nsIGfxInfo::FEATURE_DENIED
;
587 if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED")) {
588 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
590 if (aStatus
.EqualsLiteral("ALLOW_ALWAYS")) {
591 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
594 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
595 // expecting the "mismatch" status showing up here.
597 return nsIGfxInfo::FEATURE_STATUS_OK
;
600 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
601 const nsAString
& op
) {
602 if (op
.EqualsLiteral("LESS_THAN")) {
603 return DRIVER_LESS_THAN
;
605 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN")) {
606 return DRIVER_BUILD_ID_LESS_THAN
;
608 if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
609 return DRIVER_LESS_THAN_OR_EQUAL
;
611 if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
612 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
614 if (op
.EqualsLiteral("GREATER_THAN")) {
615 return DRIVER_GREATER_THAN
;
617 if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
618 return DRIVER_GREATER_THAN_OR_EQUAL
;
620 if (op
.EqualsLiteral("EQUAL")) {
623 if (op
.EqualsLiteral("NOT_EQUAL")) {
624 return DRIVER_NOT_EQUAL
;
626 if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
627 return DRIVER_BETWEEN_EXCLUSIVE
;
629 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE")) {
630 return DRIVER_BETWEEN_INCLUSIVE
;
632 if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
633 return DRIVER_BETWEEN_INCLUSIVE_START
;
636 return DRIVER_COMPARISON_IGNORED
;
640 Deserialize Blocklist entries from string.
642 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
644 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
645 GfxDriverInfo
& aDriverInfo
) {
646 // If we get an application version to be zero, something is not working
647 // and we are not going to bother checking the blocklist versions.
648 // See TestGfxWidgets.cpp for how version comparison works.
649 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
650 static mozilla::Version
zeroV("0");
651 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
653 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
654 << "Invalid application version "
655 << GfxInfoBase::GetApplicationVersion().get();
658 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
660 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
661 nsTArray
<nsCString
> splitted
;
662 ParseString(keyValue
, ':', splitted
);
663 if (splitted
.Length() != 2) {
664 // If we don't recognize the input data, we do not want to proceed.
665 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
666 << "Unrecognized data " << nsCString(keyValue
).get();
669 const nsCString
& key
= splitted
[0];
670 const nsCString
& value
= splitted
[1];
671 NS_ConvertUTF8toUTF16
dataValue(value
);
673 if (value
.Length() == 0) {
674 // Safety check for empty values.
675 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
676 << "Empty value for " << key
.get();
680 if (key
.EqualsLiteral("blockID")) {
681 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
682 aDriverInfo
.mRuleId
= blockIdStr
.get();
683 } else if (key
.EqualsLiteral("os")) {
684 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
685 } else if (key
.EqualsLiteral("osversion")) {
686 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
687 } else if (key
.EqualsLiteral("windowProtocol")) {
688 aDriverInfo
.mWindowProtocol
= dataValue
;
689 } else if (key
.EqualsLiteral("vendor")) {
690 aDriverInfo
.mAdapterVendor
= dataValue
;
691 } else if (key
.EqualsLiteral("driverVendor")) {
692 aDriverInfo
.mDriverVendor
= dataValue
;
693 } else if (key
.EqualsLiteral("feature")) {
694 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
695 if (aDriverInfo
.mFeature
== 0) {
696 // If we don't recognize the feature, we do not want to proceed.
697 gfxWarning() << "Unrecognized feature " << value
.get();
700 } else if (key
.EqualsLiteral("featureStatus")) {
701 aDriverInfo
.mFeatureStatus
=
702 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
703 } else if (key
.EqualsLiteral("driverVersion")) {
705 if (ParseDriverVersion(dataValue
, &version
))
706 aDriverInfo
.mDriverVersion
= version
;
707 } else if (key
.EqualsLiteral("driverVersionMax")) {
709 if (ParseDriverVersion(dataValue
, &version
))
710 aDriverInfo
.mDriverVersionMax
= version
;
711 } else if (key
.EqualsLiteral("driverVersionComparator")) {
712 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
713 } else if (key
.EqualsLiteral("model")) {
714 aDriverInfo
.mModel
= dataValue
;
715 } else if (key
.EqualsLiteral("product")) {
716 aDriverInfo
.mProduct
= dataValue
;
717 } else if (key
.EqualsLiteral("manufacturer")) {
718 aDriverInfo
.mManufacturer
= dataValue
;
719 } else if (key
.EqualsLiteral("hardware")) {
720 aDriverInfo
.mHardware
= dataValue
;
721 } else if (key
.EqualsLiteral("versionRange")) {
722 nsTArray
<nsCString
> versionRange
;
723 ParseString(value
, ',', versionRange
);
724 if (versionRange
.Length() != 2) {
725 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
726 << "Unrecognized versionRange " << value
.get();
729 const nsCString
& minValue
= versionRange
[0];
730 const nsCString
& maxValue
= versionRange
[1];
732 mozilla::Version
minV(minValue
.get());
733 mozilla::Version
maxV(maxValue
.get());
735 if (minV
> zeroV
&& !(appV
>= minV
)) {
736 // The version of the application is less than the minimal version
737 // this blocklist entry applies to, so we can just ignore it by
738 // returning false and letting the caller deal with it.
741 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
742 // The version of the application is more than the maximal 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 } else if (key
.EqualsLiteral("devices")) {
748 nsTArray
<nsCString
> devices
;
749 ParseString(value
, ',', devices
);
750 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
752 // Get GfxDriverInfo to adopt the devices array we created.
753 aDriverInfo
.mDeleteDevices
= true;
754 aDriverInfo
.mDevices
= deviceIds
;
757 // We explicitly ignore unknown elements.
764 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
765 const char16_t
* aData
) {
766 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
767 nsTArray
<GfxDriverInfo
> driverInfo
;
768 NS_ConvertUTF16toUTF8
utf8Data(aData
);
770 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
772 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
773 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
774 // Probably some non-standard semantics of the copy/move operations?
775 *driverInfo
.AppendElement() = di
;
776 // Prevent di falling out of scope from destroying the devices.
777 di
.mDeleteDevices
= false;
779 driverInfo
.AppendElement();
783 EvaluateDownloadedBlocklist(driverInfo
);
789 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
791 GfxInfoBase::~GfxInfoBase() = default;
793 nsresult
GfxInfoBase::Init() {
794 InitGfxDriverInfoShutdownObserver();
796 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
798 os
->AddObserver(this, "blocklist-data-gfxItems", true);
804 void GfxInfoBase::GetData() {
805 if (mScreenPixels
!= INT64_MAX
) {
806 // Already initialized.
810 ScreenManager::GetSingleton().GetTotalScreenPixels(&mScreenPixels
);
814 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
816 // Ignore the gfx.blocklist.all pref on release and beta.
817 #if defined(RELEASE_OR_BETA)
818 int32_t blocklistAll
= 0;
820 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
822 if (blocklistAll
> 0) {
823 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
824 << "Forcing blocklisting all features";
825 *aStatus
= FEATURE_BLOCKED_DEVICE
;
826 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
830 if (blocklistAll
< 0) {
831 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
832 << "Ignoring any feature blocklisting.";
833 *aStatus
= FEATURE_STATUS_OK
;
837 // This is how we evaluate the downloadable blocklist. If there is no pref,
838 // then we will fallback to checking the static blocklist.
839 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
843 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
844 // Use the cached data received from the parent process.
845 MOZ_ASSERT(sFeatureStatus
);
846 bool success
= false;
847 for (const auto& fs
: *sFeatureStatus
) {
848 if (fs
.feature() == aFeature
) {
849 aFailureId
= fs
.failureId();
850 *aStatus
= fs
.status();
855 return success
? NS_OK
: NS_ERROR_FAILURE
;
859 nsTArray
<GfxDriverInfo
> driverInfo
;
861 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
865 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
866 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
867 if (!sFeatureStatus
) {
868 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
869 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
871 nsAutoCString failureId
;
872 GetFeatureStatus(i
, failureId
, &status
);
873 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
874 gfxFeatureStatus
.feature() = i
;
875 gfxFeatureStatus
.status() = status
;
876 gfxFeatureStatus
.failureId() = failureId
;
877 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
881 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
882 for (const auto& status
: *sFeatureStatus
) {
883 gfx::GfxInfoFeatureStatus copy
= status
;
884 features
.AppendElement(copy
);
889 inline bool MatchingAllowStatus(int32_t aStatus
) {
891 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
892 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
899 // Matching OS go somewhat beyond the simple equality check because of the
900 // "All Windows" and "All OS X" variations.
902 // aBlockedOS is describing the system(s) we are trying to block.
903 // aSystemOS is describing the system we are running on.
905 // aSystemOS should not be "Windows" or "OSX" - it should be set to
906 // a particular version instead.
907 // However, it is valid for aBlockedOS to be one of those generic values,
908 // as we could be blocking all of the versions.
909 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
910 OperatingSystem aSystemOS
,
911 uint32_t aSystemOSBuild
) {
912 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
913 aSystemOS
!= OperatingSystem::OSX
);
915 // If the block entry OS is unknown, it doesn't match
916 if (aBlockedOS
== OperatingSystem::Unknown
) {
921 if (aBlockedOS
== OperatingSystem::Windows
) {
922 // We do want even "unknown" aSystemOS to fall under "all windows"
926 constexpr uint32_t kMinWin10BuildNumber
= 18362;
927 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
928 aSystemOS
== OperatingSystem::Windows10
) {
929 // For allowlist purposes, we sometimes want to restrict to only recent
930 // versions of Windows 10. This is a bit of a kludge but easier than adding
931 // complicated blocklist infrastructure for build ID comparisons like driver
933 return aSystemOSBuild
>= kMinWin10BuildNumber
;
936 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
937 if (aSystemOS
== OperatingSystem::Windows10
) {
938 return aSystemOSBuild
< kMinWin10BuildNumber
;
945 #if defined(XP_MACOSX)
946 if (aBlockedOS
== OperatingSystem::OSX
) {
947 // We do want even "unknown" aSystemOS to fall under "all OS X"
952 return aSystemOS
== aBlockedOS
;
955 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
956 switch (aBatteryStatus
) {
957 case BatteryStatus::All
:
959 case BatteryStatus::None
:
961 case BatteryStatus::Present
:
965 MOZ_ASSERT_UNREACHABLE("bad battery status");
969 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
970 int64_t aScreenPixels
) {
971 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
972 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
974 switch (aScreenStatus
) {
975 case ScreenSizeStatus::All
:
977 case ScreenSizeStatus::Small
:
978 return aScreenPixels
<= kMaxSmallPixels
;
979 case ScreenSizeStatus::SmallAndMedium
:
980 return aScreenPixels
<= kMaxMediumPixels
;
981 case ScreenSizeStatus::Medium
:
982 return aScreenPixels
> kMaxSmallPixels
&&
983 aScreenPixels
<= kMaxMediumPixels
;
984 case ScreenSizeStatus::MediumAndLarge
:
985 return aScreenPixels
> kMaxSmallPixels
;
986 case ScreenSizeStatus::Large
:
987 return aScreenPixels
> kMaxMediumPixels
;
990 MOZ_ASSERT_UNREACHABLE("bad screen status");
994 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
995 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
996 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
998 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
1000 // Some properties are not available on all platforms.
1001 nsAutoString windowProtocol
;
1002 nsresult rv
= GetWindowProtocol(windowProtocol
);
1003 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
1007 bool hasBattery
= false;
1008 rv
= GetHasBattery(&hasBattery
);
1009 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
1013 uint32_t osBuild
= OperatingSystemBuild();
1015 // Get the adapters once then reuse below
1016 nsAutoString adapterVendorID
[2];
1017 nsAutoString adapterDeviceID
[2];
1018 nsAutoString adapterDriverVendor
[2];
1019 nsAutoString adapterDriverVersionString
[2];
1020 bool adapterInfoFailed
[2];
1022 adapterInfoFailed
[0] =
1023 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
1024 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
1025 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
1026 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
1027 adapterInfoFailed
[1] =
1028 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
1029 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
1030 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
1031 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
1032 // No point in going on if we don't have adapter info
1033 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
1037 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1038 uint64_t driverVersion
[2] = {0, 0};
1039 if (!adapterInfoFailed
[0]) {
1040 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
1042 if (!adapterInfoFailed
[1]) {
1043 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
1048 for (; i
< info
.Length(); i
++) {
1049 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
1050 // blocklisting. Only consider entries for our search mode.
1051 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
1055 // If we don't have the info for this GPU, no need to check further.
1056 // It is unclear that we would ever have a mixture of 1st and 2nd
1057 // GPU, but leaving the code in for that possibility for now.
1058 // (Actually, currently mGpu2 will never be true, so this can
1059 // be optimized out.)
1060 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
1061 if (adapterInfoFailed
[infoIndex
]) {
1065 // Do the operating system check first, no point in getting the driver
1066 // info if we won't need to use it.
1067 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
1071 if (info
[i
].mOperatingSystemVersion
&&
1072 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
1076 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
1080 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
1084 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
1088 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
1092 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
1093 adapterDriverVendor
[infoIndex
])) {
1097 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
1098 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
1099 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
1104 // Failed to search, allowlist should not match, blocklist should match
1105 // for safety reasons
1115 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
1118 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
1121 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
1124 if (!info
[i
].mManufacturer
.IsEmpty() &&
1125 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1129 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1130 switch (info
[i
].mComparisonOp
) {
1131 case DRIVER_LESS_THAN
:
1132 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1134 case DRIVER_BUILD_ID_LESS_THAN
:
1135 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1137 case DRIVER_LESS_THAN_OR_EQUAL
:
1138 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1140 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1141 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1143 case DRIVER_GREATER_THAN
:
1144 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1146 case DRIVER_GREATER_THAN_OR_EQUAL
:
1147 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1150 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1152 case DRIVER_NOT_EQUAL
:
1153 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1155 case DRIVER_BETWEEN_EXCLUSIVE
:
1156 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1157 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1159 case DRIVER_BETWEEN_INCLUSIVE
:
1160 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1161 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1163 case DRIVER_BETWEEN_INCLUSIVE_START
:
1164 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1165 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1167 case DRIVER_COMPARISON_IGNORED
:
1168 // We don't have a comparison op, so we match everything.
1172 NS_WARNING("Bogus op in GfxDriverInfo");
1176 // We don't care what driver version it was. We only check OS version and if
1177 // the device matches.
1181 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1182 if (info
[i
].mFeature
== GfxDriverInfo::allFeatures
||
1183 info
[i
].mFeature
== aFeature
||
1184 (info
[i
].mFeature
== GfxDriverInfo::optionalFeatures
&&
1185 OnlyAllowFeatureOnKnownConfig(aFeature
))) {
1186 status
= info
[i
].mFeatureStatus
;
1187 if (!info
[i
].mRuleId
.IsEmpty()) {
1188 aFailureId
= info
[i
].mRuleId
.get();
1190 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1198 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1199 // as either the primary or secondary adapter. D2D is also blocked when the
1200 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1201 // If the primary GPU already matched something in the blocklist then we
1202 // ignore this special rule. See bug 1008759.
1203 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1204 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1205 if (!adapterInfoFailed
[1]) {
1206 nsAString
& nvVendorID
=
1207 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1208 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1209 if (nvVendorID
.Equals(adapterVendorID
[1],
1210 nsCaseInsensitiveStringComparator
) &&
1211 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1212 nsCaseInsensitiveStringComparator
)) {
1213 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1214 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1219 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1220 // back to the Windows handler, so we must handle this here.
1221 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1222 if (info
[i
].mSuggestedVersion
) {
1223 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1224 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1225 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1226 aSuggestedVersion
.AppendPrintf(
1227 "%lld.%lld.%lld.%lld",
1228 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1229 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1230 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1231 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1239 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1240 MOZ_ASSERT(!sFeatureStatus
);
1241 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1244 bool GfxInfoBase::DoesWindowProtocolMatch(
1245 const nsAString
& aBlocklistWindowProtocol
,
1246 const nsAString
& aWindowProtocol
) {
1247 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1248 nsCaseInsensitiveStringComparator
) ||
1249 aBlocklistWindowProtocol
.Equals(
1250 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1251 nsCaseInsensitiveStringComparator
);
1254 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1255 const nsAString
& aAdapterVendor
) {
1256 return aBlocklistVendor
.Equals(aAdapterVendor
,
1257 nsCaseInsensitiveStringComparator
) ||
1258 aBlocklistVendor
.Equals(
1259 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1260 nsCaseInsensitiveStringComparator
);
1263 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1264 const nsAString
& aDriverVendor
) {
1265 return aBlocklistVendor
.Equals(aDriverVendor
,
1266 nsCaseInsensitiveStringComparator
) ||
1267 aBlocklistVendor
.Equals(
1268 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1269 nsCaseInsensitiveStringComparator
);
1272 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1273 return aFeature
== nsIGfxInfo::FEATURE_VIDEO_OVERLAY
||
1274 aFeature
== nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
;
1277 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1278 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1279 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1280 OperatingSystem
* aOS
/* = nullptr */) {
1281 if (aFeature
<= 0) {
1282 gfxWarning() << "Invalid feature <= 0";
1286 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1287 // Terminate now with the status determined by the derived type (OS-specific
1292 if (sShutdownOccurred
) {
1293 // This is futile; we've already commenced shutdown and our blocklists have
1294 // been deleted. We may want to look into resurrecting the blocklist instead
1295 // but for now, just don't even go there.
1299 // Ensure any additional initialization required is complete.
1302 // If an operating system was provided by the derived GetFeatureStatusImpl,
1303 // grab it here. Otherwise, the OS is unknown.
1304 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1306 nsAutoString adapterVendorID
;
1307 nsAutoString adapterDeviceID
;
1308 nsAutoString adapterDriverVersionString
;
1309 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1310 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1311 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1312 if (OnlyAllowFeatureOnKnownConfig(aFeature
)) {
1313 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1314 *aStatus
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1316 *aStatus
= nsIGfxInfo::FEATURE_STATUS_OK
;
1321 // We only check either the given blocklist, or the static list, as given.
1323 if (aDriverInfo
.Length()) {
1325 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1326 aFailureId
, os
, /* aForAllowing */ false);
1329 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1331 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1332 aFeature
, aFailureId
, os
,
1333 /* aForAllowing */ false);
1336 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1337 if (IsFeatureAllowlisted(aFeature
)) {
1338 // This feature is actually using the allowlist; that means after we pass
1339 // the blocklist to prevent us explicitly from getting the feature, we now
1340 // need to check the allowlist to ensure we are allowed to get it in the
1342 if (aDriverInfo
.Length()) {
1343 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1344 aFeature
, aFailureId
, os
,
1345 /* aForAllowing */ true);
1347 status
= FindBlocklistedDeviceInList(
1348 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1349 /* aForAllowing */ true);
1352 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1353 status
= nsIGfxInfo::FEATURE_DENIED
;
1356 // It's now done being processed. It's safe to set the status to
1358 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1367 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1368 nsAString
& aVersion
) {
1370 if (GetPrefValueForDriverVersion(version
)) {
1371 aVersion
= NS_ConvertASCIItoUTF16(version
);
1376 nsCString discardFailureId
;
1377 nsTArray
<GfxDriverInfo
> driverInfo
;
1378 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1382 void GfxInfoBase::EvaluateDownloadedBlocklist(
1383 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1384 // If the list is empty, then we don't actually want to call
1385 // GetFeatureStatusImpl since we will use the static list instead. In that
1386 // case, all we want to do is make sure the pref is removed.
1387 if (aDriverInfo
.IsEmpty()) {
1388 gfxCriticalNoteOnce
<< "Evaluate empty downloaded blocklist";
1392 OperatingSystem os
= GetOperatingSystem();
1394 // For every feature we know about, we evaluate whether this blocklist has a
1395 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1396 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1397 // anywhere permanent.
1398 for (int feature
= 1; feature
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++feature
) {
1399 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
1400 nsCString failureId
;
1401 nsAutoString suggestedVersion
;
1403 // Note that we are careful to call the base class method since we only want
1404 // to evaluate the downloadable blocklist for these prefs.
1405 MOZ_ALWAYS_TRUE(NS_SUCCEEDED(GfxInfoBase::GetFeatureStatusImpl(
1406 feature
, &status
, suggestedVersion
, aDriverInfo
, failureId
, &os
)));
1410 MOZ_FALLTHROUGH_ASSERT("Unhandled feature status!");
1411 case nsIGfxInfo::FEATURE_STATUS_UNKNOWN
:
1412 // This may be returned during shutdown or for invalid features.
1413 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
1414 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
1415 case nsIGfxInfo::FEATURE_DENIED
:
1416 // We cannot use the downloadable blocklist to control the allowlist.
1417 // If a feature is allowlisted, then we should also ignore DENIED
1418 // statuses from GetFeatureStatusImpl because we don't check the
1419 // static list when and this is an expected value. If we wish to
1420 // override the allowlist, it is as simple as creating a normal
1421 // blocklist rule with a BLOCKED* status code.
1422 case nsIGfxInfo::FEATURE_STATUS_OK
:
1423 RemovePrefForFeature(feature
);
1426 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1427 if (!suggestedVersion
.IsEmpty()) {
1428 SetPrefValueForDriverVersion(suggestedVersion
);
1430 RemovePrefForDriverVersion();
1434 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1435 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1436 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1437 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1438 case nsIGfxInfo::FEATURE_BLOCKED_PLATFORM_TEST
:
1439 SetPrefValueForFeature(feature
, status
, failureId
);
1445 NS_IMETHODIMP_(void)
1446 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1447 // gfxCriticalError has a mutex lock of its own, so we may not actually
1448 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1449 // will not return the copy of the logs unless it can get the same lock
1450 // that gfxCriticalError uses. Still, that is so much of an implementation
1451 // detail that it's nicer to just add an extra lock here and in
1453 MutexAutoLock
lock(mMutex
);
1455 // By default, gfxCriticalError asserts; make it not assert in this case.
1456 gfxCriticalError(CriticalLog::DefaultOptions(false))
1457 << "(LF) " << failure
.BeginReading();
1460 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1461 nsTArray
<nsCString
>& failures
) {
1462 MutexAutoLock
lock(mMutex
);
1464 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1465 if (!logForwarder
) {
1466 return NS_ERROR_UNEXPECTED
;
1469 // There are two string copies in this method, starting with this one. We are
1470 // assuming this is not a big deal, as the size of the array should be small
1471 // and the strings in it should be small as well (the error messages in the
1472 // code.) The second copy happens with the AppendElement() calls.
1473 // Technically, we don't need the mutex lock after the StringVectorCopy()
1475 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1476 LoggingRecord::const_iterator it
;
1477 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1478 failures
.AppendElement(nsDependentCSubstring(std::get
<1>(*it
).c_str(),
1479 std::get
<1>(*it
).size()));
1480 indices
.AppendElement(std::get
<0>(*it
));
1486 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1488 static void InitCollectors() {
1489 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1492 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1493 JS::MutableHandle
<JS::Value
> aResult
) {
1495 InfoObject
obj(aCx
);
1497 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1498 (*sCollectors
)[i
]->GetInfo(obj
);
1501 // Some example property definitions
1502 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1503 // obj.DefineProperty("renderer", mRendererIDsString);
1504 // obj.DefineProperty("five", 5);
1507 return NS_ERROR_FAILURE
;
1510 aResult
.setObject(*obj
.mObj
);
1514 nsAutoCString gBaseAppVersion
;
1516 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1517 static bool versionInitialized
= false;
1518 if (!versionInitialized
) {
1519 // If we fail to get the version, we will not try again.
1520 versionInitialized
= true;
1522 // Get the version from xpcom/system/nsIXULAppInfo.idl
1523 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1525 app
->GetVersion(gBaseAppVersion
);
1528 return gBaseAppVersion
;
1531 /* static */ bool GfxInfoBase::OnlyAllowFeatureOnKnownConfig(int32_t aFeature
) {
1533 // The GPU process doesn't need hardware acceleration and can run on
1534 // devices that we normally block from not being on our whitelist.
1535 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
1537 // We can mostly assume that ANGLE will work
1538 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
1539 // Remote WebGL is needed for Win32k Lockdown, so it should be enabled
1540 // regardless of HW support or not
1541 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
1542 // Backdrop filter should generally work, especially if we fall back to
1543 // Software WebRender because of an unknown vendor.
1544 case nsIGfxInfo::FEATURE_BACKDROP_FILTER
:
1551 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1553 sCollectors
->AppendElement(collector
);
1556 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1558 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1559 if ((*sCollectors
)[i
] == collector
) {
1560 sCollectors
->RemoveElementAt(i
);
1564 if (sCollectors
->IsEmpty()) {
1566 sCollectors
= nullptr;
1570 static void AppendMonitor(JSContext
* aCx
, widget::Screen
& aScreen
,
1571 JS::Handle
<JSObject
*> aOutArray
, int32_t aIndex
) {
1572 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1574 auto screenSize
= aScreen
.GetRect().Size();
1576 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1577 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1579 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1580 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1582 // XXX Just preserving behavior since this is exposed to telemetry, but we
1583 // could consider including this everywhere.
1585 JS::Rooted
<JS::Value
> scale(
1586 aCx
, JS::NumberValue(aScreen
.GetContentsScaleFactor()));
1587 JS_SetProperty(aCx
, obj
, "scale", scale
);
1591 JS::Rooted
<JS::Value
> refreshRate(aCx
,
1592 JS::Int32Value(aScreen
.GetRefreshRate()));
1593 JS_SetProperty(aCx
, obj
, "refreshRate", refreshRate
);
1595 JS::Rooted
<JS::Value
> pseudoDisplay(
1596 aCx
, JS::BooleanValue(aScreen
.GetIsPseudoDisplay()));
1597 JS_SetProperty(aCx
, obj
, "pseudoDisplay", pseudoDisplay
);
1600 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1601 JS_SetElement(aCx
, aOutArray
, aIndex
, element
);
1604 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
,
1605 JS::Handle
<JSObject
*> aOutArray
) {
1607 auto& sm
= ScreenManager::GetSingleton();
1608 for (auto& screen
: sm
.CurrentScreenList()) {
1609 AppendMonitor(aCx
, *screen
, aOutArray
, index
++);
1613 // Ensure we return at least one monitor, this is needed for xpcshell.
1614 RefPtr
<Screen
> screen
= sm
.GetPrimaryScreen();
1615 AppendMonitor(aCx
, *screen
, aOutArray
, index
++);
1622 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
) {
1623 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1625 nsresult rv
= FindMonitors(aCx
, array
);
1626 if (NS_FAILED(rv
)) {
1630 aResult
.setObject(*array
);
1634 static inline bool SetJSPropertyString(JSContext
* aCx
,
1635 JS::Handle
<JSObject
*> aObj
,
1636 const char* aProp
, const char* aString
) {
1637 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1642 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1643 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1646 template <typename T
>
1647 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1650 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1653 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1656 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1657 JS::MutableHandle
<JS::Value
> aOut
) {
1658 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1660 return NS_ERROR_OUT_OF_MEMORY
;
1662 aOut
.setObject(*obj
);
1664 layers::LayersBackend backend
=
1665 gfxPlatform::Initialized()
1666 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1667 : layers::LayersBackend::LAYERS_NONE
;
1668 const char* backendName
= layers::GetLayersBackendName(backend
);
1669 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1671 // If graphics isn't initialized yet, just stop now.
1672 if (!gfxPlatform::Initialized()) {
1676 DescribeFeatures(aCx
, obj
);
1680 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1681 JS::MutableHandle
<JS::Value
> aOut
) {
1682 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1683 if (!containerObj
) {
1684 return NS_ERROR_OUT_OF_MEMORY
;
1686 aOut
.setObject(*containerObj
);
1688 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1689 if (!featureArray
) {
1690 return NS_ERROR_OUT_OF_MEMORY
;
1693 // Collect features.
1694 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1695 FeatureState
& aFeature
) -> void {
1696 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1700 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1701 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1702 !SetJSPropertyString(aCx
, obj
, "status",
1703 FeatureStatusToString(aFeature
.GetValue()))) {
1707 JS::Rooted
<JS::Value
> log(aCx
);
1708 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1711 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1715 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1720 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1721 if (!fallbackArray
) {
1722 return NS_ERROR_OUT_OF_MEMORY
;
1725 // Collect fallbacks.
1726 gfxConfig::ForEachFallback(
1727 [&](const char* aName
, const char* aMessage
) -> void {
1728 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1733 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1734 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1738 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1743 JS::Rooted
<JS::Value
> val(aCx
);
1745 val
= JS::ObjectValue(*featureArray
);
1746 JS_SetProperty(aCx
, containerObj
, "features", val
);
1748 val
= JS::ObjectValue(*fallbackArray
);
1749 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1754 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1755 const FeatureState
& aFeature
,
1756 JS::MutableHandle
<JS::Value
> aOut
) {
1757 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1761 aOut
.setObject(*log
);
1763 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1764 const char* aMessage
,
1765 const nsCString
& aFailureId
) -> void {
1766 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1771 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1772 !SetJSPropertyString(aCx
, obj
, "status",
1773 FeatureStatusToString(aStatus
)) ||
1774 (!aFailureId
.IsEmpty() &&
1775 !SetJSPropertyString(aCx
, obj
, "failureId", aFailureId
.get())) ||
1776 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1780 if (!AppendJSElement(aCx
, log
, obj
)) {
1788 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1789 JS::Rooted
<JSObject
*> obj(aCx
);
1791 gfx::FeatureState
& hwCompositing
=
1792 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1793 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1795 gfx::FeatureState
& gpuProcess
=
1796 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1797 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1799 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1800 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1802 gfx::FeatureState
& wrCompositor
=
1803 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1804 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1806 gfx::FeatureState
& openglCompositing
=
1807 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1808 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1810 gfx::FeatureState
& omtp
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1811 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1814 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1815 JS::Handle
<JSObject
*> aContainer
,
1817 mozilla::gfx::FeatureState
& aFeatureState
,
1818 JS::MutableHandle
<JSObject
*> aOutObj
) {
1819 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1824 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1826 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1827 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1828 JS_SetProperty(aCx
, obj
, "status", val
);
1830 // Add the feature object to the container.
1832 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1833 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1840 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1841 JS::MutableHandle
<JS::Value
> aOut
) {
1842 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1844 return NS_ERROR_OUT_OF_MEMORY
;
1846 aOut
.setObject(*array
);
1848 DriverCrashGuard::ForEachActiveCrashGuard(
1849 [&](const char* aName
, const char* aPrefName
) -> void {
1850 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1854 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1857 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1860 if (!AppendJSElement(aCx
, array
, obj
)) {
1869 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1870 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1875 GfxInfoBase::GetCodecSupportInfo(nsACString
& aCodecSupportInfo
) {
1876 aCodecSupportInfo
.Assign(gfx::gfxVars::CodecSupportInfo());
1881 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1882 *aIsHeadless
= gfxPlatform::IsHeadless();
1887 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1888 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1892 case BackendType::DIRECT2D1_1
: {
1893 outStr
.AppendPrintf("Direct2D 1.1");
1896 case BackendType::SKIA
: {
1897 outStr
.AppendPrintf("Skia");
1900 case BackendType::CAIRO
: {
1901 outStr
.AppendPrintf("Cairo");
1905 return NS_ERROR_FAILURE
;
1908 aContentBackend
.Assign(outStr
);
1913 GfxInfoBase::GetAzureCanvasBackend(nsAString
& aBackend
) {
1914 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1915 gfxPlatform::GetPlatform()->GetAzureCanvasBackend()),
1921 GfxInfoBase::GetAzureContentBackend(nsAString
& aBackend
) {
1922 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1923 gfxPlatform::GetPlatform()->GetAzureContentBackend()),
1929 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1930 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1932 // Not supported in content processes.
1933 return NS_ERROR_FAILURE
;
1936 *aOutValue
= !!gpu
->GetGPUChild();
1940 NS_IMETHODIMP_(int32_t)
1941 GfxInfoBase::GetMaxRefreshRate(bool* aMixed
) {
1946 int32_t maxRefreshRate
= 0;
1947 for (auto& screen
: ScreenManager::GetSingleton().CurrentScreenList()) {
1948 int32_t refreshRate
= screen
->GetRefreshRate();
1949 if (aMixed
&& maxRefreshRate
> 0 && maxRefreshRate
!= refreshRate
) {
1952 maxRefreshRate
= std::max(maxRefreshRate
, refreshRate
);
1955 return maxRefreshRate
> 0 ? maxRefreshRate
: -1;
1959 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1960 gfxPlatform::GetPlatform();
1962 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1964 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1965 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1967 DebugOnly
<nsresult
> rv
= gpm
->EnsureGPUReady();
1968 MOZ_ASSERT(rv
!= NS_ERROR_ILLEGAL_DURING_SHUTDOWN
);
1970 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1978 NS_IMETHODIMP
GfxInfoBase::KillGPUProcessForTests() {
1979 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1981 // gfxPlatform has not been initialized.
1982 return NS_ERROR_NOT_INITIALIZED
;
1989 NS_IMETHODIMP
GfxInfoBase::CrashGPUProcessForTests() {
1990 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1992 // gfxPlatform has not been initialized.
1993 return NS_ERROR_NOT_INITIALIZED
;
1996 gpm
->CrashProcess();
2000 GfxInfoCollectorBase::GfxInfoCollectorBase() {
2001 GfxInfoBase::AddCollector(this);
2004 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
2005 GfxInfoBase::RemoveCollector(this);