Bug 1829047 - do not schedule task if all tests are skipped. r=ahal
[gecko.git] / widget / GfxInfoBase.cpp
blob233a8c0eb140a7c512cc71c13bd78755b4bc1c03
1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/ArrayUtils.h"
10 #include "GfxInfoBase.h"
12 #include <mutex> // std::call_once
14 #include "GfxDriverInfo.h"
15 #include "js/Array.h" // JS::GetArrayLength, JS::NewArrayObject
16 #include "js/PropertyAndElement.h" // JS_SetElement, JS_SetProperty
17 #include "nsCOMPtr.h"
18 #include "nsCOMArray.h"
19 #include "nsString.h"
20 #include "nsUnicharUtils.h"
21 #include "nsVersionComparator.h"
22 #include "mozilla/Services.h"
23 #include "mozilla/Observer.h"
24 #include "nsIObserver.h"
25 #include "nsIObserverService.h"
26 #include "nsTArray.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/widget/ScreenManager.h"
37 #include "mozilla/widget/Screen.h"
39 #include "jsapi.h"
41 #include "gfxPlatform.h"
42 #include "gfxConfig.h"
43 #include "DriverCrashGuard.h"
45 using namespace mozilla::widget;
46 using namespace mozilla;
47 using mozilla::MutexAutoLock;
49 nsTArray<GfxDriverInfo>* GfxInfoBase::sDriverInfo;
50 StaticAutoPtr<nsTArray<gfx::GfxInfoFeatureStatus>> GfxInfoBase::sFeatureStatus;
51 bool GfxInfoBase::sDriverInfoObserverInitialized;
52 bool GfxInfoBase::sShutdownOccurred;
54 // Call this when setting sFeatureStatus to a non-null pointer to
55 // ensure destruction even if the GfxInfo component is never instantiated.
56 static void InitFeatureStatus(nsTArray<gfx::GfxInfoFeatureStatus>* aPtr) {
57 static std::once_flag sOnce;
58 std::call_once(sOnce, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus); });
59 GfxInfoBase::sFeatureStatus = aPtr;
62 // Observes for shutdown so that the child GfxDriverInfo list is freed.
63 class ShutdownObserver : public nsIObserver {
64 virtual ~ShutdownObserver() = default;
66 public:
67 ShutdownObserver() = default;
69 NS_DECL_ISUPPORTS
71 NS_IMETHOD Observe(nsISupports* subject, const char* aTopic,
72 const char16_t* aData) override {
73 MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
75 delete GfxInfoBase::sDriverInfo;
76 GfxInfoBase::sDriverInfo = nullptr;
78 for (auto& deviceFamily : GfxDriverInfo::sDeviceFamilies) {
79 delete deviceFamily;
80 deviceFamily = nullptr;
83 for (auto& windowProtocol : GfxDriverInfo::sWindowProtocol) {
84 delete windowProtocol;
85 windowProtocol = nullptr;
88 for (auto& deviceVendor : GfxDriverInfo::sDeviceVendors) {
89 delete deviceVendor;
90 deviceVendor = nullptr;
93 for (auto& driverVendor : GfxDriverInfo::sDriverVendors) {
94 delete driverVendor;
95 driverVendor = nullptr;
98 GfxInfoBase::sShutdownOccurred = true;
100 return NS_OK;
104 NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
106 static void InitGfxDriverInfoShutdownObserver() {
107 if (GfxInfoBase::sDriverInfoObserverInitialized) return;
109 GfxInfoBase::sDriverInfoObserverInitialized = true;
111 nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
112 if (!observerService) {
113 NS_WARNING("Could not get observer service!");
114 return;
117 ShutdownObserver* obs = new ShutdownObserver();
118 observerService->AddObserver(obs, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
121 using namespace mozilla::widget;
122 using namespace mozilla::gfx;
123 using namespace mozilla;
125 NS_IMPL_ISUPPORTS(GfxInfoBase, nsIGfxInfo, nsIObserver,
126 nsISupportsWeakReference)
128 #define BLOCKLIST_PREF_BRANCH "gfx.blacklist."
129 #define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
131 static const char* GetPrefNameForFeature(int32_t aFeature) {
132 const char* name = nullptr;
133 switch (aFeature) {
134 case nsIGfxInfo::FEATURE_DIRECT2D:
135 name = BLOCKLIST_PREF_BRANCH "direct2d";
136 break;
137 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
138 name = BLOCKLIST_PREF_BRANCH "layers.direct3d9";
139 break;
140 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
141 name = BLOCKLIST_PREF_BRANCH "layers.direct3d10";
142 break;
143 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
144 name = BLOCKLIST_PREF_BRANCH "layers.direct3d10-1";
145 break;
146 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS:
147 name = BLOCKLIST_PREF_BRANCH "layers.direct3d11";
148 break;
149 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE:
150 name = BLOCKLIST_PREF_BRANCH "direct3d11angle";
151 break;
152 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING:
153 name = BLOCKLIST_PREF_BRANCH "hardwarevideodecoding";
154 break;
155 case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
156 name = BLOCKLIST_PREF_BRANCH "layers.opengl";
157 break;
158 case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
159 name = BLOCKLIST_PREF_BRANCH "webgl.opengl";
160 break;
161 case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
162 name = BLOCKLIST_PREF_BRANCH "webgl.angle";
163 break;
164 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA:
165 name = BLOCKLIST_PREF_BRANCH "webgl.msaa";
166 break;
167 case nsIGfxInfo::FEATURE_STAGEFRIGHT:
168 name = BLOCKLIST_PREF_BRANCH "stagefright";
169 break;
170 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264:
171 name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.h264";
172 break;
173 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE:
174 name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.encode";
175 break;
176 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE:
177 name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.decode";
178 break;
179 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION:
180 name = BLOCKLIST_PREF_BRANCH "canvas2d.acceleration";
181 break;
182 case nsIGfxInfo::FEATURE_DX_INTEROP2:
183 name = BLOCKLIST_PREF_BRANCH "dx.interop2";
184 break;
185 case nsIGfxInfo::FEATURE_GPU_PROCESS:
186 name = BLOCKLIST_PREF_BRANCH "gpu.process";
187 break;
188 case nsIGfxInfo::FEATURE_WEBGL2:
189 name = BLOCKLIST_PREF_BRANCH "webgl2";
190 break;
191 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX:
192 name = BLOCKLIST_PREF_BRANCH "d3d11.keyed.mutex";
193 break;
194 case nsIGfxInfo::FEATURE_WEBRENDER:
195 name = BLOCKLIST_PREF_BRANCH "webrender";
196 break;
197 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR:
198 name = BLOCKLIST_PREF_BRANCH "webrender.compositor";
199 break;
200 case nsIGfxInfo::FEATURE_DX_NV12:
201 name = BLOCKLIST_PREF_BRANCH "dx.nv12";
202 break;
203 case nsIGfxInfo::FEATURE_DX_P010:
204 name = BLOCKLIST_PREF_BRANCH "dx.p010";
205 break;
206 case nsIGfxInfo::FEATURE_DX_P016:
207 name = BLOCKLIST_PREF_BRANCH "dx.p016";
208 break;
209 case nsIGfxInfo::FEATURE_VP8_HW_DECODE:
210 name = BLOCKLIST_PREF_BRANCH "vp8.hw-decode";
211 break;
212 case nsIGfxInfo::FEATURE_VP9_HW_DECODE:
213 name = BLOCKLIST_PREF_BRANCH "vp9.hw-decode";
214 break;
215 case nsIGfxInfo::FEATURE_GL_SWIZZLE:
216 name = BLOCKLIST_PREF_BRANCH "gl.swizzle";
217 break;
218 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS:
219 name = BLOCKLIST_PREF_BRANCH "webrender.scissored_cache_clears";
220 break;
221 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS:
222 name = BLOCKLIST_PREF_BRANCH "webgl.allow-oop";
223 break;
224 case nsIGfxInfo::FEATURE_THREADSAFE_GL:
225 name = BLOCKLIST_PREF_BRANCH "gl.threadsafe";
226 break;
227 case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS:
228 name = BLOCKLIST_PREF_BRANCH "webrender.optimized-shaders";
229 break;
230 case nsIGfxInfo::FEATURE_X11_EGL:
231 name = BLOCKLIST_PREF_BRANCH "x11.egl";
232 break;
233 case nsIGfxInfo::FEATURE_DMABUF:
234 name = BLOCKLIST_PREF_BRANCH "dmabuf";
235 break;
236 case nsIGfxInfo::FEATURE_WEBGPU:
237 name = BLOCKLIST_PREF_BRANCH "webgpu";
238 break;
239 case nsIGfxInfo::FEATURE_VIDEO_OVERLAY:
240 name = BLOCKLIST_PREF_BRANCH "video-overlay";
241 break;
242 case nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY:
243 name = BLOCKLIST_PREF_BRANCH "hw-video-zero-copy";
244 break;
245 case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE:
246 name = BLOCKLIST_PREF_BRANCH "webrender.program-binary-disk";
247 break;
248 case nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT:
249 name = BLOCKLIST_PREF_BRANCH "webrender.partial-present";
250 break;
251 case nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT:
252 name = BLOCKLIST_PREF_BRANCH "dmabuf.surface-export";
253 break;
254 case nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE:
255 name = BLOCKLIST_PREF_BRANCH "reuse-decoder-device";
256 break;
257 case nsIGfxInfo::FEATURE_BACKDROP_FILTER:
258 name = BLOCKLIST_PREF_BRANCH "backdrop.filter";
259 break;
260 case nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D:
261 name = BLOCKLIST_PREF_BRANCH "accelerated-canvas2d";
262 break;
263 default:
264 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
265 break;
268 return name;
271 // Returns the value of the pref for the relevant feature in aValue.
272 // If the pref doesn't exist, aValue is not touched, and returns false.
273 static bool GetPrefValueForFeature(int32_t aFeature, int32_t& aValue,
274 nsACString& aFailureId) {
275 const char* prefname = GetPrefNameForFeature(aFeature);
276 if (!prefname) return false;
278 aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
279 if (!NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue))) {
280 return false;
283 if (aValue == nsIGfxInfo::FEATURE_DENIED) {
284 // We should never see the DENIED status with the downloadable blocklist.
285 return false;
288 nsCString failureprefname(prefname);
289 failureprefname += ".failureid";
290 nsAutoCString failureValue;
291 nsresult rv = Preferences::GetCString(failureprefname.get(), failureValue);
292 if (NS_SUCCEEDED(rv)) {
293 aFailureId = failureValue.get();
294 } else {
295 aFailureId = "FEATURE_FAILURE_BLOCKLIST_PREF";
298 return true;
301 static void SetPrefValueForFeature(int32_t aFeature, int32_t aValue,
302 const nsACString& aFailureId) {
303 const char* prefname = GetPrefNameForFeature(aFeature);
304 if (!prefname) return;
305 if (XRE_IsParentProcess()) {
306 GfxInfoBase::sFeatureStatus = nullptr;
309 Preferences::SetInt(prefname, aValue);
310 if (!aFailureId.IsEmpty()) {
311 nsAutoCString failureprefname(prefname);
312 failureprefname += ".failureid";
313 Preferences::SetCString(failureprefname.get(), aFailureId);
317 static void RemovePrefForFeature(int32_t aFeature) {
318 const char* prefname = GetPrefNameForFeature(aFeature);
319 if (!prefname) return;
321 if (XRE_IsParentProcess()) {
322 GfxInfoBase::sFeatureStatus = nullptr;
324 Preferences::ClearUser(prefname);
327 static bool GetPrefValueForDriverVersion(nsCString& aVersion) {
328 return NS_SUCCEEDED(
329 Preferences::GetCString(SUGGESTED_VERSION_PREF, aVersion));
332 static void SetPrefValueForDriverVersion(const nsAString& aVersion) {
333 Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion);
336 static void RemovePrefForDriverVersion() {
337 Preferences::ClearUser(SUGGESTED_VERSION_PREF);
340 static OperatingSystem BlocklistOSToOperatingSystem(const nsAString& os) {
341 if (os.EqualsLiteral("WINNT 6.1")) {
342 return OperatingSystem::Windows7;
344 if (os.EqualsLiteral("WINNT 6.2")) {
345 return OperatingSystem::Windows8;
347 if (os.EqualsLiteral("WINNT 6.3")) {
348 return OperatingSystem::Windows8_1;
350 if (os.EqualsLiteral("WINNT 10.0")) {
351 return OperatingSystem::Windows10;
353 if (os.EqualsLiteral("Linux")) {
354 return OperatingSystem::Linux;
356 if (os.EqualsLiteral("Darwin 9")) {
357 return OperatingSystem::OSX10_5;
359 if (os.EqualsLiteral("Darwin 10")) {
360 return OperatingSystem::OSX10_6;
362 if (os.EqualsLiteral("Darwin 11")) {
363 return OperatingSystem::OSX10_7;
365 if (os.EqualsLiteral("Darwin 12")) {
366 return OperatingSystem::OSX10_8;
368 if (os.EqualsLiteral("Darwin 13")) {
369 return OperatingSystem::OSX10_9;
371 if (os.EqualsLiteral("Darwin 14")) {
372 return OperatingSystem::OSX10_10;
374 if (os.EqualsLiteral("Darwin 15")) {
375 return OperatingSystem::OSX10_11;
377 if (os.EqualsLiteral("Darwin 16")) {
378 return OperatingSystem::OSX10_12;
380 if (os.EqualsLiteral("Darwin 17")) {
381 return OperatingSystem::OSX10_13;
383 if (os.EqualsLiteral("Darwin 18")) {
384 return OperatingSystem::OSX10_14;
386 if (os.EqualsLiteral("Darwin 19")) {
387 return OperatingSystem::OSX10_15;
389 if (os.EqualsLiteral("Darwin 20")) {
390 return OperatingSystem::OSX11_0;
392 if (os.EqualsLiteral("Android")) {
393 return OperatingSystem::Android;
394 // For historical reasons, "All" in blocklist means "All Windows"
396 if (os.EqualsLiteral("All")) {
397 return OperatingSystem::Windows;
399 if (os.EqualsLiteral("Darwin")) {
400 return OperatingSystem::OSX;
403 return OperatingSystem::Unknown;
406 static GfxDeviceFamily* BlocklistDevicesToDeviceFamily(
407 nsTArray<nsCString>& devices) {
408 if (devices.Length() == 0) return nullptr;
410 // For each device, get its device ID, and return a freshly-allocated
411 // GfxDeviceFamily with the contents of that array.
412 GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
414 for (uint32_t i = 0; i < devices.Length(); ++i) {
415 // We make sure we don't add any "empty" device entries to the array, so
416 // we don't need to check if devices[i] is empty.
417 deviceIds->Append(NS_ConvertUTF8toUTF16(devices[i]));
420 return deviceIds;
423 static int32_t BlocklistFeatureToGfxFeature(const nsAString& aFeature) {
424 MOZ_ASSERT(!aFeature.IsEmpty());
425 if (aFeature.EqualsLiteral("DIRECT2D")) {
426 return nsIGfxInfo::FEATURE_DIRECT2D;
428 if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS")) {
429 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
431 if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS")) {
432 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
434 if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
435 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
437 if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS")) {
438 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
440 if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE")) {
441 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
443 if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
444 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
446 if (aFeature.EqualsLiteral("OPENGL_LAYERS")) {
447 return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
449 if (aFeature.EqualsLiteral("WEBGL_OPENGL")) {
450 return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
452 if (aFeature.EqualsLiteral("WEBGL_ANGLE")) {
453 return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
455 if (aFeature.EqualsLiteral("WEBGL_MSAA")) {
456 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA;
458 if (aFeature.EqualsLiteral("STAGEFRIGHT")) {
459 return nsIGfxInfo::FEATURE_STAGEFRIGHT;
461 if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
462 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
464 if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
465 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
467 if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
468 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264;
470 if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION")) {
471 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
473 if (aFeature.EqualsLiteral("DX_INTEROP2")) {
474 return nsIGfxInfo::FEATURE_DX_INTEROP2;
476 if (aFeature.EqualsLiteral("GPU_PROCESS")) {
477 return nsIGfxInfo::FEATURE_GPU_PROCESS;
479 if (aFeature.EqualsLiteral("WEBGL2")) {
480 return nsIGfxInfo::FEATURE_WEBGL2;
482 if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX")) {
483 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
485 if (aFeature.EqualsLiteral("WEBRENDER")) {
486 return nsIGfxInfo::FEATURE_WEBRENDER;
488 if (aFeature.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
489 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR;
491 if (aFeature.EqualsLiteral("DX_NV12")) {
492 return nsIGfxInfo::FEATURE_DX_NV12;
494 if (aFeature.EqualsLiteral("VP8_HW_DECODE")) {
495 return nsIGfxInfo::FEATURE_VP8_HW_DECODE;
497 if (aFeature.EqualsLiteral("VP9_HW_DECODE")) {
498 return nsIGfxInfo::FEATURE_VP9_HW_DECODE;
500 if (aFeature.EqualsLiteral("GL_SWIZZLE")) {
501 return nsIGfxInfo::FEATURE_GL_SWIZZLE;
503 if (aFeature.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
504 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS;
506 if (aFeature.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
507 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS;
509 if (aFeature.EqualsLiteral("THREADSAFE_GL")) {
510 return nsIGfxInfo::FEATURE_THREADSAFE_GL;
512 if (aFeature.EqualsLiteral("X11_EGL")) {
513 return nsIGfxInfo::FEATURE_X11_EGL;
515 if (aFeature.EqualsLiteral("DMABUF")) {
516 return nsIGfxInfo::FEATURE_DMABUF;
518 if (aFeature.EqualsLiteral("WEBGPU")) {
519 return nsIGfxInfo::FEATURE_WEBGPU;
521 if (aFeature.EqualsLiteral("VIDEO_OVERLAY")) {
522 return nsIGfxInfo::FEATURE_VIDEO_OVERLAY;
524 if (aFeature.EqualsLiteral("HW_DECODED_VIDEO_ZERO_COPY")) {
525 return nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY;
527 if (aFeature.EqualsLiteral("REUSE_DECODER_DEVICE")) {
528 return nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE;
530 if (aFeature.EqualsLiteral("WEBRENDER_PARTIAL_PRESENT")) {
531 return nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT;
533 if (aFeature.EqualsLiteral("BACKDROP_FILTER")) {
534 return nsIGfxInfo::FEATURE_BACKDROP_FILTER;
536 if (aFeature.EqualsLiteral("ACCELERATED_CANVAS2D")) {
537 return nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D;
540 // If we don't recognize the feature, it may be new, and something
541 // this version doesn't understand. So, nothing to do. This is
542 // different from feature not being specified at all, in which case
543 // this method should not get called and we should continue with the
544 // "all features" blocklisting.
545 return -1;
548 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
549 const nsAString& aStatus) {
550 if (aStatus.EqualsLiteral("STATUS_OK")) {
551 return nsIGfxInfo::FEATURE_STATUS_OK;
553 if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
554 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
556 if (aStatus.EqualsLiteral("BLOCKED_DEVICE")) {
557 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
559 if (aStatus.EqualsLiteral("DISCOURAGED")) {
560 return nsIGfxInfo::FEATURE_DISCOURAGED;
562 if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION")) {
563 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
565 if (aStatus.EqualsLiteral("DENIED")) {
566 return nsIGfxInfo::FEATURE_DENIED;
568 if (aStatus.EqualsLiteral("ALLOW_QUALIFIED")) {
569 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
571 if (aStatus.EqualsLiteral("ALLOW_ALWAYS")) {
572 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
575 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
576 // expecting the "mismatch" status showing up here.
578 return nsIGfxInfo::FEATURE_STATUS_OK;
581 static VersionComparisonOp BlocklistComparatorToComparisonOp(
582 const nsAString& op) {
583 if (op.EqualsLiteral("LESS_THAN")) {
584 return DRIVER_LESS_THAN;
586 if (op.EqualsLiteral("BUILD_ID_LESS_THAN")) {
587 return DRIVER_BUILD_ID_LESS_THAN;
589 if (op.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
590 return DRIVER_LESS_THAN_OR_EQUAL;
592 if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
593 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL;
595 if (op.EqualsLiteral("GREATER_THAN")) {
596 return DRIVER_GREATER_THAN;
598 if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
599 return DRIVER_GREATER_THAN_OR_EQUAL;
601 if (op.EqualsLiteral("EQUAL")) {
602 return DRIVER_EQUAL;
604 if (op.EqualsLiteral("NOT_EQUAL")) {
605 return DRIVER_NOT_EQUAL;
607 if (op.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
608 return DRIVER_BETWEEN_EXCLUSIVE;
610 if (op.EqualsLiteral("BETWEEN_INCLUSIVE")) {
611 return DRIVER_BETWEEN_INCLUSIVE;
613 if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
614 return DRIVER_BETWEEN_INCLUSIVE_START;
617 return DRIVER_COMPARISON_IGNORED;
621 Deserialize Blocklist entries from string.
622 e.g:
623 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
625 static bool BlocklistEntryToDriverInfo(const nsACString& aBlocklistEntry,
626 GfxDriverInfo& aDriverInfo) {
627 // If we get an application version to be zero, something is not working
628 // and we are not going to bother checking the blocklist versions.
629 // See TestGfxWidgets.cpp for how version comparison works.
630 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
631 static mozilla::Version zeroV("0");
632 static mozilla::Version appV(GfxInfoBase::GetApplicationVersion().get());
633 if (appV <= zeroV) {
634 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
635 << "Invalid application version "
636 << GfxInfoBase::GetApplicationVersion().get();
639 aDriverInfo.mRuleId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns;
641 for (const auto& keyValue : aBlocklistEntry.Split('\t')) {
642 nsTArray<nsCString> splitted;
643 ParseString(keyValue, ':', splitted);
644 if (splitted.Length() != 2) {
645 // If we don't recognize the input data, we do not want to proceed.
646 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
647 << "Unrecognized data " << nsCString(keyValue).get();
648 return false;
650 const nsCString& key = splitted[0];
651 const nsCString& value = splitted[1];
652 NS_ConvertUTF8toUTF16 dataValue(value);
654 if (value.Length() == 0) {
655 // Safety check for empty values.
656 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
657 << "Empty value for " << key.get();
658 return false;
661 if (key.EqualsLiteral("blockID")) {
662 nsCString blockIdStr = "FEATURE_FAILURE_DL_BLOCKLIST_"_ns + value;
663 aDriverInfo.mRuleId = blockIdStr.get();
664 } else if (key.EqualsLiteral("os")) {
665 aDriverInfo.mOperatingSystem = BlocklistOSToOperatingSystem(dataValue);
666 } else if (key.EqualsLiteral("osversion")) {
667 aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
668 } else if (key.EqualsLiteral("windowProtocol")) {
669 aDriverInfo.mWindowProtocol = dataValue;
670 } else if (key.EqualsLiteral("vendor")) {
671 aDriverInfo.mAdapterVendor = dataValue;
672 } else if (key.EqualsLiteral("driverVendor")) {
673 aDriverInfo.mDriverVendor = dataValue;
674 } else if (key.EqualsLiteral("feature")) {
675 aDriverInfo.mFeature = BlocklistFeatureToGfxFeature(dataValue);
676 if (aDriverInfo.mFeature < 0) {
677 // If we don't recognize the feature, we do not want to proceed.
678 gfxWarning() << "Unrecognized feature " << value.get();
679 return false;
681 } else if (key.EqualsLiteral("featureStatus")) {
682 aDriverInfo.mFeatureStatus =
683 BlocklistFeatureStatusToGfxFeatureStatus(dataValue);
684 } else if (key.EqualsLiteral("driverVersion")) {
685 uint64_t version;
686 if (ParseDriverVersion(dataValue, &version))
687 aDriverInfo.mDriverVersion = version;
688 } else if (key.EqualsLiteral("driverVersionMax")) {
689 uint64_t version;
690 if (ParseDriverVersion(dataValue, &version))
691 aDriverInfo.mDriverVersionMax = version;
692 } else if (key.EqualsLiteral("driverVersionComparator")) {
693 aDriverInfo.mComparisonOp = BlocklistComparatorToComparisonOp(dataValue);
694 } else if (key.EqualsLiteral("model")) {
695 aDriverInfo.mModel = dataValue;
696 } else if (key.EqualsLiteral("product")) {
697 aDriverInfo.mProduct = dataValue;
698 } else if (key.EqualsLiteral("manufacturer")) {
699 aDriverInfo.mManufacturer = dataValue;
700 } else if (key.EqualsLiteral("hardware")) {
701 aDriverInfo.mHardware = dataValue;
702 } else if (key.EqualsLiteral("versionRange")) {
703 nsTArray<nsCString> versionRange;
704 ParseString(value, ',', versionRange);
705 if (versionRange.Length() != 2) {
706 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
707 << "Unrecognized versionRange " << value.get();
708 return false;
710 const nsCString& minValue = versionRange[0];
711 const nsCString& maxValue = versionRange[1];
713 mozilla::Version minV(minValue.get());
714 mozilla::Version maxV(maxValue.get());
716 if (minV > zeroV && !(appV >= minV)) {
717 // The version of the application is less than the minimal version
718 // this blocklist entry applies to, so we can just ignore it by
719 // returning false and letting the caller deal with it.
720 return false;
722 if (maxV > zeroV && !(appV <= maxV)) {
723 // The version of the application is more than the maximal version
724 // this blocklist entry applies to, so we can just ignore it by
725 // returning false and letting the caller deal with it.
726 return false;
728 } else if (key.EqualsLiteral("devices")) {
729 nsTArray<nsCString> devices;
730 ParseString(value, ',', devices);
731 GfxDeviceFamily* deviceIds = BlocklistDevicesToDeviceFamily(devices);
732 if (deviceIds) {
733 // Get GfxDriverInfo to adopt the devices array we created.
734 aDriverInfo.mDeleteDevices = true;
735 aDriverInfo.mDevices = deviceIds;
738 // We explicitly ignore unknown elements.
741 return true;
744 NS_IMETHODIMP
745 GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
746 const char16_t* aData) {
747 if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
748 nsTArray<GfxDriverInfo> driverInfo;
749 NS_ConvertUTF16toUTF8 utf8Data(aData);
751 for (const auto& blocklistEntry : utf8Data.Split('\n')) {
752 GfxDriverInfo di;
753 if (BlocklistEntryToDriverInfo(blocklistEntry, di)) {
754 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
755 // Probably some non-standard semantics of the copy/move operations?
756 *driverInfo.AppendElement() = di;
757 // Prevent di falling out of scope from destroying the devices.
758 di.mDeleteDevices = false;
759 } else {
760 driverInfo.AppendElement();
764 EvaluateDownloadedBlocklist(driverInfo);
767 return NS_OK;
770 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX), mMutex("GfxInfoBase") {}
772 GfxInfoBase::~GfxInfoBase() = default;
774 nsresult GfxInfoBase::Init() {
775 InitGfxDriverInfoShutdownObserver();
777 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
778 if (os) {
779 os->AddObserver(this, "blocklist-data-gfxItems", true);
782 return NS_OK;
785 void GfxInfoBase::GetData() {
786 if (mScreenPixels != INT64_MAX) {
787 // Already initialized.
788 return;
791 ScreenManager::GetSingleton().GetTotalScreenPixels(&mScreenPixels);
794 NS_IMETHODIMP
795 GfxInfoBase::GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
796 int32_t* aStatus) {
797 // Ignore the gfx.blocklist.all pref on release and beta.
798 #if defined(RELEASE_OR_BETA)
799 int32_t blocklistAll = 0;
800 #else
801 int32_t blocklistAll = StaticPrefs::gfx_blocklist_all_AtStartup();
802 #endif
803 if (blocklistAll > 0) {
804 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
805 << "Forcing blocklisting all features";
806 *aStatus = FEATURE_BLOCKED_DEVICE;
807 aFailureId = "FEATURE_FAILURE_BLOCK_ALL";
808 return NS_OK;
811 if (blocklistAll < 0) {
812 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
813 << "Ignoring any feature blocklisting.";
814 *aStatus = FEATURE_STATUS_OK;
815 return NS_OK;
818 // This is how we evaluate the downloadable blocklist. If there is no pref,
819 // then we will fallback to checking the static blocklist.
820 if (GetPrefValueForFeature(aFeature, *aStatus, aFailureId)) {
821 return NS_OK;
824 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
825 // Use the cached data received from the parent process.
826 MOZ_ASSERT(sFeatureStatus);
827 bool success = false;
828 for (const auto& fs : *sFeatureStatus) {
829 if (fs.feature() == aFeature) {
830 aFailureId = fs.failureId();
831 *aStatus = fs.status();
832 success = true;
833 break;
836 return success ? NS_OK : NS_ERROR_FAILURE;
839 nsString version;
840 nsTArray<GfxDriverInfo> driverInfo;
841 nsresult rv =
842 GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo, aFailureId);
843 return rv;
846 nsTArray<gfx::GfxInfoFeatureStatus> GfxInfoBase::GetAllFeatures() {
847 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
848 if (!sFeatureStatus) {
849 InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>());
850 for (int32_t i = 1; i <= nsIGfxInfo::FEATURE_MAX_VALUE; ++i) {
851 int32_t status = 0;
852 nsAutoCString failureId;
853 GetFeatureStatus(i, failureId, &status);
854 gfx::GfxInfoFeatureStatus gfxFeatureStatus;
855 gfxFeatureStatus.feature() = i;
856 gfxFeatureStatus.status() = status;
857 gfxFeatureStatus.failureId() = failureId;
858 sFeatureStatus->AppendElement(gfxFeatureStatus);
862 nsTArray<gfx::GfxInfoFeatureStatus> features;
863 for (const auto& status : *sFeatureStatus) {
864 gfx::GfxInfoFeatureStatus copy = status;
865 features.AppendElement(copy);
867 return features;
870 inline bool MatchingAllowStatus(int32_t aStatus) {
871 switch (aStatus) {
872 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS:
873 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED:
874 return true;
875 default:
876 return false;
880 // Matching OS go somewhat beyond the simple equality check because of the
881 // "All Windows" and "All OS X" variations.
883 // aBlockedOS is describing the system(s) we are trying to block.
884 // aSystemOS is describing the system we are running on.
886 // aSystemOS should not be "Windows" or "OSX" - it should be set to
887 // a particular version instead.
888 // However, it is valid for aBlockedOS to be one of those generic values,
889 // as we could be blocking all of the versions.
890 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS,
891 OperatingSystem aSystemOS,
892 uint32_t aSystemOSBuild) {
893 MOZ_ASSERT(aSystemOS != OperatingSystem::Windows &&
894 aSystemOS != OperatingSystem::OSX);
896 // If the block entry OS is unknown, it doesn't match
897 if (aBlockedOS == OperatingSystem::Unknown) {
898 return false;
901 #if defined(XP_WIN)
902 if (aBlockedOS == OperatingSystem::Windows) {
903 // We do want even "unknown" aSystemOS to fall under "all windows"
904 return true;
907 constexpr uint32_t kMinWin10BuildNumber = 18362;
908 if (aBlockedOS == OperatingSystem::RecentWindows10 &&
909 aSystemOS == OperatingSystem::Windows10) {
910 // For allowlist purposes, we sometimes want to restrict to only recent
911 // versions of Windows 10. This is a bit of a kludge but easier than adding
912 // complicated blocklist infrastructure for build ID comparisons like driver
913 // versions.
914 return aSystemOSBuild >= kMinWin10BuildNumber;
917 if (aBlockedOS == OperatingSystem::NotRecentWindows10) {
918 if (aSystemOS == OperatingSystem::Windows10) {
919 return aSystemOSBuild < kMinWin10BuildNumber;
920 } else {
921 return true;
924 #endif
926 #if defined(XP_MACOSX)
927 if (aBlockedOS == OperatingSystem::OSX) {
928 // We do want even "unknown" aSystemOS to fall under "all OS X"
929 return true;
931 #endif
933 return aSystemOS == aBlockedOS;
936 inline bool MatchingBattery(BatteryStatus aBatteryStatus, bool aHasBattery) {
937 switch (aBatteryStatus) {
938 case BatteryStatus::All:
939 return true;
940 case BatteryStatus::None:
941 return !aHasBattery;
942 case BatteryStatus::Present:
943 return aHasBattery;
946 MOZ_ASSERT_UNREACHABLE("bad battery status");
947 return false;
950 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus,
951 int64_t aScreenPixels) {
952 constexpr int64_t kMaxSmallPixels = 2304000; // 1920x1200
953 constexpr int64_t kMaxMediumPixels = 4953600; // 3440x1440
955 switch (aScreenStatus) {
956 case ScreenSizeStatus::All:
957 return true;
958 case ScreenSizeStatus::Small:
959 return aScreenPixels <= kMaxSmallPixels;
960 case ScreenSizeStatus::SmallAndMedium:
961 return aScreenPixels <= kMaxMediumPixels;
962 case ScreenSizeStatus::Medium:
963 return aScreenPixels > kMaxSmallPixels &&
964 aScreenPixels <= kMaxMediumPixels;
965 case ScreenSizeStatus::MediumAndLarge:
966 return aScreenPixels > kMaxSmallPixels;
967 case ScreenSizeStatus::Large:
968 return aScreenPixels > kMaxMediumPixels;
971 MOZ_ASSERT_UNREACHABLE("bad screen status");
972 return false;
975 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
976 const nsTArray<GfxDriverInfo>& info, nsAString& aSuggestedVersion,
977 int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
978 bool aForAllowing) {
979 int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
981 // Some properties are not available on all platforms.
982 nsAutoString windowProtocol;
983 nsresult rv = GetWindowProtocol(windowProtocol);
984 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
985 return 0;
988 bool hasBattery = false;
989 rv = GetHasBattery(&hasBattery);
990 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
991 return 0;
994 uint32_t osBuild = OperatingSystemBuild();
996 // Get the adapters once then reuse below
997 nsAutoString adapterVendorID[2];
998 nsAutoString adapterDeviceID[2];
999 nsAutoString adapterDriverVendor[2];
1000 nsAutoString adapterDriverVersionString[2];
1001 bool adapterInfoFailed[2];
1003 adapterInfoFailed[0] =
1004 (NS_FAILED(GetAdapterVendorID(adapterVendorID[0])) ||
1005 NS_FAILED(GetAdapterDeviceID(adapterDeviceID[0])) ||
1006 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor[0])) ||
1007 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString[0])));
1008 adapterInfoFailed[1] =
1009 (NS_FAILED(GetAdapterVendorID2(adapterVendorID[1])) ||
1010 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID[1])) ||
1011 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor[1])) ||
1012 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString[1])));
1013 // No point in going on if we don't have adapter info
1014 if (adapterInfoFailed[0] && adapterInfoFailed[1]) {
1015 return 0;
1018 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1019 uint64_t driverVersion[2] = {0, 0};
1020 if (!adapterInfoFailed[0]) {
1021 ParseDriverVersion(adapterDriverVersionString[0], &driverVersion[0]);
1023 if (!adapterInfoFailed[1]) {
1024 ParseDriverVersion(adapterDriverVersionString[1], &driverVersion[1]);
1026 #endif
1028 uint32_t i = 0;
1029 for (; i < info.Length(); i++) {
1030 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
1031 // blocklisting. Only consider entries for our search mode.
1032 if (MatchingAllowStatus(info[i].mFeatureStatus) != aForAllowing) {
1033 continue;
1036 // If we don't have the info for this GPU, no need to check further.
1037 // It is unclear that we would ever have a mixture of 1st and 2nd
1038 // GPU, but leaving the code in for that possibility for now.
1039 // (Actually, currently mGpu2 will never be true, so this can
1040 // be optimized out.)
1041 uint32_t infoIndex = info[i].mGpu2 ? 1 : 0;
1042 if (adapterInfoFailed[infoIndex]) {
1043 continue;
1046 // Do the operating system check first, no point in getting the driver
1047 // info if we won't need to use it.
1048 if (!MatchingOperatingSystems(info[i].mOperatingSystem, os, osBuild)) {
1049 continue;
1052 if (info[i].mOperatingSystemVersion &&
1053 info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
1054 continue;
1057 if (!MatchingBattery(info[i].mBattery, hasBattery)) {
1058 continue;
1061 if (!MatchingScreenSize(info[i].mScreen, mScreenPixels)) {
1062 continue;
1065 if (!DoesWindowProtocolMatch(info[i].mWindowProtocol, windowProtocol)) {
1066 continue;
1069 if (!DoesVendorMatch(info[i].mAdapterVendor, adapterVendorID[infoIndex])) {
1070 continue;
1073 if (!DoesDriverVendorMatch(info[i].mDriverVendor,
1074 adapterDriverVendor[infoIndex])) {
1075 continue;
1078 if (info[i].mDevices && !info[i].mDevices->IsEmpty()) {
1079 nsresult rv = info[i].mDevices->Contains(adapterDeviceID[infoIndex]);
1080 if (rv == NS_ERROR_NOT_AVAILABLE) {
1081 // Not found
1082 continue;
1084 if (rv != NS_OK) {
1085 // Failed to search, allowlist should not match, blocklist should match
1086 // for safety reasons
1087 if (aForAllowing) {
1088 continue;
1090 break;
1094 bool match = false;
1096 if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
1097 continue;
1099 if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
1100 continue;
1102 if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
1103 continue;
1105 if (!info[i].mManufacturer.IsEmpty() &&
1106 !info[i].mManufacturer.Equals(Manufacturer())) {
1107 continue;
1110 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_WIDGET_GTK)
1111 switch (info[i].mComparisonOp) {
1112 case DRIVER_LESS_THAN:
1113 match = driverVersion[infoIndex] < info[i].mDriverVersion;
1114 break;
1115 case DRIVER_BUILD_ID_LESS_THAN:
1116 match = (driverVersion[infoIndex] & 0xFFFF) < info[i].mDriverVersion;
1117 break;
1118 case DRIVER_LESS_THAN_OR_EQUAL:
1119 match = driverVersion[infoIndex] <= info[i].mDriverVersion;
1120 break;
1121 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL:
1122 match = (driverVersion[infoIndex] & 0xFFFF) <= info[i].mDriverVersion;
1123 break;
1124 case DRIVER_GREATER_THAN:
1125 match = driverVersion[infoIndex] > info[i].mDriverVersion;
1126 break;
1127 case DRIVER_GREATER_THAN_OR_EQUAL:
1128 match = driverVersion[infoIndex] >= info[i].mDriverVersion;
1129 break;
1130 case DRIVER_EQUAL:
1131 match = driverVersion[infoIndex] == info[i].mDriverVersion;
1132 break;
1133 case DRIVER_NOT_EQUAL:
1134 match = driverVersion[infoIndex] != info[i].mDriverVersion;
1135 break;
1136 case DRIVER_BETWEEN_EXCLUSIVE:
1137 match = driverVersion[infoIndex] > info[i].mDriverVersion &&
1138 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1139 break;
1140 case DRIVER_BETWEEN_INCLUSIVE:
1141 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1142 driverVersion[infoIndex] <= info[i].mDriverVersionMax;
1143 break;
1144 case DRIVER_BETWEEN_INCLUSIVE_START:
1145 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1146 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1147 break;
1148 case DRIVER_COMPARISON_IGNORED:
1149 // We don't have a comparison op, so we match everything.
1150 match = true;
1151 break;
1152 default:
1153 NS_WARNING("Bogus op in GfxDriverInfo");
1154 break;
1156 #else
1157 // We don't care what driver version it was. We only check OS version and if
1158 // the device matches.
1159 match = true;
1160 #endif
1162 if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
1163 if (info[i].mFeature == GfxDriverInfo::allFeatures ||
1164 info[i].mFeature == aFeature) {
1165 status = info[i].mFeatureStatus;
1166 if (!info[i].mRuleId.IsEmpty()) {
1167 aFailureId = info[i].mRuleId.get();
1168 } else {
1169 aFailureId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1171 break;
1176 #if defined(XP_WIN)
1177 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1178 // as either the primary or secondary adapter. D2D is also blocked when the
1179 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1180 // If the primary GPU already matched something in the blocklist then we
1181 // ignore this special rule. See bug 1008759.
1182 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN &&
1183 (aFeature == nsIGfxInfo::FEATURE_DIRECT2D)) {
1184 if (!adapterInfoFailed[1]) {
1185 nsAString& nvVendorID =
1186 (nsAString&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA);
1187 const nsString nv310mDeviceId = u"0x0A70"_ns;
1188 if (nvVendorID.Equals(adapterVendorID[1],
1189 nsCaseInsensitiveStringComparator) &&
1190 nv310mDeviceId.Equals(adapterDeviceID[1],
1191 nsCaseInsensitiveStringComparator)) {
1192 status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
1193 aFailureId = "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1198 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1199 // back to the Windows handler, so we must handle this here.
1200 if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
1201 if (info[i].mSuggestedVersion) {
1202 aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
1203 } else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
1204 info[i].mDriverVersion != GfxDriverInfo::allDriverVersions) {
1205 aSuggestedVersion.AppendPrintf(
1206 "%lld.%lld.%lld.%lld",
1207 (info[i].mDriverVersion & 0xffff000000000000) >> 48,
1208 (info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
1209 (info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
1210 (info[i].mDriverVersion & 0x000000000000ffff));
1213 #endif
1215 return status;
1218 void GfxInfoBase::SetFeatureStatus(nsTArray<gfx::GfxInfoFeatureStatus>&& aFS) {
1219 MOZ_ASSERT(!sFeatureStatus);
1220 InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>(std::move(aFS)));
1223 bool GfxInfoBase::DoesWindowProtocolMatch(
1224 const nsAString& aBlocklistWindowProtocol,
1225 const nsAString& aWindowProtocol) {
1226 return aBlocklistWindowProtocol.Equals(aWindowProtocol,
1227 nsCaseInsensitiveStringComparator) ||
1228 aBlocklistWindowProtocol.Equals(
1229 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All),
1230 nsCaseInsensitiveStringComparator);
1233 bool GfxInfoBase::DoesVendorMatch(const nsAString& aBlocklistVendor,
1234 const nsAString& aAdapterVendor) {
1235 return aBlocklistVendor.Equals(aAdapterVendor,
1236 nsCaseInsensitiveStringComparator) ||
1237 aBlocklistVendor.Equals(
1238 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All),
1239 nsCaseInsensitiveStringComparator);
1242 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
1243 const nsAString& aDriverVendor) {
1244 return aBlocklistVendor.Equals(aDriverVendor,
1245 nsCaseInsensitiveStringComparator) ||
1246 aBlocklistVendor.Equals(
1247 GfxDriverInfo::GetDriverVendor(DriverVendor::All),
1248 nsCaseInsensitiveStringComparator);
1251 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature) const {
1252 return aFeature == nsIGfxInfo::FEATURE_VIDEO_OVERLAY ||
1253 aFeature == nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY;
1256 nsresult GfxInfoBase::GetFeatureStatusImpl(
1257 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedVersion,
1258 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
1259 OperatingSystem* aOS /* = nullptr */) {
1260 if (aFeature <= 0) {
1261 gfxWarning() << "Invalid feature <= 0";
1262 return NS_OK;
1265 if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1266 // Terminate now with the status determined by the derived type (OS-specific
1267 // code).
1268 return NS_OK;
1271 if (sShutdownOccurred) {
1272 // This is futile; we've already commenced shutdown and our blocklists have
1273 // been deleted. We may want to look into resurrecting the blocklist instead
1274 // but for now, just don't even go there.
1275 return NS_OK;
1278 // Ensure any additional initialization required is complete.
1279 GetData();
1281 // If an operating system was provided by the derived GetFeatureStatusImpl,
1282 // grab it here. Otherwise, the OS is unknown.
1283 OperatingSystem os = (aOS ? *aOS : OperatingSystem::Unknown);
1285 nsAutoString adapterVendorID;
1286 nsAutoString adapterDeviceID;
1287 nsAutoString adapterDriverVersionString;
1288 if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
1289 NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
1290 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString))) {
1291 aFailureId = "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1292 *aStatus = FEATURE_BLOCKED_DEVICE;
1293 return NS_OK;
1296 // We only check either the given blocklist, or the static list, as given.
1297 int32_t status;
1298 if (aDriverInfo.Length()) {
1299 status =
1300 FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature,
1301 aFailureId, os, /* aForAllowing */ false);
1302 } else {
1303 if (!sDriverInfo) {
1304 sDriverInfo = new nsTArray<GfxDriverInfo>();
1306 status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion,
1307 aFeature, aFailureId, os,
1308 /* aForAllowing */ false);
1311 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1312 if (IsFeatureAllowlisted(aFeature)) {
1313 // This feature is actually using the allowlist; that means after we pass
1314 // the blocklist to prevent us explicitly from getting the feature, we now
1315 // need to check the allowlist to ensure we are allowed to get it in the
1316 // first place.
1317 if (aDriverInfo.Length()) {
1318 status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion,
1319 aFeature, aFailureId, os,
1320 /* aForAllowing */ true);
1321 } else {
1322 status = FindBlocklistedDeviceInList(
1323 GetGfxDriverInfo(), aSuggestedVersion, aFeature, aFailureId, os,
1324 /* aForAllowing */ true);
1327 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1328 status = nsIGfxInfo::FEATURE_DENIED;
1330 } else {
1331 // It's now done being processed. It's safe to set the status to
1332 // STATUS_OK.
1333 status = nsIGfxInfo::FEATURE_STATUS_OK;
1337 *aStatus = status;
1338 return NS_OK;
1341 NS_IMETHODIMP
1342 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
1343 nsAString& aVersion) {
1344 nsCString version;
1345 if (GetPrefValueForDriverVersion(version)) {
1346 aVersion = NS_ConvertASCIItoUTF16(version);
1347 return NS_OK;
1350 int32_t status;
1351 nsCString discardFailureId;
1352 nsTArray<GfxDriverInfo> driverInfo;
1353 return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo,
1354 discardFailureId);
1357 void GfxInfoBase::EvaluateDownloadedBlocklist(
1358 nsTArray<GfxDriverInfo>& aDriverInfo) {
1359 // If the list is empty, then we don't actually want to call
1360 // GetFeatureStatusImpl since we will use the static list instead. In that
1361 // case, all we want to do is make sure the pref is removed.
1362 if (aDriverInfo.IsEmpty()) {
1363 gfxCriticalNoteOnce << "Evaluate empty downloaded blocklist";
1364 return;
1367 OperatingSystem os = GetOperatingSystem();
1369 // For every feature we know about, we evaluate whether this blocklist has a
1370 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1371 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1372 // anywhere permanent.
1373 for (int feature = 1; feature <= nsIGfxInfo::FEATURE_MAX_VALUE; ++feature) {
1374 int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
1375 nsCString failureId;
1376 nsAutoString suggestedVersion;
1378 // Note that we are careful to call the base class method since we only want
1379 // to evaluate the downloadable blocklist for these prefs.
1380 MOZ_ALWAYS_TRUE(NS_SUCCEEDED(GfxInfoBase::GetFeatureStatusImpl(
1381 feature, &status, suggestedVersion, aDriverInfo, failureId, &os)));
1383 switch (status) {
1384 default:
1385 MOZ_FALLTHROUGH_ASSERT("Unhandled feature status!");
1386 case nsIGfxInfo::FEATURE_STATUS_UNKNOWN:
1387 // This may be returned during shutdown or for invalid features.
1388 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS:
1389 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED:
1390 case nsIGfxInfo::FEATURE_DENIED:
1391 // We cannot use the downloadable blocklist to control the allowlist.
1392 // If a feature is allowlisted, then we should also ignore DENIED
1393 // statuses from GetFeatureStatusImpl because we don't check the
1394 // static list when and this is an expected value. If we wish to
1395 // override the allowlist, it is as simple as creating a normal
1396 // blocklist rule with a BLOCKED* status code.
1397 case nsIGfxInfo::FEATURE_STATUS_OK:
1398 RemovePrefForFeature(feature);
1399 break;
1401 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
1402 if (!suggestedVersion.IsEmpty()) {
1403 SetPrefValueForDriverVersion(suggestedVersion);
1404 } else {
1405 RemovePrefForDriverVersion();
1407 [[fallthrough]];
1409 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION:
1410 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
1411 case nsIGfxInfo::FEATURE_DISCOURAGED:
1412 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
1413 case nsIGfxInfo::FEATURE_BLOCKED_PLATFORM_TEST:
1414 SetPrefValueForFeature(feature, status, failureId);
1415 break;
1420 NS_IMETHODIMP_(void)
1421 GfxInfoBase::LogFailure(const nsACString& failure) {
1422 // gfxCriticalError has a mutex lock of its own, so we may not actually
1423 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1424 // will not return the copy of the logs unless it can get the same lock
1425 // that gfxCriticalError uses. Still, that is so much of an implementation
1426 // detail that it's nicer to just add an extra lock here and in
1427 // ::GetFailures()
1428 MutexAutoLock lock(mMutex);
1430 // By default, gfxCriticalError asserts; make it not assert in this case.
1431 gfxCriticalError(CriticalLog::DefaultOptions(false))
1432 << "(LF) " << failure.BeginReading();
1435 NS_IMETHODIMP GfxInfoBase::GetFailures(nsTArray<int32_t>& indices,
1436 nsTArray<nsCString>& failures) {
1437 MutexAutoLock lock(mMutex);
1439 LogForwarder* logForwarder = Factory::GetLogForwarder();
1440 if (!logForwarder) {
1441 return NS_ERROR_UNEXPECTED;
1444 // There are two string copies in this method, starting with this one. We are
1445 // assuming this is not a big deal, as the size of the array should be small
1446 // and the strings in it should be small as well (the error messages in the
1447 // code.) The second copy happens with the AppendElement() calls.
1448 // Technically, we don't need the mutex lock after the StringVectorCopy()
1449 // call.
1450 LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
1451 LoggingRecord::const_iterator it;
1452 for (it = loggedStrings.begin(); it != loggedStrings.end(); ++it) {
1453 failures.AppendElement(nsDependentCSubstring(std::get<1>(*it).c_str(),
1454 std::get<1>(*it).size()));
1455 indices.AppendElement(std::get<0>(*it));
1458 return NS_OK;
1461 nsTArray<GfxInfoCollectorBase*>* sCollectors;
1463 static void InitCollectors() {
1464 if (!sCollectors) sCollectors = new nsTArray<GfxInfoCollectorBase*>;
1467 nsresult GfxInfoBase::GetInfo(JSContext* aCx,
1468 JS::MutableHandle<JS::Value> aResult) {
1469 InitCollectors();
1470 InfoObject obj(aCx);
1472 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1473 (*sCollectors)[i]->GetInfo(obj);
1476 // Some example property definitions
1477 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1478 // obj.DefineProperty("renderer", mRendererIDsString);
1479 // obj.DefineProperty("five", 5);
1481 if (!obj.mOk) {
1482 return NS_ERROR_FAILURE;
1485 aResult.setObject(*obj.mObj);
1486 return NS_OK;
1489 nsAutoCString gBaseAppVersion;
1491 const nsCString& GfxInfoBase::GetApplicationVersion() {
1492 static bool versionInitialized = false;
1493 if (!versionInitialized) {
1494 // If we fail to get the version, we will not try again.
1495 versionInitialized = true;
1497 // Get the version from xpcom/system/nsIXULAppInfo.idl
1498 nsCOMPtr<nsIXULAppInfo> app = do_GetService("@mozilla.org/xre/app-info;1");
1499 if (app) {
1500 app->GetVersion(gBaseAppVersion);
1503 return gBaseAppVersion;
1506 void GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector) {
1507 InitCollectors();
1508 sCollectors->AppendElement(collector);
1511 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector) {
1512 InitCollectors();
1513 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1514 if ((*sCollectors)[i] == collector) {
1515 sCollectors->RemoveElementAt(i);
1516 break;
1519 if (sCollectors->IsEmpty()) {
1520 delete sCollectors;
1521 sCollectors = nullptr;
1525 static void AppendMonitor(JSContext* aCx, widget::Screen& aScreen,
1526 JS::Handle<JSObject*> aOutArray, int32_t aIndex) {
1527 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1529 auto screenSize = aScreen.GetRect().Size();
1531 JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value(screenSize.width));
1532 JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
1534 JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value(screenSize.height));
1535 JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
1537 // XXX Just preserving behavior since this is exposed to telemetry, but we
1538 // could consider including this everywhere.
1539 #ifdef XP_MACOSX
1540 JS::Rooted<JS::Value> scale(
1541 aCx, JS::NumberValue(aScreen.GetContentsScaleFactor()));
1542 JS_SetProperty(aCx, obj, "scale", scale);
1543 #endif
1545 #ifdef XP_WIN
1546 JS::Rooted<JS::Value> refreshRate(aCx,
1547 JS::Int32Value(aScreen.GetRefreshRate()));
1548 JS_SetProperty(aCx, obj, "refreshRate", refreshRate);
1550 JS::Rooted<JS::Value> pseudoDisplay(
1551 aCx, JS::BooleanValue(aScreen.GetIsPseudoDisplay()));
1552 JS_SetProperty(aCx, obj, "pseudoDisplay", pseudoDisplay);
1553 #endif
1555 JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
1556 JS_SetElement(aCx, aOutArray, aIndex, element);
1559 nsresult GfxInfoBase::FindMonitors(JSContext* aCx,
1560 JS::Handle<JSObject*> aOutArray) {
1561 int32_t index = 0;
1562 auto& sm = ScreenManager::GetSingleton();
1563 for (auto& screen : sm.CurrentScreenList()) {
1564 AppendMonitor(aCx, *screen, aOutArray, index++);
1567 if (index == 0) {
1568 // Ensure we return at least one monitor, this is needed for xpcshell.
1569 RefPtr<Screen> screen = sm.GetPrimaryScreen();
1570 AppendMonitor(aCx, *screen, aOutArray, index++);
1573 return NS_OK;
1576 NS_IMETHODIMP
1577 GfxInfoBase::GetMonitors(JSContext* aCx, JS::MutableHandle<JS::Value> aResult) {
1578 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1580 nsresult rv = FindMonitors(aCx, array);
1581 if (NS_FAILED(rv)) {
1582 return rv;
1585 aResult.setObject(*array);
1586 return NS_OK;
1589 static inline bool SetJSPropertyString(JSContext* aCx,
1590 JS::Handle<JSObject*> aObj,
1591 const char* aProp, const char* aString) {
1592 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, aString));
1593 if (!str) {
1594 return false;
1597 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1598 return JS_SetProperty(aCx, aObj, aProp, val);
1601 template <typename T>
1602 static inline bool AppendJSElement(JSContext* aCx, JS::Handle<JSObject*> aObj,
1603 const T& aValue) {
1604 uint32_t index;
1605 if (!JS::GetArrayLength(aCx, aObj, &index)) {
1606 return false;
1608 return JS_SetElement(aCx, aObj, index, aValue);
1611 nsresult GfxInfoBase::GetFeatures(JSContext* aCx,
1612 JS::MutableHandle<JS::Value> aOut) {
1613 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1614 if (!obj) {
1615 return NS_ERROR_OUT_OF_MEMORY;
1617 aOut.setObject(*obj);
1619 layers::LayersBackend backend =
1620 gfxPlatform::Initialized()
1621 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1622 : layers::LayersBackend::LAYERS_NONE;
1623 const char* backendName = layers::GetLayersBackendName(backend);
1624 SetJSPropertyString(aCx, obj, "compositor", backendName);
1626 // If graphics isn't initialized yet, just stop now.
1627 if (!gfxPlatform::Initialized()) {
1628 return NS_OK;
1631 DescribeFeatures(aCx, obj);
1632 return NS_OK;
1635 nsresult GfxInfoBase::GetFeatureLog(JSContext* aCx,
1636 JS::MutableHandle<JS::Value> aOut) {
1637 JS::Rooted<JSObject*> containerObj(aCx, JS_NewPlainObject(aCx));
1638 if (!containerObj) {
1639 return NS_ERROR_OUT_OF_MEMORY;
1641 aOut.setObject(*containerObj);
1643 JS::Rooted<JSObject*> featureArray(aCx, JS::NewArrayObject(aCx, 0));
1644 if (!featureArray) {
1645 return NS_ERROR_OUT_OF_MEMORY;
1648 // Collect features.
1649 gfxConfig::ForEachFeature([&](const char* aName, const char* aDescription,
1650 FeatureState& aFeature) -> void {
1651 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1652 if (!obj) {
1653 return;
1655 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1656 !SetJSPropertyString(aCx, obj, "description", aDescription) ||
1657 !SetJSPropertyString(aCx, obj, "status",
1658 FeatureStatusToString(aFeature.GetValue()))) {
1659 return;
1662 JS::Rooted<JS::Value> log(aCx);
1663 if (!BuildFeatureStateLog(aCx, aFeature, &log)) {
1664 return;
1666 if (!JS_SetProperty(aCx, obj, "log", log)) {
1667 return;
1670 if (!AppendJSElement(aCx, featureArray, obj)) {
1671 return;
1675 JS::Rooted<JSObject*> fallbackArray(aCx, JS::NewArrayObject(aCx, 0));
1676 if (!fallbackArray) {
1677 return NS_ERROR_OUT_OF_MEMORY;
1680 // Collect fallbacks.
1681 gfxConfig::ForEachFallback(
1682 [&](const char* aName, const char* aMessage) -> void {
1683 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1684 if (!obj) {
1685 return;
1688 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1689 !SetJSPropertyString(aCx, obj, "message", aMessage)) {
1690 return;
1693 if (!AppendJSElement(aCx, fallbackArray, obj)) {
1694 return;
1698 JS::Rooted<JS::Value> val(aCx);
1700 val = JS::ObjectValue(*featureArray);
1701 JS_SetProperty(aCx, containerObj, "features", val);
1703 val = JS::ObjectValue(*fallbackArray);
1704 JS_SetProperty(aCx, containerObj, "fallbacks", val);
1706 return NS_OK;
1709 bool GfxInfoBase::BuildFeatureStateLog(JSContext* aCx,
1710 const FeatureState& aFeature,
1711 JS::MutableHandle<JS::Value> aOut) {
1712 JS::Rooted<JSObject*> log(aCx, JS::NewArrayObject(aCx, 0));
1713 if (!log) {
1714 return false;
1716 aOut.setObject(*log);
1718 aFeature.ForEachStatusChange([&](const char* aType, FeatureStatus aStatus,
1719 const char* aMessage,
1720 const nsCString& aFailureId) -> void {
1721 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1722 if (!obj) {
1723 return;
1726 if (!SetJSPropertyString(aCx, obj, "type", aType) ||
1727 !SetJSPropertyString(aCx, obj, "status",
1728 FeatureStatusToString(aStatus)) ||
1729 (!aFailureId.IsEmpty() &&
1730 !SetJSPropertyString(aCx, obj, "failureId", aFailureId.get())) ||
1731 (aMessage && !SetJSPropertyString(aCx, obj, "message", aMessage))) {
1732 return;
1735 if (!AppendJSElement(aCx, log, obj)) {
1736 return;
1740 return true;
1743 void GfxInfoBase::DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> aObj) {
1744 JS::Rooted<JSObject*> obj(aCx);
1746 gfx::FeatureState& hwCompositing =
1747 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING);
1748 InitFeatureObject(aCx, aObj, "hwCompositing", hwCompositing, &obj);
1750 gfx::FeatureState& gpuProcess =
1751 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS);
1752 InitFeatureObject(aCx, aObj, "gpuProcess", gpuProcess, &obj);
1754 gfx::FeatureState& webrender = gfxConfig::GetFeature(gfx::Feature::WEBRENDER);
1755 InitFeatureObject(aCx, aObj, "webrender", webrender, &obj);
1757 gfx::FeatureState& wrCompositor =
1758 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR);
1759 InitFeatureObject(aCx, aObj, "wrCompositor", wrCompositor, &obj);
1761 gfx::FeatureState& openglCompositing =
1762 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING);
1763 InitFeatureObject(aCx, aObj, "openglCompositing", openglCompositing, &obj);
1765 gfx::FeatureState& omtp = gfxConfig::GetFeature(gfx::Feature::OMTP);
1766 InitFeatureObject(aCx, aObj, "omtp", omtp, &obj);
1769 bool GfxInfoBase::InitFeatureObject(JSContext* aCx,
1770 JS::Handle<JSObject*> aContainer,
1771 const char* aName,
1772 mozilla::gfx::FeatureState& aFeatureState,
1773 JS::MutableHandle<JSObject*> aOutObj) {
1774 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1775 if (!obj) {
1776 return false;
1779 nsCString status = aFeatureState.GetStatusAndFailureIdString();
1781 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, status.get()));
1782 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1783 JS_SetProperty(aCx, obj, "status", val);
1785 // Add the feature object to the container.
1787 JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
1788 JS_SetProperty(aCx, aContainer, aName, val);
1791 aOutObj.set(obj);
1792 return true;
1795 nsresult GfxInfoBase::GetActiveCrashGuards(JSContext* aCx,
1796 JS::MutableHandle<JS::Value> aOut) {
1797 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1798 if (!array) {
1799 return NS_ERROR_OUT_OF_MEMORY;
1801 aOut.setObject(*array);
1803 DriverCrashGuard::ForEachActiveCrashGuard(
1804 [&](const char* aName, const char* aPrefName) -> void {
1805 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1806 if (!obj) {
1807 return;
1809 if (!SetJSPropertyString(aCx, obj, "type", aName)) {
1810 return;
1812 if (!SetJSPropertyString(aCx, obj, "prefName", aPrefName)) {
1813 return;
1815 if (!AppendJSElement(aCx, array, obj)) {
1816 return;
1820 return NS_OK;
1823 NS_IMETHODIMP
1824 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate) {
1825 *aTargetFrameRate = gfxPlatform::TargetFrameRate();
1826 return NS_OK;
1829 NS_IMETHODIMP
1830 GfxInfoBase::GetCodecSupportInfo(nsACString& aCodecSupportInfo) {
1831 aCodecSupportInfo.Assign(gfx::gfxVars::CodecSupportInfo());
1832 return NS_OK;
1835 NS_IMETHODIMP
1836 GfxInfoBase::GetIsHeadless(bool* aIsHeadless) {
1837 *aIsHeadless = gfxPlatform::IsHeadless();
1838 return NS_OK;
1841 NS_IMETHODIMP
1842 GfxInfoBase::GetContentBackend(nsAString& aContentBackend) {
1843 BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1844 nsString outStr;
1846 switch (backend) {
1847 case BackendType::DIRECT2D1_1: {
1848 outStr.AppendPrintf("Direct2D 1.1");
1849 break;
1851 case BackendType::SKIA: {
1852 outStr.AppendPrintf("Skia");
1853 break;
1855 case BackendType::CAIRO: {
1856 outStr.AppendPrintf("Cairo");
1857 break;
1859 default:
1860 return NS_ERROR_FAILURE;
1863 aContentBackend.Assign(outStr);
1864 return NS_OK;
1867 NS_IMETHODIMP
1868 GfxInfoBase::GetAzureCanvasBackend(nsAString& aBackend) {
1869 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1870 gfxPlatform::GetPlatform()->GetAzureCanvasBackend()),
1871 aBackend);
1872 return NS_OK;
1875 NS_IMETHODIMP
1876 GfxInfoBase::GetAzureContentBackend(nsAString& aBackend) {
1877 CopyASCIItoUTF16(mozilla::MakeStringSpan(
1878 gfxPlatform::GetPlatform()->GetAzureContentBackend()),
1879 aBackend);
1880 return NS_OK;
1883 NS_IMETHODIMP
1884 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue) {
1885 GPUProcessManager* gpu = GPUProcessManager::Get();
1886 if (!gpu) {
1887 // Not supported in content processes.
1888 return NS_ERROR_FAILURE;
1891 *aOutValue = !!gpu->GetGPUChild();
1892 return NS_OK;
1895 NS_IMETHODIMP_(int32_t)
1896 GfxInfoBase::GetMaxRefreshRate(bool* aMixed) {
1897 if (aMixed) {
1898 *aMixed = false;
1901 int32_t maxRefreshRate = 0;
1902 for (auto& screen : ScreenManager::GetSingleton().CurrentScreenList()) {
1903 int32_t refreshRate = screen->GetRefreshRate();
1904 if (aMixed && maxRefreshRate > 0 && maxRefreshRate != refreshRate) {
1905 *aMixed = true;
1907 maxRefreshRate = std::max(maxRefreshRate, refreshRate);
1910 return maxRefreshRate > 0 ? maxRefreshRate : -1;
1913 NS_IMETHODIMP
1914 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) {
1915 gfxPlatform::GetPlatform();
1917 GPUProcessManager* gpm = GPUProcessManager::Get();
1918 if (aEnable) {
1919 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS)) {
1920 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1922 gpm->EnsureGPUReady();
1923 } else {
1924 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1925 gpm->KillProcess();
1928 *_retval = true;
1929 return NS_OK;
1932 NS_IMETHODIMP GfxInfoBase::KillGPUProcessForTests() {
1933 GPUProcessManager* gpm = GPUProcessManager::Get();
1934 if (!gpm) {
1935 // gfxPlatform has not been initialized.
1936 return NS_ERROR_NOT_INITIALIZED;
1939 gpm->KillProcess();
1940 return NS_OK;
1943 NS_IMETHODIMP GfxInfoBase::CrashGPUProcessForTests() {
1944 GPUProcessManager* gpm = GPUProcessManager::Get();
1945 if (!gpm) {
1946 // gfxPlatform has not been initialized.
1947 return NS_ERROR_NOT_INITIALIZED;
1950 gpm->CrashProcess();
1951 return NS_OK;
1954 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1955 GfxInfoBase::AddCollector(this);
1958 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1959 GfxInfoBase::RemoveCollector(this);