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";
234 case nsIGfxInfo::FEATURE_X11_EGL
:
235 name
= BLOCKLIST_PREF_BRANCH
"x11.egl";
237 case nsIGfxInfo::FEATURE_DMABUF
:
238 name
= BLOCKLIST_PREF_BRANCH
"dmabuf";
241 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
248 // Returns the value of the pref for the relevant feature in aValue.
249 // If the pref doesn't exist, aValue is not touched, and returns false.
250 static bool GetPrefValueForFeature(int32_t aFeature
, int32_t& aValue
,
251 nsACString
& aFailureId
) {
252 const char* prefname
= GetPrefNameForFeature(aFeature
);
253 if (!prefname
) return false;
255 aValue
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
256 if (!NS_SUCCEEDED(Preferences::GetInt(prefname
, &aValue
))) {
260 nsCString
failureprefname(prefname
);
261 failureprefname
+= ".failureid";
262 nsAutoCString failureValue
;
263 nsresult rv
= Preferences::GetCString(failureprefname
.get(), failureValue
);
264 if (NS_SUCCEEDED(rv
)) {
265 aFailureId
= failureValue
.get();
267 aFailureId
= "FEATURE_FAILURE_BLOCKLIST_PREF";
273 static void SetPrefValueForFeature(int32_t aFeature
, int32_t aValue
,
274 const nsACString
& aFailureId
) {
275 const char* prefname
= GetPrefNameForFeature(aFeature
);
276 if (!prefname
) return;
277 if (XRE_IsParentProcess()) {
278 GfxInfoBase::sFeatureStatus
= nullptr;
281 Preferences::SetInt(prefname
, aValue
);
282 if (!aFailureId
.IsEmpty()) {
283 nsCString
failureprefname(prefname
);
284 failureprefname
+= ".failureid";
285 Preferences::SetCString(failureprefname
.get(), aFailureId
);
289 static void RemovePrefForFeature(int32_t aFeature
) {
290 const char* prefname
= GetPrefNameForFeature(aFeature
);
291 if (!prefname
) return;
293 if (XRE_IsParentProcess()) {
294 GfxInfoBase::sFeatureStatus
= nullptr;
296 Preferences::ClearUser(prefname
);
299 static bool GetPrefValueForDriverVersion(nsCString
& aVersion
) {
301 Preferences::GetCString(SUGGESTED_VERSION_PREF
, aVersion
));
304 static void SetPrefValueForDriverVersion(const nsAString
& aVersion
) {
305 Preferences::SetString(SUGGESTED_VERSION_PREF
, aVersion
);
308 static void RemovePrefForDriverVersion() {
309 Preferences::ClearUser(SUGGESTED_VERSION_PREF
);
312 static OperatingSystem
BlocklistOSToOperatingSystem(const nsAString
& os
) {
313 if (os
.EqualsLiteral("WINNT 6.1")) {
314 return OperatingSystem::Windows7
;
315 } else if (os
.EqualsLiteral("WINNT 6.2")) {
316 return OperatingSystem::Windows8
;
317 } else if (os
.EqualsLiteral("WINNT 6.3")) {
318 return OperatingSystem::Windows8_1
;
319 } else if (os
.EqualsLiteral("WINNT 10.0")) {
320 return OperatingSystem::Windows10
;
321 } else if (os
.EqualsLiteral("Linux")) {
322 return OperatingSystem::Linux
;
323 } else if (os
.EqualsLiteral("Darwin 9")) {
324 return OperatingSystem::OSX10_5
;
325 } else if (os
.EqualsLiteral("Darwin 10")) {
326 return OperatingSystem::OSX10_6
;
327 } else if (os
.EqualsLiteral("Darwin 11")) {
328 return OperatingSystem::OSX10_7
;
329 } else if (os
.EqualsLiteral("Darwin 12")) {
330 return OperatingSystem::OSX10_8
;
331 } else if (os
.EqualsLiteral("Darwin 13")) {
332 return OperatingSystem::OSX10_9
;
333 } else if (os
.EqualsLiteral("Darwin 14")) {
334 return OperatingSystem::OSX10_10
;
335 } else if (os
.EqualsLiteral("Darwin 15")) {
336 return OperatingSystem::OSX10_11
;
337 } else if (os
.EqualsLiteral("Darwin 16")) {
338 return OperatingSystem::OSX10_12
;
339 } else if (os
.EqualsLiteral("Darwin 17")) {
340 return OperatingSystem::OSX10_13
;
341 } else if (os
.EqualsLiteral("Darwin 18")) {
342 return OperatingSystem::OSX10_14
;
343 } else if (os
.EqualsLiteral("Darwin 19")) {
344 return OperatingSystem::OSX10_15
;
345 } else if (os
.EqualsLiteral("Darwin 20")) {
346 return OperatingSystem::OSX11_0
;
347 } else if (os
.EqualsLiteral("Android")) {
348 return OperatingSystem::Android
;
349 // For historical reasons, "All" in blocklist means "All Windows"
350 } else if (os
.EqualsLiteral("All")) {
351 return OperatingSystem::Windows
;
352 } else if (os
.EqualsLiteral("Darwin")) {
353 return OperatingSystem::OSX
;
356 return OperatingSystem::Unknown
;
359 static GfxDeviceFamily
* BlocklistDevicesToDeviceFamily(
360 nsTArray
<nsCString
>& devices
) {
361 if (devices
.Length() == 0) return nullptr;
363 // For each device, get its device ID, and return a freshly-allocated
364 // GfxDeviceFamily with the contents of that array.
365 GfxDeviceFamily
* deviceIds
= new GfxDeviceFamily
;
367 for (uint32_t i
= 0; i
< devices
.Length(); ++i
) {
368 // We make sure we don't add any "empty" device entries to the array, so
369 // we don't need to check if devices[i] is empty.
370 deviceIds
->Append(NS_ConvertUTF8toUTF16(devices
[i
]));
376 static int32_t BlocklistFeatureToGfxFeature(const nsAString
& aFeature
) {
377 MOZ_ASSERT(!aFeature
.IsEmpty());
378 if (aFeature
.EqualsLiteral("DIRECT2D"))
379 return nsIGfxInfo::FEATURE_DIRECT2D
;
380 else if (aFeature
.EqualsLiteral("DIRECT3D_9_LAYERS"))
381 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
;
382 else if (aFeature
.EqualsLiteral("DIRECT3D_10_LAYERS"))
383 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
;
384 else if (aFeature
.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
385 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
;
386 else if (aFeature
.EqualsLiteral("DIRECT3D_11_LAYERS"))
387 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
;
388 else if (aFeature
.EqualsLiteral("DIRECT3D_11_ANGLE"))
389 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
;
390 else if (aFeature
.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
391 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
;
392 else if (aFeature
.EqualsLiteral("OPENGL_LAYERS"))
393 return nsIGfxInfo::FEATURE_OPENGL_LAYERS
;
394 else if (aFeature
.EqualsLiteral("WEBGL_OPENGL"))
395 return nsIGfxInfo::FEATURE_WEBGL_OPENGL
;
396 else if (aFeature
.EqualsLiteral("WEBGL_ANGLE"))
397 return nsIGfxInfo::FEATURE_WEBGL_ANGLE
;
398 else if (aFeature
.EqualsLiteral("WEBGL_MSAA"))
399 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
;
400 else if (aFeature
.EqualsLiteral("STAGEFRIGHT"))
401 return nsIGfxInfo::FEATURE_STAGEFRIGHT
;
402 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
403 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
;
404 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
405 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
;
406 else if (aFeature
.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264"))
407 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
;
408 else if (aFeature
.EqualsLiteral("CANVAS2D_ACCELERATION"))
409 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
;
410 else if (aFeature
.EqualsLiteral("DX_INTEROP2"))
411 return nsIGfxInfo::FEATURE_DX_INTEROP2
;
412 else if (aFeature
.EqualsLiteral("GPU_PROCESS"))
413 return nsIGfxInfo::FEATURE_GPU_PROCESS
;
414 else if (aFeature
.EqualsLiteral("WEBGL2"))
415 return nsIGfxInfo::FEATURE_WEBGL2
;
416 else if (aFeature
.EqualsLiteral("D3D11_KEYED_MUTEX"))
417 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
;
418 else if (aFeature
.EqualsLiteral("WEBRENDER"))
419 return nsIGfxInfo::FEATURE_WEBRENDER
;
420 else if (aFeature
.EqualsLiteral("WEBRENDER_COMPOSITOR"))
421 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
;
422 else if (aFeature
.EqualsLiteral("DX_NV12"))
423 return nsIGfxInfo::FEATURE_DX_NV12
;
424 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
425 // in downloadable blocklist.
426 else if (aFeature
.EqualsLiteral("GL_SWIZZLE"))
427 return nsIGfxInfo::FEATURE_GL_SWIZZLE
;
428 else if (aFeature
.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS"))
429 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS
;
430 else if (aFeature
.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS"))
431 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
;
432 else if (aFeature
.EqualsLiteral("THREADSAFE_GL"))
433 return nsIGfxInfo::FEATURE_THREADSAFE_GL
;
434 else if (aFeature
.EqualsLiteral("WEBRENDER_SOFTWARE"))
435 return nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
;
436 else if (aFeature
.EqualsLiteral("X11_EGL"))
437 return nsIGfxInfo::FEATURE_X11_EGL
;
438 else if (aFeature
.EqualsLiteral("DMABUF"))
439 return nsIGfxInfo::FEATURE_DMABUF
;
441 // If we don't recognize the feature, it may be new, and something
442 // this version doesn't understand. So, nothing to do. This is
443 // different from feature not being specified at all, in which case
444 // this method should not get called and we should continue with the
445 // "all features" blocklisting.
449 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
450 const nsAString
& aStatus
) {
451 if (aStatus
.EqualsLiteral("STATUS_OK"))
452 return nsIGfxInfo::FEATURE_STATUS_OK
;
453 else if (aStatus
.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
454 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
;
455 else if (aStatus
.EqualsLiteral("BLOCKED_DEVICE"))
456 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
457 else if (aStatus
.EqualsLiteral("DISCOURAGED"))
458 return nsIGfxInfo::FEATURE_DISCOURAGED
;
459 else if (aStatus
.EqualsLiteral("BLOCKED_OS_VERSION"))
460 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
;
461 else if (aStatus
.EqualsLiteral("DENIED"))
462 return nsIGfxInfo::FEATURE_DENIED
;
463 else if (aStatus
.EqualsLiteral("ALLOW_QUALIFIED"))
464 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
;
465 else if (aStatus
.EqualsLiteral("ALLOW_ALWAYS"))
466 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS
;
468 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
469 // expecting the "mismatch" status showing up here.
471 return nsIGfxInfo::FEATURE_STATUS_OK
;
474 static VersionComparisonOp
BlocklistComparatorToComparisonOp(
475 const nsAString
& op
) {
476 if (op
.EqualsLiteral("LESS_THAN"))
477 return DRIVER_LESS_THAN
;
478 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN"))
479 return DRIVER_BUILD_ID_LESS_THAN
;
480 else if (op
.EqualsLiteral("LESS_THAN_OR_EQUAL"))
481 return DRIVER_LESS_THAN_OR_EQUAL
;
482 else if (op
.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
483 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
;
484 else if (op
.EqualsLiteral("GREATER_THAN"))
485 return DRIVER_GREATER_THAN
;
486 else if (op
.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
487 return DRIVER_GREATER_THAN_OR_EQUAL
;
488 else if (op
.EqualsLiteral("EQUAL"))
490 else if (op
.EqualsLiteral("NOT_EQUAL"))
491 return DRIVER_NOT_EQUAL
;
492 else if (op
.EqualsLiteral("BETWEEN_EXCLUSIVE"))
493 return DRIVER_BETWEEN_EXCLUSIVE
;
494 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE"))
495 return DRIVER_BETWEEN_INCLUSIVE
;
496 else if (op
.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
497 return DRIVER_BETWEEN_INCLUSIVE_START
;
499 return DRIVER_COMPARISON_IGNORED
;
503 Deserialize Blocklist entries from string.
505 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
507 static bool BlocklistEntryToDriverInfo(const nsACString
& aBlocklistEntry
,
508 GfxDriverInfo
& aDriverInfo
) {
509 // If we get an application version to be zero, something is not working
510 // and we are not going to bother checking the blocklist versions.
511 // See TestGfxWidgets.cpp for how version comparison works.
512 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
513 static mozilla::Version
zeroV("0");
514 static mozilla::Version
appV(GfxInfoBase::GetApplicationVersion().get());
516 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
517 << "Invalid application version "
518 << GfxInfoBase::GetApplicationVersion().get();
521 aDriverInfo
.mRuleId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns
;
523 for (const auto& keyValue
: aBlocklistEntry
.Split('\t')) {
524 nsTArray
<nsCString
> splitted
;
525 ParseString(keyValue
, ':', splitted
);
526 if (splitted
.Length() != 2) {
527 // If we don't recognize the input data, we do not want to proceed.
528 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
529 << "Unrecognized data " << nsCString(keyValue
).get();
532 const nsCString
& key
= splitted
[0];
533 const nsCString
& value
= splitted
[1];
534 NS_ConvertUTF8toUTF16
dataValue(value
);
536 if (value
.Length() == 0) {
537 // Safety check for empty values.
538 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
539 << "Empty value for " << key
.get();
543 if (key
.EqualsLiteral("blockID")) {
544 nsCString blockIdStr
= "FEATURE_FAILURE_DL_BLOCKLIST_"_ns
+ value
;
545 aDriverInfo
.mRuleId
= blockIdStr
.get();
546 } else if (key
.EqualsLiteral("os")) {
547 aDriverInfo
.mOperatingSystem
= BlocklistOSToOperatingSystem(dataValue
);
548 } else if (key
.EqualsLiteral("osversion")) {
549 aDriverInfo
.mOperatingSystemVersion
= strtoul(value
.get(), nullptr, 10);
550 } else if (key
.EqualsLiteral("desktopEnvironment")) {
551 aDriverInfo
.mDesktopEnvironment
= dataValue
;
552 } else if (key
.EqualsLiteral("windowProtocol")) {
553 aDriverInfo
.mWindowProtocol
= dataValue
;
554 } else if (key
.EqualsLiteral("vendor")) {
555 aDriverInfo
.mAdapterVendor
= dataValue
;
556 } else if (key
.EqualsLiteral("driverVendor")) {
557 aDriverInfo
.mDriverVendor
= dataValue
;
558 } else if (key
.EqualsLiteral("feature")) {
559 aDriverInfo
.mFeature
= BlocklistFeatureToGfxFeature(dataValue
);
560 if (aDriverInfo
.mFeature
< 0) {
561 // If we don't recognize the feature, we do not want to proceed.
562 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
563 << "Unrecognized feature " << value
.get();
566 } else if (key
.EqualsLiteral("featureStatus")) {
567 aDriverInfo
.mFeatureStatus
=
568 BlocklistFeatureStatusToGfxFeatureStatus(dataValue
);
569 } else if (key
.EqualsLiteral("driverVersion")) {
571 if (ParseDriverVersion(dataValue
, &version
))
572 aDriverInfo
.mDriverVersion
= version
;
573 } else if (key
.EqualsLiteral("driverVersionMax")) {
575 if (ParseDriverVersion(dataValue
, &version
))
576 aDriverInfo
.mDriverVersionMax
= version
;
577 } else if (key
.EqualsLiteral("driverVersionComparator")) {
578 aDriverInfo
.mComparisonOp
= BlocklistComparatorToComparisonOp(dataValue
);
579 } else if (key
.EqualsLiteral("model")) {
580 aDriverInfo
.mModel
= dataValue
;
581 } else if (key
.EqualsLiteral("product")) {
582 aDriverInfo
.mProduct
= dataValue
;
583 } else if (key
.EqualsLiteral("manufacturer")) {
584 aDriverInfo
.mManufacturer
= dataValue
;
585 } else if (key
.EqualsLiteral("hardware")) {
586 aDriverInfo
.mHardware
= dataValue
;
587 } else if (key
.EqualsLiteral("versionRange")) {
588 nsTArray
<nsCString
> versionRange
;
589 ParseString(value
, ',', versionRange
);
590 if (versionRange
.Length() != 2) {
591 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
592 << "Unrecognized versionRange " << value
.get();
595 const nsCString
& minValue
= versionRange
[0];
596 const nsCString
& maxValue
= versionRange
[1];
598 mozilla::Version
minV(minValue
.get());
599 mozilla::Version
maxV(maxValue
.get());
601 if (minV
> zeroV
&& !(appV
>= minV
)) {
602 // The version of the application is less than the minimal version
603 // this blocklist entry applies to, so we can just ignore it by
604 // returning false and letting the caller deal with it.
607 if (maxV
> zeroV
&& !(appV
<= maxV
)) {
608 // The version of the application is more than the maximal version
609 // this blocklist entry applies to, so we can just ignore it by
610 // returning false and letting the caller deal with it.
613 } else if (key
.EqualsLiteral("devices")) {
614 nsTArray
<nsCString
> devices
;
615 ParseString(value
, ',', devices
);
616 GfxDeviceFamily
* deviceIds
= BlocklistDevicesToDeviceFamily(devices
);
618 // Get GfxDriverInfo to adopt the devices array we created.
619 aDriverInfo
.mDeleteDevices
= true;
620 aDriverInfo
.mDevices
= deviceIds
;
623 // We explicitly ignore unknown elements.
630 GfxInfoBase::Observe(nsISupports
* aSubject
, const char* aTopic
,
631 const char16_t
* aData
) {
632 if (strcmp(aTopic
, "blocklist-data-gfxItems") == 0) {
633 nsTArray
<GfxDriverInfo
> driverInfo
;
634 NS_ConvertUTF16toUTF8
utf8Data(aData
);
636 for (const auto& blocklistEntry
: utf8Data
.Split('\n')) {
638 if (BlocklistEntryToDriverInfo(blocklistEntry
, di
)) {
639 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
640 // Probably some non-standard semantics of the copy/move operations?
641 *driverInfo
.AppendElement() = di
;
642 // Prevent di falling out of scope from destroying the devices.
643 di
.mDeleteDevices
= false;
645 driverInfo
.AppendElement();
649 EvaluateDownloadedBlocklist(driverInfo
);
655 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX
), mMutex("GfxInfoBase") {}
657 GfxInfoBase::~GfxInfoBase() = default;
659 nsresult
GfxInfoBase::Init() {
660 InitGfxDriverInfoShutdownObserver();
662 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
664 os
->AddObserver(this, "blocklist-data-gfxItems", true);
670 void GfxInfoBase::GetData() {
671 if (mScreenPixels
!= INT64_MAX
) {
672 // Already initialized.
676 nsCOMPtr
<nsIScreenManager
> manager
=
677 do_GetService("@mozilla.org/gfx/screenmanager;1");
679 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
683 manager
->GetTotalScreenPixels(&mScreenPixels
);
687 GfxInfoBase::GetFeatureStatus(int32_t aFeature
, nsACString
& aFailureId
,
689 // Ignore the gfx.blocklist.all pref on release and beta.
690 #if defined(RELEASE_OR_BETA)
691 int32_t blocklistAll
= 0;
693 int32_t blocklistAll
= StaticPrefs::gfx_blocklist_all_AtStartup();
695 if (blocklistAll
> 0) {
696 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
697 << "Forcing blocklisting all features";
698 *aStatus
= FEATURE_BLOCKED_DEVICE
;
699 aFailureId
= "FEATURE_FAILURE_BLOCK_ALL";
701 } else if (blocklistAll
< 0) {
702 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
703 << "Ignoring any feature blocklisting.";
704 *aStatus
= FEATURE_STATUS_OK
;
708 if (GetPrefValueForFeature(aFeature
, *aStatus
, aFailureId
)) {
712 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
713 // Use the cached data received from the parent process.
714 MOZ_ASSERT(sFeatureStatus
);
715 bool success
= false;
716 for (const auto& fs
: *sFeatureStatus
) {
717 if (fs
.feature() == aFeature
) {
718 aFailureId
= fs
.failureId();
719 *aStatus
= fs
.status();
724 return success
? NS_OK
: NS_ERROR_FAILURE
;
728 nsTArray
<GfxDriverInfo
> driverInfo
;
730 GetFeatureStatusImpl(aFeature
, aStatus
, version
, driverInfo
, aFailureId
);
734 nsTArray
<gfx::GfxInfoFeatureStatus
> GfxInfoBase::GetAllFeatures() {
735 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
736 if (!sFeatureStatus
) {
737 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>());
738 for (int32_t i
= 1; i
<= nsIGfxInfo::FEATURE_MAX_VALUE
; ++i
) {
740 nsAutoCString failureId
;
741 GetFeatureStatus(i
, failureId
, &status
);
742 gfx::GfxInfoFeatureStatus gfxFeatureStatus
;
743 gfxFeatureStatus
.feature() = i
;
744 gfxFeatureStatus
.status() = status
;
745 gfxFeatureStatus
.failureId() = failureId
;
746 sFeatureStatus
->AppendElement(gfxFeatureStatus
);
750 nsTArray
<gfx::GfxInfoFeatureStatus
> features
;
751 for (const auto& status
: *sFeatureStatus
) {
752 gfx::GfxInfoFeatureStatus copy
= status
;
753 features
.AppendElement(copy
);
758 inline bool MatchingAllowStatus(int32_t aStatus
) {
760 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS
:
761 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED
:
768 // Matching OS go somewhat beyond the simple equality check because of the
769 // "All Windows" and "All OS X" variations.
771 // aBlockedOS is describing the system(s) we are trying to block.
772 // aSystemOS is describing the system we are running on.
774 // aSystemOS should not be "Windows" or "OSX" - it should be set to
775 // a particular version instead.
776 // However, it is valid for aBlockedOS to be one of those generic values,
777 // as we could be blocking all of the versions.
778 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS
,
779 OperatingSystem aSystemOS
,
780 uint32_t aSystemOSBuild
) {
781 MOZ_ASSERT(aSystemOS
!= OperatingSystem::Windows
&&
782 aSystemOS
!= OperatingSystem::OSX
);
784 // If the block entry OS is unknown, it doesn't match
785 if (aBlockedOS
== OperatingSystem::Unknown
) {
790 if (aBlockedOS
== OperatingSystem::Windows
) {
791 // We do want even "unknown" aSystemOS to fall under "all windows"
795 constexpr uint32_t kMinWin10BuildNumber
= 18362;
796 if (aBlockedOS
== OperatingSystem::RecentWindows10
&&
797 aSystemOS
== OperatingSystem::Windows10
) {
798 // For allowlist purposes, we sometimes want to restrict to only recent
799 // versions of Windows 10. This is a bit of a kludge but easier than adding
800 // complicated blocklist infrastructure for build ID comparisons like driver
802 return aSystemOSBuild
>= kMinWin10BuildNumber
;
805 if (aBlockedOS
== OperatingSystem::NotRecentWindows10
) {
806 if (aSystemOS
== OperatingSystem::Windows10
) {
807 return aSystemOSBuild
< kMinWin10BuildNumber
;
814 #if defined(XP_MACOSX)
815 if (aBlockedOS
== OperatingSystem::OSX
) {
816 // We do want even "unknown" aSystemOS to fall under "all OS X"
821 return aSystemOS
== aBlockedOS
;
824 inline bool MatchingBattery(BatteryStatus aBatteryStatus
, bool aHasBattery
) {
825 switch (aBatteryStatus
) {
826 case BatteryStatus::All
:
828 case BatteryStatus::None
:
830 case BatteryStatus::Present
:
834 MOZ_ASSERT_UNREACHABLE("bad battery status");
838 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus
,
839 int64_t aScreenPixels
) {
840 constexpr int64_t kMaxSmallPixels
= 2304000; // 1920x1200
841 constexpr int64_t kMaxMediumPixels
= 4953600; // 3440x1440
843 switch (aScreenStatus
) {
844 case ScreenSizeStatus::All
:
846 case ScreenSizeStatus::Small
:
847 return aScreenPixels
<= kMaxSmallPixels
;
848 case ScreenSizeStatus::SmallAndMedium
:
849 return aScreenPixels
<= kMaxMediumPixels
;
850 case ScreenSizeStatus::Medium
:
851 return aScreenPixels
> kMaxSmallPixels
&&
852 aScreenPixels
<= kMaxMediumPixels
;
853 case ScreenSizeStatus::MediumAndLarge
:
854 return aScreenPixels
> kMaxSmallPixels
;
855 case ScreenSizeStatus::Large
:
856 return aScreenPixels
> kMaxMediumPixels
;
859 MOZ_ASSERT_UNREACHABLE("bad screen status");
863 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
864 const nsTArray
<GfxDriverInfo
>& info
, nsAString
& aSuggestedVersion
,
865 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
867 int32_t status
= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
;
869 // Some properties are not available on all platforms.
870 nsAutoString desktopEnvironment
;
871 nsresult rv
= GetDesktopEnvironment(desktopEnvironment
);
872 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
876 nsAutoString windowProtocol
;
877 rv
= GetWindowProtocol(windowProtocol
);
878 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
882 bool hasBattery
= false;
883 rv
= GetHasBattery(&hasBattery
);
884 if (NS_FAILED(rv
) && rv
!= NS_ERROR_NOT_IMPLEMENTED
) {
888 uint32_t osBuild
= OperatingSystemBuild();
890 // Get the adapters once then reuse below
891 nsAutoString adapterVendorID
[2];
892 nsAutoString adapterDeviceID
[2];
893 nsAutoString adapterDriverVendor
[2];
894 nsAutoString adapterDriverVersionString
[2];
895 bool adapterInfoFailed
[2];
897 adapterInfoFailed
[0] =
898 (NS_FAILED(GetAdapterVendorID(adapterVendorID
[0])) ||
899 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
[0])) ||
900 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor
[0])) ||
901 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
[0])));
902 adapterInfoFailed
[1] =
903 (NS_FAILED(GetAdapterVendorID2(adapterVendorID
[1])) ||
904 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID
[1])) ||
905 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor
[1])) ||
906 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString
[1])));
907 // No point in going on if we don't have adapter info
908 if (adapterInfoFailed
[0] && adapterInfoFailed
[1]) {
912 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
913 uint64_t driverVersion
[2] = {0, 0};
914 if (!adapterInfoFailed
[0]) {
915 ParseDriverVersion(adapterDriverVersionString
[0], &driverVersion
[0]);
917 if (!adapterInfoFailed
[1]) {
918 ParseDriverVersion(adapterDriverVersionString
[1], &driverVersion
[1]);
923 for (; i
< info
.Length(); i
++) {
924 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
925 // blocklisting. Only consider entries for our search mode.
926 if (MatchingAllowStatus(info
[i
].mFeatureStatus
) != aForAllowing
) {
930 // If we don't have the info for this GPU, no need to check further.
931 // It is unclear that we would ever have a mixture of 1st and 2nd
932 // GPU, but leaving the code in for that possibility for now.
933 // (Actually, currently mGpu2 will never be true, so this can
934 // be optimized out.)
935 uint32_t infoIndex
= info
[i
].mGpu2
? 1 : 0;
936 if (adapterInfoFailed
[infoIndex
]) {
940 // Do the operating system check first, no point in getting the driver
941 // info if we won't need to use it.
942 if (!MatchingOperatingSystems(info
[i
].mOperatingSystem
, os
, osBuild
)) {
946 if (info
[i
].mOperatingSystemVersion
&&
947 info
[i
].mOperatingSystemVersion
!= OperatingSystemVersion()) {
951 if (!MatchingBattery(info
[i
].mBattery
, hasBattery
)) {
955 if (!MatchingScreenSize(info
[i
].mScreen
, mScreenPixels
)) {
959 if (!DoesDesktopEnvironmentMatch(info
[i
].mDesktopEnvironment
,
960 desktopEnvironment
)) {
964 if (!DoesWindowProtocolMatch(info
[i
].mWindowProtocol
, windowProtocol
)) {
968 if (!DoesVendorMatch(info
[i
].mAdapterVendor
, adapterVendorID
[infoIndex
])) {
972 if (!DoesDriverVendorMatch(info
[i
].mDriverVendor
,
973 adapterDriverVendor
[infoIndex
])) {
977 if (info
[i
].mDevices
&& !info
[i
].mDevices
->IsEmpty()) {
978 nsresult rv
= info
[i
].mDevices
->Contains(adapterDeviceID
[infoIndex
]);
979 if (rv
== NS_ERROR_NOT_AVAILABLE
) {
984 // Failed to search, allowlist should not match, blocklist should match
985 // for safety reasons
995 if (!info
[i
].mHardware
.IsEmpty() && !info
[i
].mHardware
.Equals(Hardware())) {
998 if (!info
[i
].mModel
.IsEmpty() && !info
[i
].mModel
.Equals(Model())) {
1001 if (!info
[i
].mProduct
.IsEmpty() && !info
[i
].mProduct
.Equals(Product())) {
1004 if (!info
[i
].mManufacturer
.IsEmpty() &&
1005 !info
[i
].mManufacturer
.Equals(Manufacturer())) {
1009 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1010 switch (info
[i
].mComparisonOp
) {
1011 case DRIVER_LESS_THAN
:
1012 match
= driverVersion
[infoIndex
] < info
[i
].mDriverVersion
;
1014 case DRIVER_BUILD_ID_LESS_THAN
:
1015 match
= (driverVersion
[infoIndex
] & 0xFFFF) < info
[i
].mDriverVersion
;
1017 case DRIVER_LESS_THAN_OR_EQUAL
:
1018 match
= driverVersion
[infoIndex
] <= info
[i
].mDriverVersion
;
1020 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
:
1021 match
= (driverVersion
[infoIndex
] & 0xFFFF) <= info
[i
].mDriverVersion
;
1023 case DRIVER_GREATER_THAN
:
1024 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
;
1026 case DRIVER_GREATER_THAN_OR_EQUAL
:
1027 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
;
1030 match
= driverVersion
[infoIndex
] == info
[i
].mDriverVersion
;
1032 case DRIVER_NOT_EQUAL
:
1033 match
= driverVersion
[infoIndex
] != info
[i
].mDriverVersion
;
1035 case DRIVER_BETWEEN_EXCLUSIVE
:
1036 match
= driverVersion
[infoIndex
] > info
[i
].mDriverVersion
&&
1037 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1039 case DRIVER_BETWEEN_INCLUSIVE
:
1040 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1041 driverVersion
[infoIndex
] <= info
[i
].mDriverVersionMax
;
1043 case DRIVER_BETWEEN_INCLUSIVE_START
:
1044 match
= driverVersion
[infoIndex
] >= info
[i
].mDriverVersion
&&
1045 driverVersion
[infoIndex
] < info
[i
].mDriverVersionMax
;
1047 case DRIVER_COMPARISON_IGNORED
:
1048 // We don't have a comparison op, so we match everything.
1052 NS_WARNING("Bogus op in GfxDriverInfo");
1056 // We don't care what driver version it was. We only check OS version and if
1057 // the device matches.
1061 if (match
|| info
[i
].mDriverVersion
== GfxDriverInfo::allDriverVersions
) {
1062 if ((info
[i
].mFeature
== GfxDriverInfo::allFeatures
&&
1063 aFeature
!= nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
) ||
1064 info
[i
].mFeature
== aFeature
) {
1065 status
= info
[i
].mFeatureStatus
;
1066 if (!info
[i
].mRuleId
.IsEmpty()) {
1067 aFailureId
= info
[i
].mRuleId
.get();
1069 aFailureId
= "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1077 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1078 // as either the primary or secondary adapter. D2D is also blocked when the
1079 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1080 // If the primary GPU already matched something in the blocklist then we
1081 // ignore this special rule. See bug 1008759.
1082 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
&&
1083 (aFeature
== nsIGfxInfo::FEATURE_DIRECT2D
)) {
1084 if (!adapterInfoFailed
[1]) {
1085 nsAString
& nvVendorID
=
1086 (nsAString
&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA
);
1087 const nsString nv310mDeviceId
= u
"0x0A70"_ns
;
1088 if (nvVendorID
.Equals(adapterVendorID
[1],
1089 nsCaseInsensitiveStringComparator
) &&
1090 nv310mDeviceId
.Equals(adapterDeviceID
[1],
1091 nsCaseInsensitiveStringComparator
)) {
1092 status
= nsIGfxInfo::FEATURE_BLOCKED_DEVICE
;
1093 aFailureId
= "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1098 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1099 // back to the Windows handler, so we must handle this here.
1100 if (status
== FEATURE_BLOCKED_DRIVER_VERSION
) {
1101 if (info
[i
].mSuggestedVersion
) {
1102 aSuggestedVersion
.AppendPrintf("%s", info
[i
].mSuggestedVersion
);
1103 } else if (info
[i
].mComparisonOp
== DRIVER_LESS_THAN
&&
1104 info
[i
].mDriverVersion
!= GfxDriverInfo::allDriverVersions
) {
1105 aSuggestedVersion
.AppendPrintf(
1106 "%lld.%lld.%lld.%lld",
1107 (info
[i
].mDriverVersion
& 0xffff000000000000) >> 48,
1108 (info
[i
].mDriverVersion
& 0x0000ffff00000000) >> 32,
1109 (info
[i
].mDriverVersion
& 0x00000000ffff0000) >> 16,
1110 (info
[i
].mDriverVersion
& 0x000000000000ffff));
1118 void GfxInfoBase::SetFeatureStatus(nsTArray
<gfx::GfxInfoFeatureStatus
>&& aFS
) {
1119 MOZ_ASSERT(!sFeatureStatus
);
1120 InitFeatureStatus(new nsTArray
<gfx::GfxInfoFeatureStatus
>(std::move(aFS
)));
1123 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1124 const nsAString
& aBlocklistDesktop
, const nsAString
& aDesktopEnv
) {
1125 return aBlocklistDesktop
.Equals(aDesktopEnv
,
1126 nsCaseInsensitiveStringComparator
) ||
1127 aBlocklistDesktop
.Equals(
1128 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All
),
1129 nsCaseInsensitiveStringComparator
);
1132 bool GfxInfoBase::DoesWindowProtocolMatch(
1133 const nsAString
& aBlocklistWindowProtocol
,
1134 const nsAString
& aWindowProtocol
) {
1135 return aBlocklistWindowProtocol
.Equals(aWindowProtocol
,
1136 nsCaseInsensitiveStringComparator
) ||
1137 aBlocklistWindowProtocol
.Equals(
1138 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All
),
1139 nsCaseInsensitiveStringComparator
);
1142 bool GfxInfoBase::DoesVendorMatch(const nsAString
& aBlocklistVendor
,
1143 const nsAString
& aAdapterVendor
) {
1144 return aBlocklistVendor
.Equals(aAdapterVendor
,
1145 nsCaseInsensitiveStringComparator
) ||
1146 aBlocklistVendor
.Equals(
1147 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All
),
1148 nsCaseInsensitiveStringComparator
);
1151 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
1152 const nsAString
& aDriverVendor
) {
1153 return aBlocklistVendor
.Equals(aDriverVendor
,
1154 nsCaseInsensitiveStringComparator
) ||
1155 aBlocklistVendor
.Equals(
1156 GfxDriverInfo::GetDriverVendor(DriverVendor::All
),
1157 nsCaseInsensitiveStringComparator
);
1160 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature
) const {
1161 return aFeature
== nsIGfxInfo::FEATURE_WEBRENDER
||
1162 aFeature
== nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
;
1165 nsresult
GfxInfoBase::GetFeatureStatusImpl(
1166 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedVersion
,
1167 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
1168 OperatingSystem
* aOS
/* = nullptr */) {
1169 if (aFeature
<= 0) {
1170 gfxWarning() << "Invalid feature <= 0";
1174 if (*aStatus
!= nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1175 // Terminate now with the status determined by the derived type (OS-specific
1180 if (sShutdownOccurred
) {
1181 // This is futile; we've already commenced shutdown and our blocklists have
1182 // been deleted. We may want to look into resurrecting the blocklist instead
1183 // but for now, just don't even go there.
1187 // Ensure any additional initialization required is complete.
1190 // If an operating system was provided by the derived GetFeatureStatusImpl,
1191 // grab it here. Otherwise, the OS is unknown.
1192 OperatingSystem os
= (aOS
? *aOS
: OperatingSystem::Unknown
);
1194 nsAutoString adapterVendorID
;
1195 nsAutoString adapterDeviceID
;
1196 nsAutoString adapterDriverVersionString
;
1197 if (NS_FAILED(GetAdapterVendorID(adapterVendorID
)) ||
1198 NS_FAILED(GetAdapterDeviceID(adapterDeviceID
)) ||
1199 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString
))) {
1200 aFailureId
= "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1201 *aStatus
= FEATURE_BLOCKED_DEVICE
;
1205 // Check if the device is blocked from the downloaded blocklist. If not, check
1206 // the static list after that. This order is used so that we can later escape
1207 // out of static blocks (i.e. if we were wrong or something was patched, we
1208 // can back out our static block without doing a release).
1210 if (aDriverInfo
.Length()) {
1212 FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
, aFeature
,
1213 aFailureId
, os
, /* aForAllowing */ false);
1216 sDriverInfo
= new nsTArray
<GfxDriverInfo
>();
1218 status
= FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion
,
1219 aFeature
, aFailureId
, os
,
1220 /* aForAllowing */ false);
1223 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1224 if (IsFeatureAllowlisted(aFeature
)) {
1225 // This feature is actually using the allowlist; that means after we pass
1226 // the blocklist to prevent us explicitly from getting the feature, we now
1227 // need to check the allowlist to ensure we are allowed to get it in the
1229 if (aDriverInfo
.Length()) {
1230 status
= FindBlocklistedDeviceInList(aDriverInfo
, aSuggestedVersion
,
1231 aFeature
, aFailureId
, os
,
1232 /* aForAllowing */ true);
1234 status
= FindBlocklistedDeviceInList(
1235 GetGfxDriverInfo(), aSuggestedVersion
, aFeature
, aFailureId
, os
,
1236 /* aForAllowing */ true);
1239 if (status
== nsIGfxInfo::FEATURE_STATUS_UNKNOWN
) {
1240 status
= nsIGfxInfo::FEATURE_DENIED
;
1243 // It's now done being processed. It's safe to set the status to
1245 status
= nsIGfxInfo::FEATURE_STATUS_OK
;
1254 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature
,
1255 nsAString
& aVersion
) {
1257 if (GetPrefValueForDriverVersion(version
)) {
1258 aVersion
= NS_ConvertASCIItoUTF16(version
);
1263 nsCString discardFailureId
;
1264 nsTArray
<GfxDriverInfo
> driverInfo
;
1265 return GetFeatureStatusImpl(aFeature
, &status
, aVersion
, driverInfo
,
1269 void GfxInfoBase::EvaluateDownloadedBlocklist(
1270 nsTArray
<GfxDriverInfo
>& aDriverInfo
) {
1271 int32_t features
[] = {nsIGfxInfo::FEATURE_DIRECT2D
,
1272 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS
,
1273 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS
,
1274 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS
,
1275 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS
,
1276 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE
,
1277 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
,
1278 nsIGfxInfo::FEATURE_OPENGL_LAYERS
,
1279 nsIGfxInfo::FEATURE_WEBGL_OPENGL
,
1280 nsIGfxInfo::FEATURE_WEBGL_ANGLE
,
1281 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE
,
1282 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE
,
1283 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA
,
1284 nsIGfxInfo::FEATURE_STAGEFRIGHT
,
1285 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264
,
1286 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION
,
1287 nsIGfxInfo::FEATURE_VP8_HW_DECODE
,
1288 nsIGfxInfo::FEATURE_VP9_HW_DECODE
,
1289 nsIGfxInfo::FEATURE_DX_INTEROP2
,
1290 nsIGfxInfo::FEATURE_GPU_PROCESS
,
1291 nsIGfxInfo::FEATURE_WEBGL2
,
1292 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
1293 nsIGfxInfo::FEATURE_WEBRENDER
,
1294 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR
,
1295 nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE
,
1296 nsIGfxInfo::FEATURE_DX_NV12
,
1297 nsIGfxInfo::FEATURE_DX_P010
,
1298 nsIGfxInfo::FEATURE_DX_P016
,
1299 nsIGfxInfo::FEATURE_GL_SWIZZLE
,
1300 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
,
1301 nsIGfxInfo::FEATURE_X11_EGL
,
1302 nsIGfxInfo::FEATURE_DMABUF
,
1305 // For every feature we know about, we evaluate whether this blocklist has a
1306 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1307 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1308 // anywhere permanent.
1310 while (features
[i
]) {
1312 nsCString failureId
;
1313 nsAutoString suggestedVersion
;
1314 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1315 features
[i
], &status
, suggestedVersion
, aDriverInfo
, failureId
))) {
1318 case nsIGfxInfo::FEATURE_STATUS_OK
:
1319 RemovePrefForFeature(features
[i
]);
1322 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION
:
1323 if (!suggestedVersion
.IsEmpty()) {
1324 SetPrefValueForDriverVersion(suggestedVersion
);
1326 RemovePrefForDriverVersion();
1330 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION
:
1331 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE
:
1332 case nsIGfxInfo::FEATURE_DISCOURAGED
:
1333 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION
:
1334 SetPrefValueForFeature(features
[i
], status
, failureId
);
1343 NS_IMETHODIMP_(void)
1344 GfxInfoBase::LogFailure(const nsACString
& failure
) {
1345 // gfxCriticalError has a mutex lock of its own, so we may not actually
1346 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1347 // will not return the copy of the logs unless it can get the same lock
1348 // that gfxCriticalError uses. Still, that is so much of an implementation
1349 // detail that it's nicer to just add an extra lock here and in
1351 MutexAutoLock
lock(mMutex
);
1353 // By default, gfxCriticalError asserts; make it not assert in this case.
1354 gfxCriticalError(CriticalLog::DefaultOptions(false))
1355 << "(LF) " << failure
.BeginReading();
1358 NS_IMETHODIMP
GfxInfoBase::GetFailures(nsTArray
<int32_t>& indices
,
1359 nsTArray
<nsCString
>& failures
) {
1360 MutexAutoLock
lock(mMutex
);
1362 LogForwarder
* logForwarder
= Factory::GetLogForwarder();
1363 if (!logForwarder
) {
1364 return NS_ERROR_UNEXPECTED
;
1367 // There are two string copies in this method, starting with this one. We are
1368 // assuming this is not a big deal, as the size of the array should be small
1369 // and the strings in it should be small as well (the error messages in the
1370 // code.) The second copy happens with the AppendElement() calls.
1371 // Technically, we don't need the mutex lock after the StringVectorCopy()
1373 LoggingRecord loggedStrings
= logForwarder
->LoggingRecordCopy();
1374 LoggingRecord::const_iterator it
;
1375 for (it
= loggedStrings
.begin(); it
!= loggedStrings
.end(); ++it
) {
1376 failures
.AppendElement(
1377 nsDependentCSubstring(Get
<1>(*it
).c_str(), Get
<1>(*it
).size()));
1378 indices
.AppendElement(Get
<0>(*it
));
1384 nsTArray
<GfxInfoCollectorBase
*>* sCollectors
;
1386 static void InitCollectors() {
1387 if (!sCollectors
) sCollectors
= new nsTArray
<GfxInfoCollectorBase
*>;
1390 nsresult
GfxInfoBase::GetInfo(JSContext
* aCx
,
1391 JS::MutableHandle
<JS::Value
> aResult
) {
1393 InfoObject
obj(aCx
);
1395 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1396 (*sCollectors
)[i
]->GetInfo(obj
);
1399 // Some example property definitions
1400 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1401 // obj.DefineProperty("renderer", mRendererIDsString);
1402 // obj.DefineProperty("five", 5);
1405 return NS_ERROR_FAILURE
;
1408 aResult
.setObject(*obj
.mObj
);
1412 nsAutoCString gBaseAppVersion
;
1414 const nsCString
& GfxInfoBase::GetApplicationVersion() {
1415 static bool versionInitialized
= false;
1416 if (!versionInitialized
) {
1417 // If we fail to get the version, we will not try again.
1418 versionInitialized
= true;
1420 // Get the version from xpcom/system/nsIXULAppInfo.idl
1421 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
1423 app
->GetVersion(gBaseAppVersion
);
1426 return gBaseAppVersion
;
1429 void GfxInfoBase::AddCollector(GfxInfoCollectorBase
* collector
) {
1431 sCollectors
->AppendElement(collector
);
1434 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase
* collector
) {
1436 for (uint32_t i
= 0; i
< sCollectors
->Length(); i
++) {
1437 if ((*sCollectors
)[i
] == collector
) {
1438 sCollectors
->RemoveElementAt(i
);
1442 if (sCollectors
->IsEmpty()) {
1444 sCollectors
= nullptr;
1448 nsresult
GfxInfoBase::FindMonitors(JSContext
* aCx
, JS::HandleObject aOutArray
) {
1449 // If we have no platform specific implementation for detecting monitors, we
1450 // can just get the screen size from gfxPlatform as the best guess.
1451 if (!gfxPlatform::Initialized()) {
1455 // If the screen size is empty, we are probably in xpcshell.
1456 gfx::IntSize screenSize
= gfxPlatform::GetPlatform()->GetScreenSize();
1458 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1460 JS::Rooted
<JS::Value
> screenWidth(aCx
, JS::Int32Value(screenSize
.width
));
1461 JS_SetProperty(aCx
, obj
, "screenWidth", screenWidth
);
1463 JS::Rooted
<JS::Value
> screenHeight(aCx
, JS::Int32Value(screenSize
.height
));
1464 JS_SetProperty(aCx
, obj
, "screenHeight", screenHeight
);
1466 JS::Rooted
<JS::Value
> element(aCx
, JS::ObjectValue(*obj
));
1467 JS_SetElement(aCx
, aOutArray
, 0, element
);
1473 GfxInfoBase::GetMonitors(JSContext
* aCx
, JS::MutableHandleValue aResult
) {
1474 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1476 nsresult rv
= FindMonitors(aCx
, array
);
1477 if (NS_FAILED(rv
)) {
1481 aResult
.setObject(*array
);
1486 GfxInfoBase::RefreshMonitors() { return NS_ERROR_NOT_IMPLEMENTED
; }
1488 static inline bool SetJSPropertyString(JSContext
* aCx
,
1489 JS::Handle
<JSObject
*> aObj
,
1490 const char* aProp
, const char* aString
) {
1491 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, aString
));
1496 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1497 return JS_SetProperty(aCx
, aObj
, aProp
, val
);
1500 template <typename T
>
1501 static inline bool AppendJSElement(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1504 if (!JS::GetArrayLength(aCx
, aObj
, &index
)) {
1507 return JS_SetElement(aCx
, aObj
, index
, aValue
);
1510 nsresult
GfxInfoBase::GetFeatures(JSContext
* aCx
,
1511 JS::MutableHandle
<JS::Value
> aOut
) {
1512 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1514 return NS_ERROR_OUT_OF_MEMORY
;
1516 aOut
.setObject(*obj
);
1518 layers::LayersBackend backend
=
1519 gfxPlatform::Initialized()
1520 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1521 : layers::LayersBackend::LAYERS_NONE
;
1522 const char* backendName
= layers::GetLayersBackendName(backend
);
1523 SetJSPropertyString(aCx
, obj
, "compositor", backendName
);
1525 // If graphics isn't initialized yet, just stop now.
1526 if (!gfxPlatform::Initialized()) {
1530 DescribeFeatures(aCx
, obj
);
1534 nsresult
GfxInfoBase::GetFeatureLog(JSContext
* aCx
,
1535 JS::MutableHandle
<JS::Value
> aOut
) {
1536 JS::Rooted
<JSObject
*> containerObj(aCx
, JS_NewPlainObject(aCx
));
1537 if (!containerObj
) {
1538 return NS_ERROR_OUT_OF_MEMORY
;
1540 aOut
.setObject(*containerObj
);
1542 JS::Rooted
<JSObject
*> featureArray(aCx
, JS::NewArrayObject(aCx
, 0));
1543 if (!featureArray
) {
1544 return NS_ERROR_OUT_OF_MEMORY
;
1547 // Collect features.
1548 gfxConfig::ForEachFeature([&](const char* aName
, const char* aDescription
,
1549 FeatureState
& aFeature
) -> void {
1550 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1554 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1555 !SetJSPropertyString(aCx
, obj
, "description", aDescription
) ||
1556 !SetJSPropertyString(aCx
, obj
, "status",
1557 FeatureStatusToString(aFeature
.GetValue()))) {
1561 JS::Rooted
<JS::Value
> log(aCx
);
1562 if (!BuildFeatureStateLog(aCx
, aFeature
, &log
)) {
1565 if (!JS_SetProperty(aCx
, obj
, "log", log
)) {
1569 if (!AppendJSElement(aCx
, featureArray
, obj
)) {
1574 JS::Rooted
<JSObject
*> fallbackArray(aCx
, JS::NewArrayObject(aCx
, 0));
1575 if (!fallbackArray
) {
1576 return NS_ERROR_OUT_OF_MEMORY
;
1579 // Collect fallbacks.
1580 gfxConfig::ForEachFallback(
1581 [&](const char* aName
, const char* aMessage
) -> void {
1582 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1587 if (!SetJSPropertyString(aCx
, obj
, "name", aName
) ||
1588 !SetJSPropertyString(aCx
, obj
, "message", aMessage
)) {
1592 if (!AppendJSElement(aCx
, fallbackArray
, obj
)) {
1597 JS::Rooted
<JS::Value
> val(aCx
);
1599 val
= JS::ObjectValue(*featureArray
);
1600 JS_SetProperty(aCx
, containerObj
, "features", val
);
1602 val
= JS::ObjectValue(*fallbackArray
);
1603 JS_SetProperty(aCx
, containerObj
, "fallbacks", val
);
1608 bool GfxInfoBase::BuildFeatureStateLog(JSContext
* aCx
,
1609 const FeatureState
& aFeature
,
1610 JS::MutableHandle
<JS::Value
> aOut
) {
1611 JS::Rooted
<JSObject
*> log(aCx
, JS::NewArrayObject(aCx
, 0));
1615 aOut
.setObject(*log
);
1617 aFeature
.ForEachStatusChange([&](const char* aType
, FeatureStatus aStatus
,
1618 const char* aMessage
,
1619 const nsCString
& aFailureId
) -> void {
1620 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1625 if (!SetJSPropertyString(aCx
, obj
, "type", aType
) ||
1626 !SetJSPropertyString(aCx
, obj
, "status",
1627 FeatureStatusToString(aStatus
)) ||
1628 (aMessage
&& !SetJSPropertyString(aCx
, obj
, "message", aMessage
))) {
1632 if (!AppendJSElement(aCx
, log
, obj
)) {
1640 void GfxInfoBase::DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
) {
1641 JS::Rooted
<JSObject
*> obj(aCx
);
1643 gfx::FeatureState
& hwCompositing
=
1644 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING
);
1645 InitFeatureObject(aCx
, aObj
, "hwCompositing", hwCompositing
, &obj
);
1647 gfx::FeatureState
& gpuProcess
=
1648 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS
);
1649 InitFeatureObject(aCx
, aObj
, "gpuProcess", gpuProcess
, &obj
);
1651 gfx::FeatureState
& wrQualified
=
1652 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_QUALIFIED
);
1653 InitFeatureObject(aCx
, aObj
, "wrQualified", wrQualified
, &obj
);
1655 gfx::FeatureState
& webrender
= gfxConfig::GetFeature(gfx::Feature::WEBRENDER
);
1656 InitFeatureObject(aCx
, aObj
, "webrender", webrender
, &obj
);
1658 gfx::FeatureState
& wrCompositor
=
1659 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR
);
1660 InitFeatureObject(aCx
, aObj
, "wrCompositor", wrCompositor
, &obj
);
1662 gfx::FeatureState
& wrSoftware
=
1663 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_SOFTWARE
);
1664 InitFeatureObject(aCx
, aObj
, "wrSoftware", wrSoftware
, &obj
);
1666 gfx::FeatureState
& openglCompositing
=
1667 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING
);
1668 InitFeatureObject(aCx
, aObj
, "openglCompositing", openglCompositing
, &obj
);
1670 gfx::FeatureState
& omtp
= gfxConfig::GetFeature(gfx::Feature::OMTP
);
1671 InitFeatureObject(aCx
, aObj
, "omtp", omtp
, &obj
);
1674 bool GfxInfoBase::InitFeatureObject(JSContext
* aCx
,
1675 JS::Handle
<JSObject
*> aContainer
,
1677 mozilla::gfx::FeatureState
& aFeatureState
,
1678 JS::MutableHandle
<JSObject
*> aOutObj
) {
1679 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1684 nsCString status
= aFeatureState
.GetStatusAndFailureIdString();
1686 JS::Rooted
<JSString
*> str(aCx
, JS_NewStringCopyZ(aCx
, status
.get()));
1687 JS::Rooted
<JS::Value
> val(aCx
, JS::StringValue(str
));
1688 JS_SetProperty(aCx
, obj
, "status", val
);
1690 // Add the feature object to the container.
1692 JS::Rooted
<JS::Value
> val(aCx
, JS::ObjectValue(*obj
));
1693 JS_SetProperty(aCx
, aContainer
, aName
, val
);
1700 nsresult
GfxInfoBase::GetActiveCrashGuards(JSContext
* aCx
,
1701 JS::MutableHandle
<JS::Value
> aOut
) {
1702 JS::Rooted
<JSObject
*> array(aCx
, JS::NewArrayObject(aCx
, 0));
1704 return NS_ERROR_OUT_OF_MEMORY
;
1706 aOut
.setObject(*array
);
1708 DriverCrashGuard::ForEachActiveCrashGuard(
1709 [&](const char* aName
, const char* aPrefName
) -> void {
1710 JS::Rooted
<JSObject
*> obj(aCx
, JS_NewPlainObject(aCx
));
1714 if (!SetJSPropertyString(aCx
, obj
, "type", aName
)) {
1717 if (!SetJSPropertyString(aCx
, obj
, "prefName", aPrefName
)) {
1720 if (!AppendJSElement(aCx
, array
, obj
)) {
1729 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled
) {
1730 *aWebRenderEnabled
= gfxVars::UseWebRender();
1735 GfxInfoBase::GetUsesTiling(bool* aUsesTiling
) {
1736 *aUsesTiling
= gfxPlatform::GetPlatform()->UsesTiling();
1741 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling
) {
1742 *aUsesTiling
= gfxPlatform::GetPlatform()->ContentUsesTiling();
1747 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled
) {
1748 *aOffMainThreadPaintEnabled
= gfxConfig::IsEnabled(gfx::Feature::OMTP
);
1753 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1754 int32_t* aOffMainThreadPaintWorkerCount
) {
1755 if (gfxConfig::IsEnabled(gfx::Feature::OMTP
)) {
1756 *aOffMainThreadPaintWorkerCount
=
1757 layers::PaintThread::CalculatePaintWorkerCount();
1759 *aOffMainThreadPaintWorkerCount
= 0;
1765 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate
) {
1766 *aTargetFrameRate
= gfxPlatform::TargetFrameRate();
1771 GfxInfoBase::GetIsHeadless(bool* aIsHeadless
) {
1772 *aIsHeadless
= gfxPlatform::IsHeadless();
1777 GfxInfoBase::GetContentBackend(nsAString
& aContentBackend
) {
1778 BackendType backend
= gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1782 case BackendType::DIRECT2D1_1
: {
1783 outStr
.AppendPrintf("Direct2D 1.1");
1786 case BackendType::SKIA
: {
1787 outStr
.AppendPrintf("Skia");
1790 case BackendType::CAIRO
: {
1791 outStr
.AppendPrintf("Cairo");
1795 return NS_ERROR_FAILURE
;
1798 aContentBackend
.Assign(outStr
);
1803 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue
) {
1804 GPUProcessManager
* gpu
= GPUProcessManager::Get();
1806 // Not supported in content processes.
1807 return NS_ERROR_FAILURE
;
1810 *aOutValue
= !!gpu
->GetGPUChild();
1815 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) {
1816 gfxPlatform::GetPlatform();
1818 GPUProcessManager
* gpm
= GPUProcessManager::Get();
1820 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS
)) {
1821 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1823 gpm
->LaunchGPUProcess();
1824 gpm
->EnsureGPUReady();
1826 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS
, "xpcshell-test");
1834 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1835 GfxInfoBase::AddCollector(this);
1838 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1839 GfxInfoBase::RemoveCollector(this);