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_D3D11_KEYED_MUTEX
:
194 name
= BLOCKLIST_PREF_BRANCH
"d3d11.keyed.mutex";
196 case nsIGfxInfo::FEATURE_WEBRENDER
:
197 name
= BLOCKLIST_PREF_BRANCH
"webrender";
199 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
:
200 name
= BLOCKLIST_PREF_BRANCH
"webrender.compositor";
202 case nsIGfxInfo::FEATURE_DX_NV12
:
203 name
= BLOCKLIST_PREF_BRANCH
"dx.nv12";
205 case nsIGfxInfo::FEATURE_DX_P010
:
206 name
= BLOCKLIST_PREF_BRANCH
"dx.p010";
208 case nsIGfxInfo::FEATURE_DX_P016
:
209 name
= BLOCKLIST_PREF_BRANCH
"dx.p016";
211 case nsIGfxInfo::FEATURE_VP8_HW_DECODE
:
212 case nsIGfxInfo::FEATURE_VP9_HW_DECODE
:
213 // We don't provide prefs for these features as these are
214 // not handling downloadable blocklist.
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_SOFTWARE
:
229 name
= BLOCKLIST_PREF_BRANCH
"webrender.software";
231 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS
:
232 name
= BLOCKLIST_PREF_BRANCH
"webrender.optimized-shaders";
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("D3D11_KEYED_MUTEX"))
411 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
412 else if (aFeature
.EqualsLiteral("WEBRENDER"))
413 return nsIGfxInfo::FEATURE_WEBRENDER
;
414 else if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR"))
415 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
416 else if (aFeature
.EqualsLiteral("DX_NV12"))
417 return nsIGfxInfo::FEATURE_DX_NV12
;
418 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
419 // in downloadable blocklist.
420 else if (aFeature
.EqualsLiteral("GL_SWIZZLE"))
421 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
422 else if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS"))
423 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
424 else if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS"))
425 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
426 else if (aFeature
.EqualsLiteral("THREADSAFE_GL"))
427 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
428 else if (aFeature
.EqualsLiteral("WEBRENDER_SOFTWARE"))
429 return nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
;
431 // If we don't recognize the feature, it may be new, and something
432 // this version doesn't understand. So, nothing to do. This is
433 // different from feature not being specified at all, in which case
434 // this method should not get called and we should continue with the
435 // "all features" blocklisting.
439 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
440 const nsAString
& aStatus
) {
441 if (aStatus
.EqualsLiteral("STATUS_OK"))
442 return nsIGfxInfo::FEATURE_STATUS_OK
;
443 else if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
444 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
445 else if (aStatus
.EqualsLiteral("BLOCKED_DEVICE"))
446 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
447 else if (aStatus
.EqualsLiteral("DISCOURAGED"))
448 return nsIGfxInfo::FEATURE_DISCOURAGED
;
449 else if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION"))
450 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
451 else if (aStatus
.EqualsLiteral("DENIED"))
452 return nsIGfxInfo::FEATURE_DENIED
;
453 else if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED"))
454 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
455 else if (aStatus
.EqualsLiteral("ALLOW_ALWAYS"))
456 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
458 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
459 // expecting the "mismatch" status showing up here.
461 return nsIGfxInfo::FEATURE_STATUS_OK
;
464 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
465 const nsAString
& op
) {
466 if (op
.EqualsLiteral("LESS_THAN"))
467 return DRIVER_LESS_THAN
;
468 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN"))
469 return DRIVER_BUILD_ID_LESS_THAN
;
470 else if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL"))
471 return DRIVER_LESS_THAN_OR_EQUAL
;
472 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
473 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
474 else if (op
.EqualsLiteral("GREATER_THAN"))
475 return DRIVER_GREATER_THAN
;
476 else if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
477 return DRIVER_GREATER_THAN_OR_EQUAL
;
478 else if (op
.EqualsLiteral("EQUAL"))
480 else if (op
.EqualsLiteral("NOT_EQUAL"))
481 return DRIVER_NOT_EQUAL
;
482 else if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE"))
483 return DRIVER_BETWEEN_EXCLUSIVE
;
484 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE"))
485 return DRIVER_BETWEEN_INCLUSIVE
;
486 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
487 return DRIVER_BETWEEN_INCLUSIVE_START
;
489 return DRIVER_COMPARISON_IGNORED
;
493 Deserialize Blocklist entries from string.
495 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
497 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
498 GfxDriverInfo
& aDriverInfo
) {
499 // If we get an application version to be zero, something is not working
500 // and we are not going to bother checking the blocklist versions.
501 // See TestGfxWidgets.cpp for how version comparison works.
502 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
503 static mozilla::Version
zeroV("0");
504 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
506 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
507 << "Invalid application version "
508 << GfxInfoBase::GetApplicationVersion().get();
511 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
513 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
514 nsTArray
<nsCString
> splitted
;
515 ParseString(keyValue
, ':', splitted
);
516 if (splitted
.Length() != 2) {
517 // If we don't recognize the input data, we do not want to proceed.
518 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
519 << "Unrecognized data " << nsCString(keyValue
).get();
522 const nsCString
& key
= splitted
[0];
523 const nsCString
& value
= splitted
[1];
524 NS_ConvertUTF8toUTF16
dataValue(value
);
526 if (value
.Length() == 0) {
527 // Safety check for empty values.
528 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
529 << "Empty value for " << key
.get();
533 if (key
.EqualsLiteral("blockID")) {
534 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
535 aDriverInfo
.mRuleId
= blockIdStr
.get();
536 } else if (key
.EqualsLiteral("os")) {
537 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
538 } else if (key
.EqualsLiteral("osversion")) {
539 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
540 } else if (key
.EqualsLiteral("desktopEnvironment")) {
541 aDriverInfo
.mDesktopEnvironment
= dataValue
;
542 } else if (key
.EqualsLiteral("windowProtocol")) {
543 aDriverInfo
.mWindowProtocol
= dataValue
;
544 } else if (key
.EqualsLiteral("vendor")) {
545 aDriverInfo
.mAdapterVendor
= dataValue
;
546 } else if (key
.EqualsLiteral("driverVendor")) {
547 aDriverInfo
.mDriverVendor
= dataValue
;
548 } else if (key
.EqualsLiteral("feature")) {
549 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
550 if (aDriverInfo
.mFeature
< 0) {
551 // If we don't recognize the feature, we do not want to proceed.
552 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
553 << "Unrecognized feature " << value
.get();
556 } else if (key
.EqualsLiteral("featureStatus")) {
557 aDriverInfo
.mFeatureStatus
=
558 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
559 } else if (key
.EqualsLiteral("driverVersion")) {
561 if (ParseDriverVersion(dataValue
, &version
))
562 aDriverInfo
.mDriverVersion
= version
;
563 } else if (key
.EqualsLiteral("driverVersionMax")) {
565 if (ParseDriverVersion(dataValue
, &version
))
566 aDriverInfo
.mDriverVersionMax
= version
;
567 } else if (key
.EqualsLiteral("driverVersionComparator")) {
568 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
569 } else if (key
.EqualsLiteral("model")) {
570 aDriverInfo
.mModel
= dataValue
;
571 } else if (key
.EqualsLiteral("product")) {
572 aDriverInfo
.mProduct
= dataValue
;
573 } else if (key
.EqualsLiteral("manufacturer")) {
574 aDriverInfo
.mManufacturer
= dataValue
;
575 } else if (key
.EqualsLiteral("hardware")) {
576 aDriverInfo
.mHardware
= dataValue
;
577 } else if (key
.EqualsLiteral("versionRange")) {
578 nsTArray
<nsCString
> versionRange
;
579 ParseString(value
, ',', versionRange
);
580 if (versionRange
.Length() != 2) {
581 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
582 << "Unrecognized versionRange " << value
.get();
585 const nsCString
& minValue
= versionRange
[0];
586 const nsCString
& maxValue
= versionRange
[1];
588 mozilla::Version
minV(minValue
.get());
589 mozilla::Version
maxV(maxValue
.get());
591 if (minV
> zeroV
&& !(appV
>= minV
)) {
592 // The version of the application is less than the minimal version
593 // this blocklist entry applies to, so we can just ignore it by
594 // returning false and letting the caller deal with it.
597 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
598 // The version of the application is more than the maximal version
599 // this blocklist entry applies to, so we can just ignore it by
600 // returning false and letting the caller deal with it.
603 } else if (key
.EqualsLiteral("devices")) {
604 nsTArray
<nsCString
> devices
;
605 ParseString(value
, ',', devices
);
606 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
608 // Get GfxDriverInfo to adopt the devices array we created.
609 aDriverInfo
.mDeleteDevices
= true;
610 aDriverInfo
.mDevices
= deviceIds
;
613 // We explicitly ignore unknown elements.
620 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
621 const char16_t
* aData
) {
622 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
623 nsTArray
<GfxDriverInfo
> driverInfo
;
624 NS_ConvertUTF16toUTF8
utf8Data(aData
);
626 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
628 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
629 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
630 // Probably some non-standard semantics of the copy/move operations?
631 *driverInfo
.AppendElement() = di
;
632 // Prevent di falling out of scope from destroying the devices.
633 di
.mDeleteDevices
= false;
635 driverInfo
.AppendElement();
639 EvaluateDownloadedBlocklist(driverInfo
);
645 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
647 GfxInfoBase::~GfxInfoBase() = default;
649 nsresult
GfxInfoBase::Init() {
650 InitGfxDriverInfoShutdownObserver();
652 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
654 os
->AddObserver(this, "blocklist-data-gfxItems", true);
660 void GfxInfoBase::GetData() {
661 if (mScreenPixels
!= INT64_MAX
) {
662 // Already initialized.
666 nsCOMPtr
<nsIScreenManager
> manager
=
667 do_GetService("@mozilla.org/gfx/screenmanager;1");
669 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
673 manager
->GetTotalScreenPixels(&mScreenPixels
);
677 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
679 // Ignore the gfx.blocklist.all pref on release and beta.
680 #if defined(RELEASE_OR_BETA)
681 int32_t blocklistAll
= 0;
683 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
685 if (blocklistAll
> 0) {
686 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
687 << "Forcing blocklisting all features";
688 *aStatus
= FEATURE_BLOCKED_DEVICE
;
689 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
691 } else if (blocklistAll
< 0) {
692 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
693 << "Ignoring any feature blocklisting.";
694 *aStatus
= FEATURE_STATUS_OK
;
698 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
702 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
703 // Use the cached data received from the parent process.
704 MOZ_ASSERT(sFeatureStatus
);
705 bool success
= false;
706 for (const auto& fs
: *sFeatureStatus
) {
707 if (fs
.feature() == aFeature
) {
708 aFailureId
= fs
.failureId();
709 *aStatus
= fs
.status();
714 return success
? NS_OK
: NS_ERROR_FAILURE
;
718 nsTArray
<GfxDriverInfo
> driverInfo
;
720 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
724 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
725 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
726 if (!sFeatureStatus
) {
727 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
728 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
730 nsAutoCString failureId
;
731 GetFeatureStatus(i
, failureId
, &status
);
732 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
733 gfxFeatureStatus
.feature() = i
;
734 gfxFeatureStatus
.status() = status
;
735 gfxFeatureStatus
.failureId() = failureId
;
736 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
740 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
741 for (const auto& status
: *sFeatureStatus
) {
742 gfx::GfxInfoFeatureStatus copy
= status
;
743 features
.AppendElement(copy
);
748 inline bool MatchingAllowStatus(int32_t aStatus
) {
750 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
751 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
758 // Matching OS go somewhat beyond the simple equality check because of the
759 // "All Windows" and "All OS X" variations.
761 // aBlockedOS is describing the system(s) we are trying to block.
762 // aSystemOS is describing the system we are running on.
764 // aSystemOS should not be "Windows" or "OSX" - it should be set to
765 // a particular version instead.
766 // However, it is valid for aBlockedOS to be one of those generic values,
767 // as we could be blocking all of the versions.
768 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
769 OperatingSystem aSystemOS
,
770 uint32_t aSystemOSBuild
) {
771 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
772 aSystemOS
!= OperatingSystem::OSX
);
774 // If the block entry OS is unknown, it doesn't match
775 if (aBlockedOS
== OperatingSystem::Unknown
) {
780 if (aBlockedOS
== OperatingSystem::Windows
) {
781 // We do want even "unknown" aSystemOS to fall under "all windows"
785 constexpr uint32_t kMinWin10BuildNumber
= 18362;
786 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
787 aSystemOS
== OperatingSystem::Windows10
) {
788 // For allowlist purposes, we sometimes want to restrict to only recent
789 // versions of Windows 10. This is a bit of a kludge but easier than adding
790 // complicated blocklist infrastructure for build ID comparisons like driver
792 return aSystemOSBuild
>= kMinWin10BuildNumber
;
795 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
796 if (aSystemOS
== OperatingSystem::Windows10
) {
797 return aSystemOSBuild
< kMinWin10BuildNumber
;
804 #if defined(XP_MACOSX)
805 if (aBlockedOS
== OperatingSystem::OSX
) {
806 // We do want even "unknown" aSystemOS to fall under "all OS X"
811 return aSystemOS
== aBlockedOS
;
814 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
815 switch (aBatteryStatus
) {
816 case BatteryStatus::All
:
818 case BatteryStatus::None
:
820 case BatteryStatus::Present
:
824 MOZ_ASSERT_UNREACHABLE("bad battery status");
828 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
829 int64_t aScreenPixels
) {
830 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
831 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
833 switch (aScreenStatus
) {
834 case ScreenSizeStatus::All
:
836 case ScreenSizeStatus::Small
:
837 return aScreenPixels
<= kMaxSmallPixels
;
838 case ScreenSizeStatus::SmallAndMedium
:
839 return aScreenPixels
<= kMaxMediumPixels
;
840 case ScreenSizeStatus::Medium
:
841 return aScreenPixels
> kMaxSmallPixels
&&
842 aScreenPixels
<= kMaxMediumPixels
;
843 case ScreenSizeStatus::MediumAndLarge
:
844 return aScreenPixels
> kMaxSmallPixels
;
845 case ScreenSizeStatus::Large
:
846 return aScreenPixels
> kMaxMediumPixels
;
849 MOZ_ASSERT_UNREACHABLE("bad screen status");
853 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
854 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
855 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
857 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
859 // Some properties are not available on all platforms.
860 nsAutoString desktopEnvironment
;
861 nsresult rv
= GetDesktopEnvironment(desktopEnvironment
);
862 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
866 nsAutoString windowProtocol
;
867 rv
= GetWindowProtocol(windowProtocol
);
868 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
872 bool hasBattery
= false;
873 rv
= GetHasBattery(&hasBattery
);
874 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
878 uint32_t osBuild
= OperatingSystemBuild();
880 // Get the adapters once then reuse below
881 nsAutoString adapterVendorID
[2];
882 nsAutoString adapterDeviceID
[2];
883 nsAutoString adapterDriverVendor
[2];
884 nsAutoString adapterDriverVersionString
[2];
885 bool adapterInfoFailed
[2];
887 adapterInfoFailed
[0] =
888 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
889 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
890 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
891 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
892 adapterInfoFailed
[1] =
893 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
894 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
895 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
896 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
897 // No point in going on if we don't have adapter info
898 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
902 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
903 uint64_t driverVersion
[2] = {0, 0};
904 if (!adapterInfoFailed
[0]) {
905 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
907 if (!adapterInfoFailed
[1]) {
908 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
913 for (; i
< info
.Length(); i
++) {
914 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
915 // blocklisting. Only consider entries for our search mode.
916 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
920 // If we don't have the info for this GPU, no need to check further.
921 // It is unclear that we would ever have a mixture of 1st and 2nd
922 // GPU, but leaving the code in for that possibility for now.
923 // (Actually, currently mGpu2 will never be true, so this can
924 // be optimized out.)
925 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
926 if (adapterInfoFailed
[infoIndex
]) {
930 // Do the operating system check first, no point in getting the driver
931 // info if we won't need to use it.
932 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
936 if (info
[i
].mOperatingSystemVersion
&&
937 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
941 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
945 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
949 if (!DoesDesktopEnvironmentMatch(info
[i
].mDesktopEnvironment
,
950 desktopEnvironment
)) {
954 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
958 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
962 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
963 adapterDriverVendor
[infoIndex
])) {
967 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
968 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
969 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
974 // Failed to search, allowlist should not match, blocklist should match
975 // for safety reasons
985 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
988 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
991 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
994 if (!info
[i
].mManufacturer
.IsEmpty() &&
995 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
999 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1000 switch (info
[i
].mComparisonOp
) {
1001 case DRIVER_LESS_THAN
:
1002 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1004 case DRIVER_BUILD_ID_LESS_THAN
:
1005 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1007 case DRIVER_LESS_THAN_OR_EQUAL
:
1008 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1010 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1011 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1013 case DRIVER_GREATER_THAN
:
1014 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1016 case DRIVER_GREATER_THAN_OR_EQUAL
:
1017 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1020 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1022 case DRIVER_NOT_EQUAL
:
1023 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1025 case DRIVER_BETWEEN_EXCLUSIVE
:
1026 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1027 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1029 case DRIVER_BETWEEN_INCLUSIVE
:
1030 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1031 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1033 case DRIVER_BETWEEN_INCLUSIVE_START
:
1034 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1035 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1037 case DRIVER_COMPARISON_IGNORED
:
1038 // We don't have a comparison op, so we match everything.
1042 NS_WARNING("Bogus op in GfxDriverInfo");
1046 // We don't care what driver version it was. We only check OS version and if
1047 // the device matches.
1051 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1052 if ((info
[i
].mFeature
== GfxDriverInfo::allFeatures
&&
1053 aFeature
!= nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
) ||
1054 info
[i
].mFeature
== aFeature
) {
1055 status
= info
[i
].mFeatureStatus
;
1056 if (!info
[i
].mRuleId
.IsEmpty()) {
1057 aFailureId
= info
[i
].mRuleId
.get();
1059 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1067 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1068 // as either the primary or secondary adapter. D2D is also blocked when the
1069 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1070 // If the primary GPU already matched something in the blocklist then we
1071 // ignore this special rule. See bug 1008759.
1072 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1073 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1074 if (!adapterInfoFailed
[1]) {
1075 nsAString
& nvVendorID
=
1076 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1077 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1078 if (nvVendorID
.Equals(adapterVendorID
[1],
1079 nsCaseInsensitiveStringComparator
) &&
1080 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1081 nsCaseInsensitiveStringComparator
)) {
1082 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1083 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1088 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1089 // back to the Windows handler, so we must handle this here.
1090 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1091 if (info
[i
].mSuggestedVersion
) {
1092 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1093 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1094 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1095 aSuggestedVersion
.AppendPrintf(
1096 "%lld.%lld.%lld.%lld",
1097 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1098 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1099 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1100 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1108 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1109 MOZ_ASSERT(!sFeatureStatus
);
1110 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1113 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1114 const nsAString
& aBlocklistDesktop
, const nsAString
& aDesktopEnv
) {
1115 return aBlocklistDesktop
.Equals(aDesktopEnv
,
1116 nsCaseInsensitiveStringComparator
) ||
1117 aBlocklistDesktop
.Equals(
1118 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All
),
1119 nsCaseInsensitiveStringComparator
);
1122 bool GfxInfoBase::DoesWindowProtocolMatch(
1123 const nsAString
& aBlocklistWindowProtocol
,
1124 const nsAString
& aWindowProtocol
) {
1125 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1126 nsCaseInsensitiveStringComparator
) ||
1127 aBlocklistWindowProtocol
.Equals(
1128 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1129 nsCaseInsensitiveStringComparator
);
1132 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1133 const nsAString
& aAdapterVendor
) {
1134 return aBlocklistVendor
.Equals(aAdapterVendor
,
1135 nsCaseInsensitiveStringComparator
) ||
1136 aBlocklistVendor
.Equals(
1137 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1138 nsCaseInsensitiveStringComparator
);
1141 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1142 const nsAString
& aDriverVendor
) {
1143 return aBlocklistVendor
.Equals(aDriverVendor
,
1144 nsCaseInsensitiveStringComparator
) ||
1145 aBlocklistVendor
.Equals(
1146 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1147 nsCaseInsensitiveStringComparator
);
1150 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1151 return aFeature
== nsIGfxInfo::FEATURE_WEBRENDER
||
1152 aFeature
== nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
;
1155 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1156 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1157 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1158 OperatingSystem
* aOS
/* = nullptr */) {
1159 if (aFeature
<= 0) {
1160 gfxWarning() << "Invalid feature <= 0";
1164 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1165 // Terminate now with the status determined by the derived type (OS-specific
1170 if (sShutdownOccurred
) {
1171 // This is futile; we've already commenced shutdown and our blocklists have
1172 // been deleted. We may want to look into resurrecting the blocklist instead
1173 // but for now, just don't even go there.
1177 // Ensure any additional initialization required is complete.
1180 // If an operating system was provided by the derived GetFeatureStatusImpl,
1181 // grab it here. Otherwise, the OS is unknown.
1182 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1184 nsAutoString adapterVendorID
;
1185 nsAutoString adapterDeviceID
;
1186 nsAutoString adapterDriverVersionString
;
1187 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1188 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1189 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1190 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1191 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1195 // Check if the device is blocked from the downloaded blocklist. If not, check
1196 // the static list after that. This order is used so that we can later escape
1197 // out of static blocks (i.e. if we were wrong or something was patched, we
1198 // can back out our static block without doing a release).
1200 if (aDriverInfo
.Length()) {
1202 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1203 aFailureId
, os
, /* aForAllowing */ false);
1206 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1208 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1209 aFeature
, aFailureId
, os
,
1210 /* aForAllowing */ false);
1213 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1214 if (IsFeatureAllowlisted(aFeature
)) {
1215 // This feature is actually using the allowlist; that means after we pass
1216 // the blocklist to prevent us explicitly from getting the feature, we now
1217 // need to check the allowlist to ensure we are allowed to get it in the
1219 if (aDriverInfo
.Length()) {
1220 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1221 aFeature
, aFailureId
, os
,
1222 /* aForAllowing */ true);
1224 status
= FindBlocklistedDeviceInList(
1225 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1226 /* aForAllowing */ true);
1229 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1230 status
= nsIGfxInfo::FEATURE_DENIED
;
1233 // It's now done being processed. It's safe to set the status to
1235 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1244 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1245 nsAString
& aVersion
) {
1247 if (GetPrefValueForDriverVersion(version
)) {
1248 aVersion
= NS_ConvertASCIItoUTF16(version
);
1253 nsCString discardFailureId
;
1254 nsTArray
<GfxDriverInfo
> driverInfo
;
1255 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1259 void GfxInfoBase::EvaluateDownloadedBlocklist(
1260 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1261 int32_t features
[] = {nsIGfxInfo::FEATURE_DIRECT2D
,
1262 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
,
1263 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
,
1264 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
,
1265 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
,
1266 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
,
1267 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
,
1268 nsIGfxInfo::FEATURE_OPENGL_LAYERS
,
1269 nsIGfxInfo::FEATURE_WEBGL_OPENGL
,
1270 nsIGfxInfo::FEATURE_WEBGL_ANGLE
,
1271 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
,
1272 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
,
1273 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
,
1274 nsIGfxInfo::FEATURE_STAGEFRIGHT
,
1275 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
,
1276 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
,
1277 nsIGfxInfo::FEATURE_VP8_HW_DECODE
,
1278 nsIGfxInfo::FEATURE_VP9_HW_DECODE
,
1279 nsIGfxInfo::FEATURE_DX_INTEROP2
,
1280 nsIGfxInfo::FEATURE_GPU_PROCESS
,
1281 nsIGfxInfo::FEATURE_WEBGL2
,
1282 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
1283 nsIGfxInfo::FEATURE_WEBRENDER
,
1284 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
,
1285 nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
,
1286 nsIGfxInfo::FEATURE_DX_NV12
,
1287 nsIGfxInfo::FEATURE_DX_P010
,
1288 nsIGfxInfo::FEATURE_DX_P016
,
1289 nsIGfxInfo::FEATURE_GL_SWIZZLE
,
1290 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
,
1293 // For every feature we know about, we evaluate whether this blocklist has a
1294 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1295 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1296 // anywhere permanent.
1298 while (features
[i
]) {
1300 nsCString failureId
;
1301 nsAutoString suggestedVersion
;
1302 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1303 features
[i
], &status
, suggestedVersion
, aDriverInfo
, failureId
))) {
1306 case nsIGfxInfo::FEATURE_STATUS_OK
:
1307 RemovePrefForFeature(features
[i
]);
1310 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1311 if (!suggestedVersion
.IsEmpty()) {
1312 SetPrefValueForDriverVersion(suggestedVersion
);
1314 RemovePrefForDriverVersion();
1318 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1319 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1320 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1321 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1322 SetPrefValueForFeature(features
[i
], status
, failureId
);
1331 NS_IMETHODIMP_(void)
1332 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1333 // gfxCriticalError has a mutex lock of its own, so we may not actually
1334 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1335 // will not return the copy of the logs unless it can get the same lock
1336 // that gfxCriticalError uses. Still, that is so much of an implementation
1337 // detail that it's nicer to just add an extra lock here and in
1339 MutexAutoLock
lock(mMutex
);
1341 // By default, gfxCriticalError asserts; make it not assert in this case.
1342 gfxCriticalError(CriticalLog::DefaultOptions(false))
1343 << "(LF) " << failure
.BeginReading();
1346 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1347 nsTArray
<nsCString
>& failures
) {
1348 MutexAutoLock
lock(mMutex
);
1350 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1351 if (!logForwarder
) {
1352 return NS_ERROR_UNEXPECTED
;
1355 // There are two string copies in this method, starting with this one. We are
1356 // assuming this is not a big deal, as the size of the array should be small
1357 // and the strings in it should be small as well (the error messages in the
1358 // code.) The second copy happens with the AppendElement() calls.
1359 // Technically, we don't need the mutex lock after the StringVectorCopy()
1361 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1362 LoggingRecord::const_iterator it
;
1363 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1364 failures
.AppendElement(
1365 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1366 indices
.AppendElement(Get
<0>(*it
));
1372 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1374 static void InitCollectors() {
1375 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1378 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1379 JS::MutableHandle
<JS::Value
> aResult
) {
1381 InfoObject
obj(aCx
);
1383 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1384 (*sCollectors
)[i
]->GetInfo(obj
);
1387 // Some example property definitions
1388 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1389 // obj.DefineProperty("renderer", mRendererIDsString);
1390 // obj.DefineProperty("five", 5);
1393 return NS_ERROR_FAILURE
;
1396 aResult
.setObject(*obj
.mObj
);
1400 nsAutoCString gBaseAppVersion
;
1402 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1403 static bool versionInitialized
= false;
1404 if (!versionInitialized
) {
1405 // If we fail to get the version, we will not try again.
1406 versionInitialized
= true;
1408 // Get the version from xpcom/system/nsIXULAppInfo.idl
1409 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1411 app
->GetVersion(gBaseAppVersion
);
1414 return gBaseAppVersion
;
1417 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1419 sCollectors
->AppendElement(collector
);
1422 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1424 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1425 if ((*sCollectors
)[i
] == collector
) {
1426 sCollectors
->RemoveElementAt(i
);
1430 if (sCollectors
->IsEmpty()) {
1432 sCollectors
= nullptr;
1436 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
, JS::HandleObject aOutArray
) {
1437 // If we have no platform specific implementation for detecting monitors, we
1438 // can just get the screen size from gfxPlatform as the best guess.
1439 if (!gfxPlatform::Initialized()) {
1443 // If the screen size is empty, we are probably in xpcshell.
1444 gfx::IntSize screenSize
= gfxPlatform::GetPlatform()->GetScreenSize();
1446 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1448 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1449 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1451 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1452 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1454 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1455 JS_SetElement(aCx
, aOutArray
, 0, element
);
1461 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandleValue aResult
) {
1462 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1464 nsresult rv
= FindMonitors(aCx
, array
);
1465 if (NS_FAILED(rv
)) {
1469 aResult
.setObject(*array
);
1474 GfxInfoBase::RefreshMonitors() { return NS_ERROR_NOT_IMPLEMENTED
; }
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
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1659 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1662 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1663 JS::Handle
<JSObject
*> aContainer
,
1665 mozilla::gfx::FeatureState
& aFeatureState
,
1666 JS::MutableHandle
<JSObject
*> aOutObj
) {
1667 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1672 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1674 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1675 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1676 JS_SetProperty(aCx
, obj
, "status", val
);
1678 // Add the feature object to the container.
1680 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1681 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1688 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1689 JS::MutableHandle
<JS::Value
> aOut
) {
1690 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1692 return NS_ERROR_OUT_OF_MEMORY
;
1694 aOut
.setObject(*array
);
1696 DriverCrashGuard::ForEachActiveCrashGuard(
1697 [&](const char* aName
, const char* aPrefName
) -> void {
1698 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1702 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1705 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1708 if (!AppendJSElement(aCx
, array
, obj
)) {
1717 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled
) {
1718 *aWebRenderEnabled
= gfxVars::UseWebRender();
1723 GfxInfoBase::GetUsesTiling(bool* aUsesTiling
) {
1724 *aUsesTiling
= gfxPlatform::GetPlatform()->UsesTiling();
1729 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling
) {
1730 *aUsesTiling
= gfxPlatform::GetPlatform()->ContentUsesTiling();
1735 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled
) {
1736 *aOffMainThreadPaintEnabled
= gfxConfig::IsEnabled(gfx::Feature::OMTP
);
1741 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1742 int32_t* aOffMainThreadPaintWorkerCount
) {
1743 if (gfxConfig::IsEnabled(gfx::Feature::OMTP
)) {
1744 *aOffMainThreadPaintWorkerCount
=
1745 layers::PaintThread::CalculatePaintWorkerCount();
1747 *aOffMainThreadPaintWorkerCount
= 0;
1753 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1754 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1759 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1760 *aIsHeadless
= gfxPlatform::IsHeadless();
1765 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1766 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1770 case BackendType::DIRECT2D1_1
: {
1771 outStr
.AppendPrintf("Direct2D 1.1");
1774 case BackendType::SKIA
: {
1775 outStr
.AppendPrintf("Skia");
1778 case BackendType::CAIRO
: {
1779 outStr
.AppendPrintf("Cairo");
1783 return NS_ERROR_FAILURE
;
1786 aContentBackend
.Assign(outStr
);
1791 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1792 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1794 // Not supported in content processes.
1795 return NS_ERROR_FAILURE
;
1798 *aOutValue
= !!gpu
->GetGPUChild();
1803 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1804 gfxPlatform::GetPlatform();
1806 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1808 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1809 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1811 gpm
->LaunchGPUProcess();
1812 gpm
->EnsureGPUReady();
1814 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1822 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1823 GfxInfoBase::AddCollector(this);
1826 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1827 GfxInfoBase::RemoveCollector(this);