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
17 #include "nsCOMArray.h"
19 #include "nsUnicharUtils.h"
20 #include "nsVersionComparator.h"
21 #include "mozilla/Services.h"
22 #include "mozilla/Observer.h"
23 #include "nsIObserver.h"
24 #include "nsIObserverService.h"
25 #include "nsIScreenManager.h"
27 #include "nsXULAppAPI.h"
28 #include "nsIXULAppInfo.h"
29 #include "mozilla/ClearOnShutdown.h"
30 #include "mozilla/Preferences.h"
31 #include "mozilla/StaticPrefs_gfx.h"
32 #include "mozilla/gfx/2D.h"
33 #include "mozilla/gfx/GPUProcessManager.h"
34 #include "mozilla/gfx/Logging.h"
35 #include "mozilla/gfx/gfxVars.h"
36 #include "mozilla/layers/PaintThread.h"
38 #include "gfxPlatform.h"
39 #include "gfxConfig.h"
40 #include "DriverCrashGuard.h"
42 using namespace mozilla::widget
;
43 using namespace mozilla
;
44 using mozilla::MutexAutoLock
;
46 nsTArray
<GfxDriverInfo
>* GfxInfoBase::sDriverInfo
;
47 StaticAutoPtr
<nsTArray
<gfx::GfxInfoFeatureStatus
>> GfxInfoBase::sFeatureStatus
;
48 bool GfxInfoBase::sDriverInfoObserverInitialized
;
49 bool GfxInfoBase::sShutdownOccurred
;
51 // Call this when setting sFeatureStatus to a non-null pointer to
52 // ensure destruction even if the GfxInfo component is never instantiated.
53 static void InitFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>* aPtr
) {
54 static std::once_flag sOnce
;
55 std::call_once(sOnce
, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus
); });
56 GfxInfoBase::sFeatureStatus
= aPtr
;
59 // Observes for shutdown so that the child GfxDriverInfo list is freed.
60 class ShutdownObserver
: public nsIObserver
{
61 virtual ~ShutdownObserver() = default;
64 ShutdownObserver() = default;
68 NS_IMETHOD
Observe(nsISupports
* subject
, const char* aTopic
,
69 const char16_t
* aData
) override
{
70 MOZ_ASSERT(strcmp(aTopic
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
) == 0);
72 delete GfxInfoBase::sDriverInfo
;
73 GfxInfoBase::sDriverInfo
= nullptr;
75 for (auto& deviceFamily
: GfxDriverInfo::sDeviceFamilies
) {
77 deviceFamily
= nullptr;
80 for (auto& desktop
: GfxDriverInfo::sDesktopEnvironment
) {
85 for (auto& windowProtocol
: GfxDriverInfo::sWindowProtocol
) {
86 delete windowProtocol
;
87 windowProtocol
= nullptr;
90 for (auto& deviceVendor
: GfxDriverInfo::sDeviceVendors
) {
92 deviceVendor
= nullptr;
95 for (auto& driverVendor
: GfxDriverInfo::sDriverVendors
) {
97 driverVendor
= nullptr;
100 GfxInfoBase::sShutdownOccurred
= true;
106 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
108 static void InitGfxDriverInfoShutdownObserver() {
109 if (GfxInfoBase::sDriverInfoObserverInitialized
) return;
111 GfxInfoBase::sDriverInfoObserverInitialized
= true;
113 nsCOMPtr
<nsIObserverService
> observerService
= services::GetObserverService();
114 if (!observerService
) {
115 NS_WARNING("Could not get observer service!");
119 ShutdownObserver
* obs
= new ShutdownObserver();
120 observerService
->AddObserver(obs
, NS_XPCOM_SHUTDOWN_OBSERVER_ID
, false);
123 using namespace mozilla::widget
;
124 using namespace mozilla::gfx
;
125 using namespace mozilla
;
127 NS_IMPL_ISUPPORTS(GfxInfoBase
, nsIGfxInfo
, nsIObserver
,
128 nsISupportsWeakReference
)
130 #define BLOCKLIST_PREF_BRANCH "gfx.blacklist."
131 #define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
133 static const char* GetPrefNameForFeature(int32_t aFeature
) {
134 const char* name
= nullptr;
136 case nsIGfxInfo::FEATURE_DIRECT2D
:
137 name
= BLOCKLIST_PREF_BRANCH
"direct2d";
139 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
:
140 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d9";
142 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
:
143 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10";
145 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
:
146 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d10-1";
148 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
:
149 name
= BLOCKLIST_PREF_BRANCH
"layers.direct3d11";
151 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
:
152 name
= BLOCKLIST_PREF_BRANCH
"direct3d11angle";
154 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
:
155 name
= BLOCKLIST_PREF_BRANCH
"hardwarevideodecoding";
157 case nsIGfxInfo::FEATURE_OPENGL_LAYERS
:
158 name
= BLOCKLIST_PREF_BRANCH
"layers.opengl";
160 case nsIGfxInfo::FEATURE_WEBGL_OPENGL
:
161 name
= BLOCKLIST_PREF_BRANCH
"webgl.opengl";
163 case nsIGfxInfo::FEATURE_WEBGL_ANGLE
:
164 name
= BLOCKLIST_PREF_BRANCH
"webgl.angle";
166 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
:
167 name
= BLOCKLIST_PREF_BRANCH
"webgl.msaa";
169 case nsIGfxInfo::FEATURE_STAGEFRIGHT
:
170 name
= BLOCKLIST_PREF_BRANCH
"stagefright";
172 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
:
173 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.h264";
175 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
:
176 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.encode";
178 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
:
179 name
= BLOCKLIST_PREF_BRANCH
"webrtc.hw.acceleration.decode";
181 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
:
182 name
= BLOCKLIST_PREF_BRANCH
"canvas2d.acceleration";
184 case nsIGfxInfo::FEATURE_DX_INTEROP2
:
185 name
= BLOCKLIST_PREF_BRANCH
"dx.interop2";
187 case nsIGfxInfo::FEATURE_GPU_PROCESS
:
188 name
= BLOCKLIST_PREF_BRANCH
"gpu.process";
190 case nsIGfxInfo::FEATURE_WEBGL2
:
191 name
= BLOCKLIST_PREF_BRANCH
"webgl2";
193 case nsIGfxInfo::FEATURE_ADVANCED_LAYERS
:
194 name
= BLOCKLIST_PREF_BRANCH
"layers.advanced";
196 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
:
197 name
= BLOCKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
199 case nsIGfxInfo::FEATURE_WEBRENDER
:
200 name
= BLOCKLIST_PREF_BRANCH
"webrender";
202 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
203 name
= BLOCKLIST_PREF_BRANCH
"webrender.compositor";
205 case nsIGfxInfo::FEATURE_DX_NV12
:
206 name
= BLOCKLIST_PREF_BRANCH
"dx.nv12";
208 case nsIGfxInfo::FEATURE_DX_P010
:
209 name
= BLOCKLIST_PREF_BRANCH
"dx.p010";
211 case nsIGfxInfo::FEATURE_DX_P016
:
212 name
= BLOCKLIST_PREF_BRANCH
"dx.p016";
214 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
215 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
216 // We don't provide prefs for these features as these are
217 // not handling downloadable blocklist.
219 case nsIGfxInfo::FEATURE_GL_SWIZZLE
:
220 name
= BLOCKLIST_PREF_BRANCH
"gl.swizzle";
222 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
:
223 name
= BLOCKLIST_PREF_BRANCH
"webrender.scissored_cache_clears";
225 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
:
226 name
= BLOCKLIST_PREF_BRANCH
"webgl.allow-oop";
228 case nsIGfxInfo::FEATURE_THREADSAFE_GL
:
229 name
= BLOCKLIST_PREF_BRANCH
"gl.threadsafe";
231 case nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
:
232 name
= BLOCKLIST_PREF_BRANCH
"webrender.software";
235 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
242 // Returns the value of the pref for the relevant feature in aValue.
243 // If the pref doesn't exist, aValue is not touched, and returns false.
244 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
245 nsACString
& aFailureId
) {
246 const char* prefname
= GetPrefNameForFeature(aFeature
);
247 if (!prefname
) return false;
249 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
250 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
254 nsCString
failureprefname(prefname
);
255 failureprefname
+= ".failureid";
256 nsAutoCString failureValue
;
257 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
258 if (NS_SUCCEEDED(rv
)) {
259 aFailureId
= failureValue
.get();
261 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
267 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
268 const nsACString
& aFailureId
) {
269 const char* prefname
= GetPrefNameForFeature(aFeature
);
270 if (!prefname
) return;
271 if (XRE_IsParentProcess()) {
272 GfxInfoBase::sFeatureStatus
= nullptr;
275 Preferences::SetInt(prefname
, aValue
);
276 if (!aFailureId
.IsEmpty()) {
277 nsCString
failureprefname(prefname
);
278 failureprefname
+= ".failureid";
279 Preferences::SetCString(failureprefname
.get(), aFailureId
);
283 static void RemovePrefForFeature(int32_t aFeature
) {
284 const char* prefname
= GetPrefNameForFeature(aFeature
);
285 if (!prefname
) return;
287 if (XRE_IsParentProcess()) {
288 GfxInfoBase::sFeatureStatus
= nullptr;
290 Preferences::ClearUser(prefname
);
293 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
295 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
298 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
299 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
302 static void RemovePrefForDriverVersion() {
303 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
306 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
307 if (os
.EqualsLiteral("WINNT 6.1")) {
308 return OperatingSystem::Windows7
;
309 } else if (os
.EqualsLiteral("WINNT 6.2")) {
310 return OperatingSystem::Windows8
;
311 } else if (os
.EqualsLiteral("WINNT 6.3")) {
312 return OperatingSystem::Windows8_1
;
313 } else if (os
.EqualsLiteral("WINNT 10.0")) {
314 return OperatingSystem::Windows10
;
315 } else if (os
.EqualsLiteral("Linux")) {
316 return OperatingSystem::Linux
;
317 } else if (os
.EqualsLiteral("Darwin 9")) {
318 return OperatingSystem::OSX10_5
;
319 } else if (os
.EqualsLiteral("Darwin 10")) {
320 return OperatingSystem::OSX10_6
;
321 } else if (os
.EqualsLiteral("Darwin 11")) {
322 return OperatingSystem::OSX10_7
;
323 } else if (os
.EqualsLiteral("Darwin 12")) {
324 return OperatingSystem::OSX10_8
;
325 } else if (os
.EqualsLiteral("Darwin 13")) {
326 return OperatingSystem::OSX10_9
;
327 } else if (os
.EqualsLiteral("Darwin 14")) {
328 return OperatingSystem::OSX10_10
;
329 } else if (os
.EqualsLiteral("Darwin 15")) {
330 return OperatingSystem::OSX10_11
;
331 } else if (os
.EqualsLiteral("Darwin 16")) {
332 return OperatingSystem::OSX10_12
;
333 } else if (os
.EqualsLiteral("Darwin 17")) {
334 return OperatingSystem::OSX10_13
;
335 } else if (os
.EqualsLiteral("Darwin 18")) {
336 return OperatingSystem::OSX10_14
;
337 } else if (os
.EqualsLiteral("Darwin 19")) {
338 return OperatingSystem::OSX10_15
;
339 } else if (os
.EqualsLiteral("Darwin 20")) {
340 return OperatingSystem::OSX11_0
;
341 } else if (os
.EqualsLiteral("Android")) {
342 return OperatingSystem::Android
;
343 // For historical reasons, "All" in blocklist means "All Windows"
344 } else if (os
.EqualsLiteral("All")) {
345 return OperatingSystem::Windows
;
346 } else if (os
.EqualsLiteral("Darwin")) {
347 return OperatingSystem::OSX
;
350 return OperatingSystem::Unknown
;
353 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
354 nsTArray
<nsCString
>& devices
) {
355 if (devices
.Length() == 0) return nullptr;
357 // For each device, get its device ID, and return a freshly-allocated
358 // GfxDeviceFamily with the contents of that array.
359 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
361 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
362 // We make sure we don't add any "empty" device entries to the array, so
363 // we don't need to check if devices[i] is empty.
364 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
370 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
371 MOZ_ASSERT(!aFeature
.IsEmpty());
372 if (aFeature
.EqualsLiteral("DIRECT2D"))
373 return nsIGfxInfo::FEATURE_DIRECT2D
;
374 else if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS"))
375 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
376 else if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS"))
377 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
378 else if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
379 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
380 else if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS"))
381 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
382 else if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE"))
383 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
384 else if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
385 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
386 else if (aFeature
.EqualsLiteral("OPENGL_LAYERS"))
387 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
388 else if (aFeature
.EqualsLiteral("WEBGL_OPENGL"))
389 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
390 else if (aFeature
.EqualsLiteral("WEBGL_ANGLE"))
391 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
392 else if (aFeature
.EqualsLiteral("WEBGL_MSAA"))
393 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
394 else if (aFeature
.EqualsLiteral("STAGEFRIGHT"))
395 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
396 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
397 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
398 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
399 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
400 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264"))
401 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
402 else if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION"))
403 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
404 else if (aFeature
.EqualsLiteral("DX_INTEROP2"))
405 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
406 else if (aFeature
.EqualsLiteral("GPU_PROCESS"))
407 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
408 else if (aFeature
.EqualsLiteral("WEBGL2"))
409 return nsIGfxInfo::FEATURE_WEBGL2
;
410 else if (aFeature
.EqualsLiteral("ADVANCED_LAYERS"))
411 return nsIGfxInfo::FEATURE_ADVANCED_LAYERS
;
412 else if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX"))
413 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
414 else if (aFeature
.EqualsLiteral("WEBRENDER"))
415 return nsIGfxInfo::FEATURE_WEBRENDER
;
416 else if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR"))
417 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
418 else if (aFeature
.EqualsLiteral("DX_NV12"))
419 return nsIGfxInfo::FEATURE_DX_NV12
;
420 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
421 // in downloadable blocklist.
422 else if (aFeature
.EqualsLiteral("GL_SWIZZLE"))
423 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
424 else if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS"))
425 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
426 else if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS"))
427 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
428 else if (aFeature
.EqualsLiteral("THREADSAFE_GL"))
429 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
430 else if (aFeature
.EqualsLiteral("WEBRENDER_SOFTWARE"))
431 return nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
;
433 // If we don't recognize the feature, it may be new, and something
434 // this version doesn't understand. So, nothing to do. This is
435 // different from feature not being specified at all, in which case
436 // this method should not get called and we should continue with the
437 // "all features" blocklisting.
441 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
442 const nsAString
& aStatus
) {
443 if (aStatus
.EqualsLiteral("STATUS_OK"))
444 return nsIGfxInfo::FEATURE_STATUS_OK
;
445 else if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
446 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
447 else if (aStatus
.EqualsLiteral("BLOCKED_DEVICE"))
448 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
449 else if (aStatus
.EqualsLiteral("DISCOURAGED"))
450 return nsIGfxInfo::FEATURE_DISCOURAGED
;
451 else if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION"))
452 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
453 else if (aStatus
.EqualsLiteral("DENIED"))
454 return nsIGfxInfo::FEATURE_DENIED
;
455 else if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED"))
456 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
457 else if (aStatus
.EqualsLiteral("ALLOW_ALWAYS"))
458 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
460 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
461 // expecting the "mismatch" status showing up here.
463 return nsIGfxInfo::FEATURE_STATUS_OK
;
466 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
467 const nsAString
& op
) {
468 if (op
.EqualsLiteral("LESS_THAN"))
469 return DRIVER_LESS_THAN
;
470 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN"))
471 return DRIVER_BUILD_ID_LESS_THAN
;
472 else if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL"))
473 return DRIVER_LESS_THAN_OR_EQUAL
;
474 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
475 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
476 else if (op
.EqualsLiteral("GREATER_THAN"))
477 return DRIVER_GREATER_THAN
;
478 else if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
479 return DRIVER_GREATER_THAN_OR_EQUAL
;
480 else if (op
.EqualsLiteral("EQUAL"))
482 else if (op
.EqualsLiteral("NOT_EQUAL"))
483 return DRIVER_NOT_EQUAL
;
484 else if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE"))
485 return DRIVER_BETWEEN_EXCLUSIVE
;
486 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE"))
487 return DRIVER_BETWEEN_INCLUSIVE
;
488 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
489 return DRIVER_BETWEEN_INCLUSIVE_START
;
491 return DRIVER_COMPARISON_IGNORED
;
495 Deserialize Blocklist entries from string.
497 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
499 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
500 GfxDriverInfo
& aDriverInfo
) {
501 // If we get an application version to be zero, something is not working
502 // and we are not going to bother checking the blocklist versions.
503 // See TestGfxWidgets.cpp for how version comparison works.
504 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
505 static mozilla::Version
zeroV("0");
506 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
508 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
509 << "Invalid application version "
510 << GfxInfoBase::GetApplicationVersion().get();
513 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
515 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
516 nsTArray
<nsCString
> splitted
;
517 ParseString(keyValue
, ':', splitted
);
518 if (splitted
.Length() != 2) {
519 // If we don't recognize the input data, we do not want to proceed.
520 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
521 << "Unrecognized data " << nsCString(keyValue
).get();
524 const nsCString
& key
= splitted
[0];
525 const nsCString
& value
= splitted
[1];
526 NS_ConvertUTF8toUTF16
dataValue(value
);
528 if (value
.Length() == 0) {
529 // Safety check for empty values.
530 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
531 << "Empty value for " << key
.get();
535 if (key
.EqualsLiteral("blockID")) {
536 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
537 aDriverInfo
.mRuleId
= blockIdStr
.get();
538 } else if (key
.EqualsLiteral("os")) {
539 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
540 } else if (key
.EqualsLiteral("osversion")) {
541 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
542 } else if (key
.EqualsLiteral("desktopEnvironment")) {
543 aDriverInfo
.mDesktopEnvironment
= dataValue
;
544 } else if (key
.EqualsLiteral("windowProtocol")) {
545 aDriverInfo
.mWindowProtocol
= dataValue
;
546 } else if (key
.EqualsLiteral("vendor")) {
547 aDriverInfo
.mAdapterVendor
= dataValue
;
548 } else if (key
.EqualsLiteral("driverVendor")) {
549 aDriverInfo
.mDriverVendor
= dataValue
;
550 } else if (key
.EqualsLiteral("feature")) {
551 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
552 if (aDriverInfo
.mFeature
< 0) {
553 // If we don't recognize the feature, we do not want to proceed.
554 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
555 << "Unrecognized feature " << value
.get();
558 } else if (key
.EqualsLiteral("featureStatus")) {
559 aDriverInfo
.mFeatureStatus
=
560 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
561 } else if (key
.EqualsLiteral("driverVersion")) {
563 if (ParseDriverVersion(dataValue
, &version
))
564 aDriverInfo
.mDriverVersion
= version
;
565 } else if (key
.EqualsLiteral("driverVersionMax")) {
567 if (ParseDriverVersion(dataValue
, &version
))
568 aDriverInfo
.mDriverVersionMax
= version
;
569 } else if (key
.EqualsLiteral("driverVersionComparator")) {
570 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
571 } else if (key
.EqualsLiteral("model")) {
572 aDriverInfo
.mModel
= dataValue
;
573 } else if (key
.EqualsLiteral("product")) {
574 aDriverInfo
.mProduct
= dataValue
;
575 } else if (key
.EqualsLiteral("manufacturer")) {
576 aDriverInfo
.mManufacturer
= dataValue
;
577 } else if (key
.EqualsLiteral("hardware")) {
578 aDriverInfo
.mHardware
= dataValue
;
579 } else if (key
.EqualsLiteral("versionRange")) {
580 nsTArray
<nsCString
> versionRange
;
581 ParseString(value
, ',', versionRange
);
582 if (versionRange
.Length() != 2) {
583 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
584 << "Unrecognized versionRange " << value
.get();
587 const nsCString
& minValue
= versionRange
[0];
588 const nsCString
& maxValue
= versionRange
[1];
590 mozilla::Version
minV(minValue
.get());
591 mozilla::Version
maxV(maxValue
.get());
593 if (minV
> zeroV
&& !(appV
>= minV
)) {
594 // The version of the application is less than the minimal version
595 // this blocklist entry applies to, so we can just ignore it by
596 // returning false and letting the caller deal with it.
599 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
600 // The version of the application is more than the maximal version
601 // this blocklist entry applies to, so we can just ignore it by
602 // returning false and letting the caller deal with it.
605 } else if (key
.EqualsLiteral("devices")) {
606 nsTArray
<nsCString
> devices
;
607 ParseString(value
, ',', devices
);
608 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
610 // Get GfxDriverInfo to adopt the devices array we created.
611 aDriverInfo
.mDeleteDevices
= true;
612 aDriverInfo
.mDevices
= deviceIds
;
615 // We explicitly ignore unknown elements.
622 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
623 const char16_t
* aData
) {
624 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
625 nsTArray
<GfxDriverInfo
> driverInfo
;
626 NS_ConvertUTF16toUTF8
utf8Data(aData
);
628 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
630 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
631 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
632 // Probably some non-standard semantics of the copy/move operations?
633 *driverInfo
.AppendElement() = di
;
634 // Prevent di falling out of scope from destroying the devices.
635 di
.mDeleteDevices
= false;
637 driverInfo
.AppendElement();
641 EvaluateDownloadedBlocklist(driverInfo
);
647 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
649 GfxInfoBase::~GfxInfoBase() = default;
651 nsresult
GfxInfoBase::Init() {
652 InitGfxDriverInfoShutdownObserver();
654 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
656 os
->AddObserver(this, "blocklist-data-gfxItems", true);
662 void GfxInfoBase::GetData() {
663 if (mScreenPixels
!= INT64_MAX
) {
664 // Already initialized.
668 nsCOMPtr
<nsIScreenManager
> manager
=
669 do_GetService("@mozilla.org/gfx/screenmanager;1");
671 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
675 manager
->GetTotalScreenPixels(&mScreenPixels
);
679 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
681 // Ignore the gfx.blocklist.all pref on release and beta.
682 #if defined(RELEASE_OR_BETA)
683 int32_t blocklistAll
= 0;
685 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
687 if (blocklistAll
> 0) {
688 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
689 << "Forcing blocklisting all features";
690 *aStatus
= FEATURE_BLOCKED_DEVICE
;
691 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
693 } else if (blocklistAll
< 0) {
694 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
695 << "Ignoring any feature blocklisting.";
696 *aStatus
= FEATURE_STATUS_OK
;
700 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
704 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
705 // Use the cached data received from the parent process.
706 MOZ_ASSERT(sFeatureStatus
);
707 bool success
= false;
708 for (const auto& fs
: *sFeatureStatus
) {
709 if (fs
.feature() == aFeature
) {
710 aFailureId
= fs
.failureId();
711 *aStatus
= fs
.status();
716 return success
? NS_OK
: NS_ERROR_FAILURE
;
720 nsTArray
<GfxDriverInfo
> driverInfo
;
722 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
726 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
727 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
728 if (!sFeatureStatus
) {
729 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
730 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
732 nsAutoCString failureId
;
733 GetFeatureStatus(i
, failureId
, &status
);
734 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
735 gfxFeatureStatus
.feature() = i
;
736 gfxFeatureStatus
.status() = status
;
737 gfxFeatureStatus
.failureId() = failureId
;
738 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
742 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
743 for (const auto& status
: *sFeatureStatus
) {
744 gfx::GfxInfoFeatureStatus copy
= status
;
745 features
.AppendElement(copy
);
750 inline bool MatchingAllowStatus(int32_t aStatus
) {
752 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
753 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
760 // Matching OS go somewhat beyond the simple equality check because of the
761 // "All Windows" and "All OS X" variations.
763 // aBlockedOS is describing the system(s) we are trying to block.
764 // aSystemOS is describing the system we are running on.
766 // aSystemOS should not be "Windows" or "OSX" - it should be set to
767 // a particular version instead.
768 // However, it is valid for aBlockedOS to be one of those generic values,
769 // as we could be blocking all of the versions.
770 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
771 OperatingSystem aSystemOS
,
772 uint32_t aSystemOSBuild
) {
773 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
774 aSystemOS
!= OperatingSystem::OSX
);
776 // If the block entry OS is unknown, it doesn't match
777 if (aBlockedOS
== OperatingSystem::Unknown
) {
782 if (aBlockedOS
== OperatingSystem::Windows
) {
783 // We do want even "unknown" aSystemOS to fall under "all windows"
787 constexpr uint32_t kMinWin10BuildNumber
= 18362;
788 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
789 aSystemOS
== OperatingSystem::Windows10
) {
790 // For allowlist purposes, we sometimes want to restrict to only recent
791 // versions of Windows 10. This is a bit of a kludge but easier than adding
792 // complicated blocklist infrastructure for build ID comparisons like driver
794 return aSystemOSBuild
>= kMinWin10BuildNumber
;
797 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
798 if (aSystemOS
== OperatingSystem::Windows10
) {
799 return aSystemOSBuild
< kMinWin10BuildNumber
;
806 #if defined(XP_MACOSX)
807 if (aBlockedOS
== OperatingSystem::OSX
) {
808 // We do want even "unknown" aSystemOS to fall under "all OS X"
813 return aSystemOS
== aBlockedOS
;
816 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
817 switch (aBatteryStatus
) {
818 case BatteryStatus::All
:
820 case BatteryStatus::None
:
822 case BatteryStatus::Present
:
826 MOZ_ASSERT_UNREACHABLE("bad battery status");
830 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
831 int64_t aScreenPixels
) {
832 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
833 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
835 switch (aScreenStatus
) {
836 case ScreenSizeStatus::All
:
838 case ScreenSizeStatus::Small
:
839 return aScreenPixels
<= kMaxSmallPixels
;
840 case ScreenSizeStatus::SmallAndMedium
:
841 return aScreenPixels
<= kMaxMediumPixels
;
842 case ScreenSizeStatus::Medium
:
843 return aScreenPixels
> kMaxSmallPixels
&&
844 aScreenPixels
<= kMaxMediumPixels
;
845 case ScreenSizeStatus::MediumAndLarge
:
846 return aScreenPixels
> kMaxSmallPixels
;
847 case ScreenSizeStatus::Large
:
848 return aScreenPixels
> kMaxMediumPixels
;
851 MOZ_ASSERT_UNREACHABLE("bad screen status");
855 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
856 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
857 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
859 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
861 // Some properties are not available on all platforms.
862 nsAutoString desktopEnvironment
;
863 nsresult rv
= GetDesktopEnvironment(desktopEnvironment
);
864 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
868 nsAutoString windowProtocol
;
869 rv
= GetWindowProtocol(windowProtocol
);
870 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
874 bool hasBattery
= false;
875 rv
= GetHasBattery(&hasBattery
);
876 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
880 uint32_t osBuild
= OperatingSystemBuild();
882 // Get the adapters once then reuse below
883 nsAutoString adapterVendorID
[2];
884 nsAutoString adapterDeviceID
[2];
885 nsAutoString adapterDriverVendor
[2];
886 nsAutoString adapterDriverVersionString
[2];
887 bool adapterInfoFailed
[2];
889 adapterInfoFailed
[0] =
890 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
891 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
892 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
893 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
894 adapterInfoFailed
[1] =
895 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
896 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
897 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
898 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
899 // No point in going on if we don't have adapter info
900 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
904 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
905 uint64_t driverVersion
[2] = {0, 0};
906 if (!adapterInfoFailed
[0]) {
907 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
909 if (!adapterInfoFailed
[1]) {
910 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
915 for (; i
< info
.Length(); i
++) {
916 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
917 // blocklisting. Only consider entries for our search mode.
918 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
922 // If we don't have the info for this GPU, no need to check further.
923 // It is unclear that we would ever have a mixture of 1st and 2nd
924 // GPU, but leaving the code in for that possibility for now.
925 // (Actually, currently mGpu2 will never be true, so this can
926 // be optimized out.)
927 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
928 if (adapterInfoFailed
[infoIndex
]) {
932 // Do the operating system check first, no point in getting the driver
933 // info if we won't need to use it.
934 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
938 if (info
[i
].mOperatingSystemVersion
&&
939 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
943 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
947 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
951 if (!DoesDesktopEnvironmentMatch(info
[i
].mDesktopEnvironment
,
952 desktopEnvironment
)) {
956 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
960 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
964 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
965 adapterDriverVendor
[infoIndex
])) {
969 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
970 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
971 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
976 // Failed to search, allowlist should not match, blocklist should match
977 // for safety reasons
987 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
990 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
993 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
996 if (!info
[i
].mManufacturer
.IsEmpty() &&
997 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1001 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
1002 switch (info
[i
].mComparisonOp
) {
1003 case DRIVER_LESS_THAN
:
1004 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1006 case DRIVER_BUILD_ID_LESS_THAN
:
1007 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1009 case DRIVER_LESS_THAN_OR_EQUAL
:
1010 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1012 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1013 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1015 case DRIVER_GREATER_THAN
:
1016 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1018 case DRIVER_GREATER_THAN_OR_EQUAL
:
1019 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1022 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1024 case DRIVER_NOT_EQUAL
:
1025 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1027 case DRIVER_BETWEEN_EXCLUSIVE
:
1028 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1029 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1031 case DRIVER_BETWEEN_INCLUSIVE
:
1032 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1033 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1035 case DRIVER_BETWEEN_INCLUSIVE_START
:
1036 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1037 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1039 case DRIVER_COMPARISON_IGNORED
:
1040 // We don't have a comparison op, so we match everything.
1044 NS_WARNING("Bogus op in GfxDriverInfo");
1048 // We don't care what driver version it was. We only check OS version and if
1049 // the device matches.
1053 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1054 if ((info
[i
].mFeature
== GfxDriverInfo::allFeatures
&&
1055 aFeature
!= nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
) ||
1056 info
[i
].mFeature
== aFeature
) {
1057 status
= info
[i
].mFeatureStatus
;
1058 if (!info
[i
].mRuleId
.IsEmpty()) {
1059 aFailureId
= info
[i
].mRuleId
.get();
1061 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1069 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1070 // as either the primary or secondary adapter. D2D is also blocked when the
1071 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1072 // If the primary GPU already matched something in the blocklist then we
1073 // ignore this special rule. See bug 1008759.
1074 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1075 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1076 if (!adapterInfoFailed
[1]) {
1077 nsAString
& nvVendorID
=
1078 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1079 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1080 if (nvVendorID
.Equals(adapterVendorID
[1],
1081 nsCaseInsensitiveStringComparator
) &&
1082 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1083 nsCaseInsensitiveStringComparator
)) {
1084 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1085 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1090 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1091 // back to the Windows handler, so we must handle this here.
1092 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1093 if (info
[i
].mSuggestedVersion
) {
1094 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1095 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1096 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1097 aSuggestedVersion
.AppendPrintf(
1098 "%lld.%lld.%lld.%lld",
1099 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1100 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1101 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1102 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1110 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1111 MOZ_ASSERT(!sFeatureStatus
);
1112 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1115 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1116 const nsAString
& aBlocklistDesktop
, const nsAString
& aDesktopEnv
) {
1117 return aBlocklistDesktop
.Equals(aDesktopEnv
,
1118 nsCaseInsensitiveStringComparator
) ||
1119 aBlocklistDesktop
.Equals(
1120 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All
),
1121 nsCaseInsensitiveStringComparator
);
1124 bool GfxInfoBase::DoesWindowProtocolMatch(
1125 const nsAString
& aBlocklistWindowProtocol
,
1126 const nsAString
& aWindowProtocol
) {
1127 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1128 nsCaseInsensitiveStringComparator
) ||
1129 aBlocklistWindowProtocol
.Equals(
1130 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1131 nsCaseInsensitiveStringComparator
);
1134 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1135 const nsAString
& aAdapterVendor
) {
1136 return aBlocklistVendor
.Equals(aAdapterVendor
,
1137 nsCaseInsensitiveStringComparator
) ||
1138 aBlocklistVendor
.Equals(
1139 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1140 nsCaseInsensitiveStringComparator
);
1143 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1144 const nsAString
& aDriverVendor
) {
1145 return aBlocklistVendor
.Equals(aDriverVendor
,
1146 nsCaseInsensitiveStringComparator
) ||
1147 aBlocklistVendor
.Equals(
1148 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1149 nsCaseInsensitiveStringComparator
);
1152 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1153 return aFeature
== nsIGfxInfo::FEATURE_WEBRENDER
||
1154 aFeature
== nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
;
1157 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1158 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1159 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1160 OperatingSystem
* aOS
/* = nullptr */) {
1161 if (aFeature
<= 0) {
1162 gfxWarning() << "Invalid feature <= 0";
1166 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1167 // Terminate now with the status determined by the derived type (OS-specific
1172 if (sShutdownOccurred
) {
1173 // This is futile; we've already commenced shutdown and our blocklists have
1174 // been deleted. We may want to look into resurrecting the blocklist instead
1175 // but for now, just don't even go there.
1179 // Ensure any additional initialization required is complete.
1182 // If an operating system was provided by the derived GetFeatureStatusImpl,
1183 // grab it here. Otherwise, the OS is unknown.
1184 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1186 nsAutoString adapterVendorID
;
1187 nsAutoString adapterDeviceID
;
1188 nsAutoString adapterDriverVersionString
;
1189 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1190 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1191 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1192 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1193 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1197 // Check if the device is blocked from the downloaded blocklist. If not, check
1198 // the static list after that. This order is used so that we can later escape
1199 // out of static blocks (i.e. if we were wrong or something was patched, we
1200 // can back out our static block without doing a release).
1202 if (aDriverInfo
.Length()) {
1204 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1205 aFailureId
, os
, /* aForAllowing */ false);
1208 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1210 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1211 aFeature
, aFailureId
, os
,
1212 /* aForAllowing */ false);
1215 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1216 if (IsFeatureAllowlisted(aFeature
)) {
1217 // This feature is actually using the allowlist; that means after we pass
1218 // the blocklist to prevent us explicitly from getting the feature, we now
1219 // need to check the allowlist to ensure we are allowed to get it in the
1221 if (aDriverInfo
.Length()) {
1222 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1223 aFeature
, aFailureId
, os
,
1224 /* aForAllowing */ true);
1226 status
= FindBlocklistedDeviceInList(
1227 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1228 /* aForAllowing */ true);
1231 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1232 status
= nsIGfxInfo::FEATURE_DENIED
;
1235 // It's now done being processed. It's safe to set the status to
1237 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1246 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1247 nsAString
& aVersion
) {
1249 if (GetPrefValueForDriverVersion(version
)) {
1250 aVersion
= NS_ConvertASCIItoUTF16(version
);
1255 nsCString discardFailureId
;
1256 nsTArray
<GfxDriverInfo
> driverInfo
;
1257 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1261 void GfxInfoBase::EvaluateDownloadedBlocklist(
1262 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1263 int32_t features
[] = {nsIGfxInfo::FEATURE_DIRECT2D
,
1264 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
,
1265 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
,
1266 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
,
1267 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
,
1268 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
,
1269 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
,
1270 nsIGfxInfo::FEATURE_OPENGL_LAYERS
,
1271 nsIGfxInfo::FEATURE_WEBGL_OPENGL
,
1272 nsIGfxInfo::FEATURE_WEBGL_ANGLE
,
1273 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
,
1274 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
,
1275 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
,
1276 nsIGfxInfo::FEATURE_STAGEFRIGHT
,
1277 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
,
1278 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
,
1279 nsIGfxInfo::FEATURE_VP8_HW_DECODE
,
1280 nsIGfxInfo::FEATURE_VP9_HW_DECODE
,
1281 nsIGfxInfo::FEATURE_DX_INTEROP2
,
1282 nsIGfxInfo::FEATURE_GPU_PROCESS
,
1283 nsIGfxInfo::FEATURE_WEBGL2
,
1284 nsIGfxInfo::FEATURE_ADVANCED_LAYERS
,
1285 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
1286 nsIGfxInfo::FEATURE_WEBRENDER
,
1287 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
,
1288 nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
,
1289 nsIGfxInfo::FEATURE_DX_NV12
,
1290 nsIGfxInfo::FEATURE_DX_P010
,
1291 nsIGfxInfo::FEATURE_DX_P016
,
1292 nsIGfxInfo::FEATURE_GL_SWIZZLE
,
1293 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
,
1296 // For every feature we know about, we evaluate whether this blocklist has a
1297 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1298 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1299 // anywhere permanent.
1301 while (features
[i
]) {
1303 nsCString failureId
;
1304 nsAutoString suggestedVersion
;
1305 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1306 features
[i
], &status
, suggestedVersion
, aDriverInfo
, failureId
))) {
1309 case nsIGfxInfo::FEATURE_STATUS_OK
:
1310 RemovePrefForFeature(features
[i
]);
1313 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1314 if (!suggestedVersion
.IsEmpty()) {
1315 SetPrefValueForDriverVersion(suggestedVersion
);
1317 RemovePrefForDriverVersion();
1321 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1322 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1323 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1324 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1325 SetPrefValueForFeature(features
[i
], status
, failureId
);
1334 NS_IMETHODIMP_(void)
1335 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1336 // gfxCriticalError has a mutex lock of its own, so we may not actually
1337 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1338 // will not return the copy of the logs unless it can get the same lock
1339 // that gfxCriticalError uses. Still, that is so much of an implementation
1340 // detail that it's nicer to just add an extra lock here and in
1342 MutexAutoLock
lock(mMutex
);
1344 // By default, gfxCriticalError asserts; make it not assert in this case.
1345 gfxCriticalError(CriticalLog::DefaultOptions(false))
1346 << "(LF) " << failure
.BeginReading();
1349 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1350 nsTArray
<nsCString
>& failures
) {
1351 MutexAutoLock
lock(mMutex
);
1353 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1354 if (!logForwarder
) {
1355 return NS_ERROR_UNEXPECTED
;
1358 // There are two string copies in this method, starting with this one. We are
1359 // assuming this is not a big deal, as the size of the array should be small
1360 // and the strings in it should be small as well (the error messages in the
1361 // code.) The second copy happens with the AppendElement() calls.
1362 // Technically, we don't need the mutex lock after the StringVectorCopy()
1364 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1365 LoggingRecord::const_iterator it
;
1366 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1367 failures
.AppendElement(
1368 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1369 indices
.AppendElement(Get
<0>(*it
));
1375 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1377 static void InitCollectors() {
1378 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1381 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1382 JS::MutableHandle
<JS::Value
> aResult
) {
1384 InfoObject
obj(aCx
);
1386 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1387 (*sCollectors
)[i
]->GetInfo(obj
);
1390 // Some example property definitions
1391 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1392 // obj.DefineProperty("renderer", mRendererIDsString);
1393 // obj.DefineProperty("five", 5);
1396 return NS_ERROR_FAILURE
;
1399 aResult
.setObject(*obj
.mObj
);
1403 nsAutoCString gBaseAppVersion
;
1405 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1406 static bool versionInitialized
= false;
1407 if (!versionInitialized
) {
1408 // If we fail to get the version, we will not try again.
1409 versionInitialized
= true;
1411 // Get the version from xpcom/system/nsIXULAppInfo.idl
1412 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1414 app
->GetVersion(gBaseAppVersion
);
1417 return gBaseAppVersion
;
1420 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1422 sCollectors
->AppendElement(collector
);
1425 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1427 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1428 if ((*sCollectors
)[i
] == collector
) {
1429 sCollectors
->RemoveElementAt(i
);
1433 if (sCollectors
->IsEmpty()) {
1435 sCollectors
= nullptr;
1439 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
, JS::HandleObject aOutArray
) {
1440 // If we have no platform specific implementation for detecting monitors, we
1441 // can just get the screen size from gfxPlatform as the best guess.
1442 if (!gfxPlatform::Initialized()) {
1446 // If the screen size is empty, we are probably in xpcshell.
1447 gfx::IntSize screenSize
= gfxPlatform::GetPlatform()->GetScreenSize();
1449 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1451 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1452 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1454 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1455 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1457 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1458 JS_SetElement(aCx
, aOutArray
, 0, element
);
1464 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandleValue aResult
) {
1465 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1467 nsresult rv
= FindMonitors(aCx
, array
);
1468 if (NS_FAILED(rv
)) {
1472 aResult
.setObject(*array
);
1476 static inline bool SetJSPropertyString(JSContext
* aCx
,
1477 JS::Handle
<JSObject
*> aObj
,
1478 const char* aProp
, const char* aString
) {
1479 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1484 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1485 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1488 template <typename T
>
1489 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1492 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1495 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1498 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1499 JS::MutableHandle
<JS::Value
> aOut
) {
1500 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1502 return NS_ERROR_OUT_OF_MEMORY
;
1504 aOut
.setObject(*obj
);
1506 layers::LayersBackend backend
=
1507 gfxPlatform::Initialized()
1508 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1509 : layers::LayersBackend::LAYERS_NONE
;
1510 const char* backendName
= layers::GetLayersBackendName(backend
);
1511 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1513 // If graphics isn't initialized yet, just stop now.
1514 if (!gfxPlatform::Initialized()) {
1518 DescribeFeatures(aCx
, obj
);
1522 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1523 JS::MutableHandle
<JS::Value
> aOut
) {
1524 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1525 if (!containerObj
) {
1526 return NS_ERROR_OUT_OF_MEMORY
;
1528 aOut
.setObject(*containerObj
);
1530 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1531 if (!featureArray
) {
1532 return NS_ERROR_OUT_OF_MEMORY
;
1535 // Collect features.
1536 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1537 FeatureState
& aFeature
) -> void {
1538 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1542 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1543 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1544 !SetJSPropertyString(aCx
, obj
, "status",
1545 FeatureStatusToString(aFeature
.GetValue()))) {
1549 JS::Rooted
<JS::Value
> log(aCx
);
1550 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1553 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1557 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1562 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1563 if (!fallbackArray
) {
1564 return NS_ERROR_OUT_OF_MEMORY
;
1567 // Collect fallbacks.
1568 gfxConfig::ForEachFallback(
1569 [&](const char* aName
, const char* aMessage
) -> void {
1570 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1575 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1576 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1580 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1585 JS::Rooted
<JS::Value
> val(aCx
);
1587 val
= JS::ObjectValue(*featureArray
);
1588 JS_SetProperty(aCx
, containerObj
, "features", val
);
1590 val
= JS::ObjectValue(*fallbackArray
);
1591 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1596 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1597 const FeatureState
& aFeature
,
1598 JS::MutableHandle
<JS::Value
> aOut
) {
1599 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1603 aOut
.setObject(*log
);
1605 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1606 const char* aMessage
,
1607 const nsCString
& aFailureId
) -> void {
1608 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1613 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1614 !SetJSPropertyString(aCx
, obj
, "status",
1615 FeatureStatusToString(aStatus
)) ||
1616 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1620 if (!AppendJSElement(aCx
, log
, obj
)) {
1628 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1629 JS::Rooted
<JSObject
*> obj(aCx
);
1631 gfx::FeatureState
& hwCompositing
=
1632 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1633 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1635 gfx::FeatureState
& gpuProcess
=
1636 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1637 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1639 gfx::FeatureState
& wrQualified
=
1640 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_QUALIFIED
);
1641 InitFeatureObject(aCx
, aObj
, "wrQualified", wrQualified
, &obj
);
1643 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1644 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1646 gfx::FeatureState
& wrCompositor
=
1647 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1648 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1650 gfx::FeatureState
& wrSoftware
=
1651 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_SOFTWARE
);
1652 InitFeatureObject(aCx
, aObj
, "wrSoftware", wrSoftware
, &obj
);
1654 gfx::FeatureState
& openglCompositing
=
1655 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1656 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1658 gfx::FeatureState
& omtp
=
1659 gfxConfig::GetFeature(gfx::Feature::OMTP
);
1660 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1662 // Only include AL if the platform attempted to use it.
1663 gfx::FeatureState
& advancedLayers
=
1664 gfxConfig::GetFeature(gfx::Feature::ADVANCED_LAYERS
);
1665 if (advancedLayers
.GetValue() != FeatureStatus::Unused
) {
1666 InitFeatureObject(aCx
, aObj
, "advancedLayers", advancedLayers
, &obj
);
1668 if (gfxConfig::UseFallback(Fallback::NO_CONSTANT_BUFFER_OFFSETTING
)) {
1669 JS::Rooted
<JS::Value
> trueVal(aCx
, JS::BooleanValue(true));
1670 JS_SetProperty(aCx
, obj
, "noConstantBufferOffsetting", trueVal
);
1675 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1676 JS::Handle
<JSObject
*> aContainer
,
1678 mozilla::gfx::FeatureState
& aFeatureState
,
1679 JS::MutableHandle
<JSObject
*> aOutObj
) {
1680 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1686 auto value
= aFeatureState
.GetValue();
1688 case FeatureStatus::Blocklisted
:
1689 case FeatureStatus::Disabled
:
1690 case FeatureStatus::Unavailable
:
1691 case FeatureStatus::UnavailableNoAngle
:
1692 case FeatureStatus::Blocked
:
1693 status
.AppendPrintf("%s:%s", FeatureStatusToString(value
),
1694 aFeatureState
.GetFailureId().get());
1697 status
.Append(FeatureStatusToString(value
));
1701 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1702 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1703 JS_SetProperty(aCx
, obj
, "status", val
);
1705 // Add the feature object to the container.
1707 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1708 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1715 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1716 JS::MutableHandle
<JS::Value
> aOut
) {
1717 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1719 return NS_ERROR_OUT_OF_MEMORY
;
1721 aOut
.setObject(*array
);
1723 DriverCrashGuard::ForEachActiveCrashGuard(
1724 [&](const char* aName
, const char* aPrefName
) -> void {
1725 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1729 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1732 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1735 if (!AppendJSElement(aCx
, array
, obj
)) {
1744 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled
) {
1745 *aWebRenderEnabled
= gfxVars::UseWebRender();
1750 GfxInfoBase::GetUsesTiling(bool* aUsesTiling
) {
1751 *aUsesTiling
= gfxPlatform::GetPlatform()->UsesTiling();
1756 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling
) {
1757 *aUsesTiling
= gfxPlatform::GetPlatform()->ContentUsesTiling();
1762 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled
) {
1763 *aOffMainThreadPaintEnabled
= gfxConfig::IsEnabled(gfx::Feature::OMTP
);
1768 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1769 int32_t* aOffMainThreadPaintWorkerCount
) {
1770 if (gfxConfig::IsEnabled(gfx::Feature::OMTP
)) {
1771 *aOffMainThreadPaintWorkerCount
=
1772 layers::PaintThread::CalculatePaintWorkerCount();
1774 *aOffMainThreadPaintWorkerCount
= 0;
1780 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1781 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1786 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1787 *aIsHeadless
= gfxPlatform::IsHeadless();
1792 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1793 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1797 case BackendType::DIRECT2D1_1
: {
1798 outStr
.AppendPrintf("Direct2D 1.1");
1801 case BackendType::SKIA
: {
1802 outStr
.AppendPrintf("Skia");
1805 case BackendType::CAIRO
: {
1806 outStr
.AppendPrintf("Cairo");
1810 return NS_ERROR_FAILURE
;
1813 aContentBackend
.Assign(outStr
);
1818 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1819 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1821 // Not supported in content processes.
1822 return NS_ERROR_FAILURE
;
1825 *aOutValue
= !!gpu
->GetGPUChild();
1830 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1831 gfxPlatform::GetPlatform();
1833 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1835 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1836 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1838 gpm
->LaunchGPUProcess();
1839 gpm
->EnsureGPUReady();
1841 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1849 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1850 GfxInfoBase::AddCollector(this);
1853 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1854 GfxInfoBase::RemoveCollector(this);