Bug 1676529 [wpt PR 26467] - [LayoutNG] Find sibling spanners using the child iterato...
[gecko.git] / widget / GfxInfoBase.cpp
blob2824a49d3147fa5da00e5bb26e6c040ed99777bd
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 "nsCOMPtr.h"
17 #include "nsCOMArray.h"
18 #include "nsString.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"
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/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;
63 public:
64 ShutdownObserver() = default;
66 NS_DECL_ISUPPORTS
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) {
76 delete deviceFamily;
77 deviceFamily = nullptr;
80 for (auto& desktop : GfxDriverInfo::sDesktopEnvironment) {
81 delete desktop;
82 desktop = nullptr;
85 for (auto& windowProtocol : GfxDriverInfo::sWindowProtocol) {
86 delete windowProtocol;
87 windowProtocol = nullptr;
90 for (auto& deviceVendor : GfxDriverInfo::sDeviceVendors) {
91 delete deviceVendor;
92 deviceVendor = nullptr;
95 for (auto& driverVendor : GfxDriverInfo::sDriverVendors) {
96 delete driverVendor;
97 driverVendor = nullptr;
100 GfxInfoBase::sShutdownOccurred = true;
102 return NS_OK;
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!");
116 return;
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;
135 switch (aFeature) {
136 case nsIGfxInfo::FEATURE_DIRECT2D:
137 name = BLOCKLIST_PREF_BRANCH "direct2d";
138 break;
139 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
140 name = BLOCKLIST_PREF_BRANCH "layers.direct3d9";
141 break;
142 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
143 name = BLOCKLIST_PREF_BRANCH "layers.direct3d10";
144 break;
145 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
146 name = BLOCKLIST_PREF_BRANCH "layers.direct3d10-1";
147 break;
148 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS:
149 name = BLOCKLIST_PREF_BRANCH "layers.direct3d11";
150 break;
151 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE:
152 name = BLOCKLIST_PREF_BRANCH "direct3d11angle";
153 break;
154 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING:
155 name = BLOCKLIST_PREF_BRANCH "hardwarevideodecoding";
156 break;
157 case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
158 name = BLOCKLIST_PREF_BRANCH "layers.opengl";
159 break;
160 case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
161 name = BLOCKLIST_PREF_BRANCH "webgl.opengl";
162 break;
163 case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
164 name = BLOCKLIST_PREF_BRANCH "webgl.angle";
165 break;
166 case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA:
167 name = BLOCKLIST_PREF_BRANCH "webgl.msaa";
168 break;
169 case nsIGfxInfo::FEATURE_STAGEFRIGHT:
170 name = BLOCKLIST_PREF_BRANCH "stagefright";
171 break;
172 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264:
173 name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.h264";
174 break;
175 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE:
176 name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.encode";
177 break;
178 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE:
179 name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.decode";
180 break;
181 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION:
182 name = BLOCKLIST_PREF_BRANCH "canvas2d.acceleration";
183 break;
184 case nsIGfxInfo::FEATURE_DX_INTEROP2:
185 name = BLOCKLIST_PREF_BRANCH "dx.interop2";
186 break;
187 case nsIGfxInfo::FEATURE_GPU_PROCESS:
188 name = BLOCKLIST_PREF_BRANCH "gpu.process";
189 break;
190 case nsIGfxInfo::FEATURE_WEBGL2:
191 name = BLOCKLIST_PREF_BRANCH "webgl2";
192 break;
193 case nsIGfxInfo::FEATURE_ADVANCED_LAYERS:
194 name = BLOCKLIST_PREF_BRANCH "layers.advanced";
195 break;
196 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX:
197 name = BLOCKLIST_PREF_BRANCH "d3d11.keyed.mutex";
198 break;
199 case nsIGfxInfo::FEATURE_WEBRENDER:
200 name = BLOCKLIST_PREF_BRANCH "webrender";
201 break;
202 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR:
203 name = BLOCKLIST_PREF_BRANCH "webrender.compositor";
204 break;
205 case nsIGfxInfo::FEATURE_DX_NV12:
206 name = BLOCKLIST_PREF_BRANCH "dx.nv12";
207 break;
208 case nsIGfxInfo::FEATURE_DX_P010:
209 name = BLOCKLIST_PREF_BRANCH "dx.p010";
210 break;
211 case nsIGfxInfo::FEATURE_DX_P016:
212 name = BLOCKLIST_PREF_BRANCH "dx.p016";
213 break;
214 case nsIGfxInfo::FEATURE_VP8_HW_DECODE:
215 case nsIGfxInfo::FEATURE_VP9_HW_DECODE:
216 // We don't provide prefs for these features as these are
217 // not handling downloadable blocklist.
218 break;
219 case nsIGfxInfo::FEATURE_GL_SWIZZLE:
220 name = BLOCKLIST_PREF_BRANCH "gl.swizzle";
221 break;
222 case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS:
223 name = BLOCKLIST_PREF_BRANCH "webrender.scissored_cache_clears";
224 break;
225 case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS:
226 name = BLOCKLIST_PREF_BRANCH "webgl.allow-oop";
227 break;
228 case nsIGfxInfo::FEATURE_THREADSAFE_GL:
229 name = BLOCKLIST_PREF_BRANCH "gl.threadsafe";
230 break;
231 case nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE:
232 name = BLOCKLIST_PREF_BRANCH "webrender.software";
233 break;
234 default:
235 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
236 break;
239 return name;
242 // Returns the value of the pref for the relevant feature in aValue.
243 // If the pref doesn't exist, aValue is not touched, and returns false.
244 static bool GetPrefValueForFeature(int32_t aFeature, int32_t& aValue,
245 nsACString& aFailureId) {
246 const char* prefname = GetPrefNameForFeature(aFeature);
247 if (!prefname) return false;
249 aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
250 if (!NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue))) {
251 return false;
254 nsCString failureprefname(prefname);
255 failureprefname += ".failureid";
256 nsAutoCString failureValue;
257 nsresult rv = Preferences::GetCString(failureprefname.get(), failureValue);
258 if (NS_SUCCEEDED(rv)) {
259 aFailureId = failureValue.get();
260 } else {
261 aFailureId = "FEATURE_FAILURE_BLOCKLIST_PREF";
264 return true;
267 static void SetPrefValueForFeature(int32_t aFeature, int32_t aValue,
268 const nsACString& aFailureId) {
269 const char* prefname = GetPrefNameForFeature(aFeature);
270 if (!prefname) return;
271 if (XRE_IsParentProcess()) {
272 GfxInfoBase::sFeatureStatus = nullptr;
275 Preferences::SetInt(prefname, aValue);
276 if (!aFailureId.IsEmpty()) {
277 nsCString failureprefname(prefname);
278 failureprefname += ".failureid";
279 Preferences::SetCString(failureprefname.get(), aFailureId);
283 static void RemovePrefForFeature(int32_t aFeature) {
284 const char* prefname = GetPrefNameForFeature(aFeature);
285 if (!prefname) return;
287 if (XRE_IsParentProcess()) {
288 GfxInfoBase::sFeatureStatus = nullptr;
290 Preferences::ClearUser(prefname);
293 static bool GetPrefValueForDriverVersion(nsCString& aVersion) {
294 return NS_SUCCEEDED(
295 Preferences::GetCString(SUGGESTED_VERSION_PREF, aVersion));
298 static void SetPrefValueForDriverVersion(const nsAString& aVersion) {
299 Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion);
302 static void RemovePrefForDriverVersion() {
303 Preferences::ClearUser(SUGGESTED_VERSION_PREF);
306 static OperatingSystem BlocklistOSToOperatingSystem(const nsAString& os) {
307 if (os.EqualsLiteral("WINNT 6.1"))
308 return OperatingSystem::Windows7;
309 else if (os.EqualsLiteral("WINNT 6.2"))
310 return OperatingSystem::Windows8;
311 else if (os.EqualsLiteral("WINNT 6.3"))
312 return OperatingSystem::Windows8_1;
313 else if (os.EqualsLiteral("WINNT 10.0"))
314 return OperatingSystem::Windows10;
315 else if (os.EqualsLiteral("Linux"))
316 return OperatingSystem::Linux;
317 else if (os.EqualsLiteral("Darwin 9"))
318 return OperatingSystem::OSX10_5;
319 else if (os.EqualsLiteral("Darwin 10"))
320 return OperatingSystem::OSX10_6;
321 else if (os.EqualsLiteral("Darwin 11"))
322 return OperatingSystem::OSX10_7;
323 else if (os.EqualsLiteral("Darwin 12"))
324 return OperatingSystem::OSX10_8;
325 else if (os.EqualsLiteral("Darwin 13"))
326 return OperatingSystem::OSX10_9;
327 else if (os.EqualsLiteral("Darwin 14"))
328 return OperatingSystem::OSX10_10;
329 else if (os.EqualsLiteral("Darwin 15"))
330 return OperatingSystem::OSX10_11;
331 else if (os.EqualsLiteral("Darwin 16"))
332 return OperatingSystem::OSX10_12;
333 else if (os.EqualsLiteral("Darwin 17"))
334 return OperatingSystem::OSX10_13;
335 else if (os.EqualsLiteral("Darwin 18"))
336 return OperatingSystem::OSX10_14;
337 else if (os.EqualsLiteral("Darwin 19"))
338 return OperatingSystem::OSX10_15;
339 else if (os.EqualsLiteral("Darwin 20"))
340 return OperatingSystem::OSX10_16;
341 else if (os.EqualsLiteral("Android"))
342 return OperatingSystem::Android;
343 // For historical reasons, "All" in blocklist means "All Windows"
344 else if (os.EqualsLiteral("All"))
345 return OperatingSystem::Windows;
347 return OperatingSystem::Unknown;
350 static GfxDeviceFamily* BlocklistDevicesToDeviceFamily(
351 nsTArray<nsCString>& devices) {
352 if (devices.Length() == 0) return nullptr;
354 // For each device, get its device ID, and return a freshly-allocated
355 // GfxDeviceFamily with the contents of that array.
356 GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
358 for (uint32_t i = 0; i < devices.Length(); ++i) {
359 // We make sure we don't add any "empty" device entries to the array, so
360 // we don't need to check if devices[i] is empty.
361 deviceIds->Append(NS_ConvertUTF8toUTF16(devices[i]));
364 return deviceIds;
367 static int32_t BlocklistFeatureToGfxFeature(const nsAString& aFeature) {
368 MOZ_ASSERT(!aFeature.IsEmpty());
369 if (aFeature.EqualsLiteral("DIRECT2D"))
370 return nsIGfxInfo::FEATURE_DIRECT2D;
371 else if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS"))
372 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
373 else if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS"))
374 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
375 else if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
376 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
377 else if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS"))
378 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
379 else if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE"))
380 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
381 else if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
382 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
383 else if (aFeature.EqualsLiteral("OPENGL_LAYERS"))
384 return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
385 else if (aFeature.EqualsLiteral("WEBGL_OPENGL"))
386 return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
387 else if (aFeature.EqualsLiteral("WEBGL_ANGLE"))
388 return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
389 else if (aFeature.EqualsLiteral("WEBGL_MSAA"))
390 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA;
391 else if (aFeature.EqualsLiteral("STAGEFRIGHT"))
392 return nsIGfxInfo::FEATURE_STAGEFRIGHT;
393 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
394 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
395 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
396 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
397 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264"))
398 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264;
399 else if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION"))
400 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
401 else if (aFeature.EqualsLiteral("DX_INTEROP2"))
402 return nsIGfxInfo::FEATURE_DX_INTEROP2;
403 else if (aFeature.EqualsLiteral("GPU_PROCESS"))
404 return nsIGfxInfo::FEATURE_GPU_PROCESS;
405 else if (aFeature.EqualsLiteral("WEBGL2"))
406 return nsIGfxInfo::FEATURE_WEBGL2;
407 else if (aFeature.EqualsLiteral("ADVANCED_LAYERS"))
408 return nsIGfxInfo::FEATURE_ADVANCED_LAYERS;
409 else if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX"))
410 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
411 else if (aFeature.EqualsLiteral("WEBRENDER"))
412 return nsIGfxInfo::FEATURE_WEBRENDER;
413 else if (aFeature.EqualsLiteral("WEBRENDER_COMPOSITOR"))
414 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR;
415 else if (aFeature.EqualsLiteral("DX_NV12"))
416 return nsIGfxInfo::FEATURE_DX_NV12;
417 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
418 // in downloadable blocklist.
419 else if (aFeature.EqualsLiteral("GL_SWIZZLE"))
420 return nsIGfxInfo::FEATURE_GL_SWIZZLE;
421 else if (aFeature.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS"))
422 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS;
423 else if (aFeature.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS"))
424 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS;
425 else if (aFeature.EqualsLiteral("THREADSAFE_GL"))
426 return nsIGfxInfo::FEATURE_THREADSAFE_GL;
427 else if (aFeature.EqualsLiteral("WEBRENDER_SOFTWARE"))
428 return nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE;
430 // If we don't recognize the feature, it may be new, and something
431 // this version doesn't understand. So, nothing to do. This is
432 // different from feature not being specified at all, in which case
433 // this method should not get called and we should continue with the
434 // "all features" blocklisting.
435 return -1;
438 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
439 const nsAString& aStatus) {
440 if (aStatus.EqualsLiteral("STATUS_OK"))
441 return nsIGfxInfo::FEATURE_STATUS_OK;
442 else if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
443 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
444 else if (aStatus.EqualsLiteral("BLOCKED_DEVICE"))
445 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
446 else if (aStatus.EqualsLiteral("DISCOURAGED"))
447 return nsIGfxInfo::FEATURE_DISCOURAGED;
448 else if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION"))
449 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
450 else if (aStatus.EqualsLiteral("DENIED"))
451 return nsIGfxInfo::FEATURE_DENIED;
452 else if (aStatus.EqualsLiteral("ALLOW_QUALIFIED"))
453 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
454 else if (aStatus.EqualsLiteral("ALLOW_ALWAYS"))
455 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
457 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
458 // expecting the "mismatch" status showing up here.
460 return nsIGfxInfo::FEATURE_STATUS_OK;
463 static VersionComparisonOp BlocklistComparatorToComparisonOp(
464 const nsAString& op) {
465 if (op.EqualsLiteral("LESS_THAN"))
466 return DRIVER_LESS_THAN;
467 else if (op.EqualsLiteral("BUILD_ID_LESS_THAN"))
468 return DRIVER_BUILD_ID_LESS_THAN;
469 else if (op.EqualsLiteral("LESS_THAN_OR_EQUAL"))
470 return DRIVER_LESS_THAN_OR_EQUAL;
471 else if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
472 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL;
473 else if (op.EqualsLiteral("GREATER_THAN"))
474 return DRIVER_GREATER_THAN;
475 else if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
476 return DRIVER_GREATER_THAN_OR_EQUAL;
477 else if (op.EqualsLiteral("EQUAL"))
478 return DRIVER_EQUAL;
479 else if (op.EqualsLiteral("NOT_EQUAL"))
480 return DRIVER_NOT_EQUAL;
481 else if (op.EqualsLiteral("BETWEEN_EXCLUSIVE"))
482 return DRIVER_BETWEEN_EXCLUSIVE;
483 else if (op.EqualsLiteral("BETWEEN_INCLUSIVE"))
484 return DRIVER_BETWEEN_INCLUSIVE;
485 else if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
486 return DRIVER_BETWEEN_INCLUSIVE_START;
488 return DRIVER_COMPARISON_IGNORED;
492 Deserialize Blocklist entries from string.
493 e.g:
494 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
496 static bool BlocklistEntryToDriverInfo(const nsACString& aBlocklistEntry,
497 GfxDriverInfo& aDriverInfo) {
498 // If we get an application version to be zero, something is not working
499 // and we are not going to bother checking the blocklist versions.
500 // See TestGfxWidgets.cpp for how version comparison works.
501 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
502 static mozilla::Version zeroV("0");
503 static mozilla::Version appV(GfxInfoBase::GetApplicationVersion().get());
504 if (appV <= zeroV) {
505 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
506 << "Invalid application version "
507 << GfxInfoBase::GetApplicationVersion().get();
510 aDriverInfo.mRuleId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns;
512 for (const auto& keyValue : aBlocklistEntry.Split('\t')) {
513 nsTArray<nsCString> splitted;
514 ParseString(keyValue, ':', splitted);
515 if (splitted.Length() != 2) {
516 // If we don't recognize the input data, we do not want to proceed.
517 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
518 << "Unrecognized data " << nsCString(keyValue).get();
519 return false;
521 const nsCString& key = splitted[0];
522 const nsCString& value = splitted[1];
523 NS_ConvertUTF8toUTF16 dataValue(value);
525 if (value.Length() == 0) {
526 // Safety check for empty values.
527 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
528 << "Empty value for " << key.get();
529 return false;
532 if (key.EqualsLiteral("blockID")) {
533 nsCString blockIdStr = "FEATURE_FAILURE_DL_BLOCKLIST_"_ns + value;
534 aDriverInfo.mRuleId = blockIdStr.get();
535 } else if (key.EqualsLiteral("os")) {
536 aDriverInfo.mOperatingSystem = BlocklistOSToOperatingSystem(dataValue);
537 } else if (key.EqualsLiteral("osversion")) {
538 aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
539 } else if (key.EqualsLiteral("desktopEnvironment")) {
540 aDriverInfo.mDesktopEnvironment = dataValue;
541 } else if (key.EqualsLiteral("windowProtocol")) {
542 aDriverInfo.mWindowProtocol = dataValue;
543 } else if (key.EqualsLiteral("vendor")) {
544 aDriverInfo.mAdapterVendor = dataValue;
545 } else if (key.EqualsLiteral("driverVendor")) {
546 aDriverInfo.mDriverVendor = dataValue;
547 } else if (key.EqualsLiteral("feature")) {
548 aDriverInfo.mFeature = BlocklistFeatureToGfxFeature(dataValue);
549 if (aDriverInfo.mFeature < 0) {
550 // If we don't recognize the feature, we do not want to proceed.
551 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
552 << "Unrecognized feature " << value.get();
553 return false;
555 } else if (key.EqualsLiteral("featureStatus")) {
556 aDriverInfo.mFeatureStatus =
557 BlocklistFeatureStatusToGfxFeatureStatus(dataValue);
558 } else if (key.EqualsLiteral("driverVersion")) {
559 uint64_t version;
560 if (ParseDriverVersion(dataValue, &version))
561 aDriverInfo.mDriverVersion = version;
562 } else if (key.EqualsLiteral("driverVersionMax")) {
563 uint64_t version;
564 if (ParseDriverVersion(dataValue, &version))
565 aDriverInfo.mDriverVersionMax = version;
566 } else if (key.EqualsLiteral("driverVersionComparator")) {
567 aDriverInfo.mComparisonOp = BlocklistComparatorToComparisonOp(dataValue);
568 } else if (key.EqualsLiteral("model")) {
569 aDriverInfo.mModel = dataValue;
570 } else if (key.EqualsLiteral("product")) {
571 aDriverInfo.mProduct = dataValue;
572 } else if (key.EqualsLiteral("manufacturer")) {
573 aDriverInfo.mManufacturer = dataValue;
574 } else if (key.EqualsLiteral("hardware")) {
575 aDriverInfo.mHardware = dataValue;
576 } else if (key.EqualsLiteral("versionRange")) {
577 nsTArray<nsCString> versionRange;
578 ParseString(value, ',', versionRange);
579 if (versionRange.Length() != 2) {
580 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
581 << "Unrecognized versionRange " << value.get();
582 return false;
584 const nsCString& minValue = versionRange[0];
585 const nsCString& maxValue = versionRange[1];
587 mozilla::Version minV(minValue.get());
588 mozilla::Version maxV(maxValue.get());
590 if (minV > zeroV && !(appV >= minV)) {
591 // The version of the application is less than the minimal version
592 // this blocklist entry applies to, so we can just ignore it by
593 // returning false and letting the caller deal with it.
594 return false;
596 if (maxV > zeroV && !(appV <= maxV)) {
597 // The version of the application is more than the maximal version
598 // this blocklist entry applies to, so we can just ignore it by
599 // returning false and letting the caller deal with it.
600 return false;
602 } else if (key.EqualsLiteral("devices")) {
603 nsTArray<nsCString> devices;
604 ParseString(value, ',', devices);
605 GfxDeviceFamily* deviceIds = BlocklistDevicesToDeviceFamily(devices);
606 if (deviceIds) {
607 // Get GfxDriverInfo to adopt the devices array we created.
608 aDriverInfo.mDeleteDevices = true;
609 aDriverInfo.mDevices = deviceIds;
612 // We explicitly ignore unknown elements.
615 return true;
618 static void BlocklistEntriesToDriverInfo(
619 const nsTSubstringSplitter<char>& aBlocklistEntries,
620 nsTArray<GfxDriverInfo>& aDriverInfo) {
621 aDriverInfo.Clear();
622 const uint32_t n =
623 std::distance(aBlocklistEntries.begin(), aBlocklistEntries.end());
624 aDriverInfo.SetLength(n);
626 for (uint32_t i = 0; i < n; ++i) {
627 const nsDependentCSubstring& blocklistEntry = aBlocklistEntries.Get(i);
628 GfxDriverInfo di;
629 if (BlocklistEntryToDriverInfo(blocklistEntry, di)) {
630 aDriverInfo[i] = di;
631 // Prevent di falling out of scope from destroying the devices.
632 di.mDeleteDevices = false;
637 NS_IMETHODIMP
638 GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
639 const char16_t* aData) {
640 if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
641 nsTArray<GfxDriverInfo> driverInfo;
642 NS_ConvertUTF16toUTF8 utf8Data(aData);
643 BlocklistEntriesToDriverInfo(utf8Data.Split('\n'), driverInfo);
644 EvaluateDownloadedBlocklist(driverInfo);
647 return NS_OK;
650 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX), mMutex("GfxInfoBase") {}
652 GfxInfoBase::~GfxInfoBase() = default;
654 nsresult GfxInfoBase::Init() {
655 InitGfxDriverInfoShutdownObserver();
657 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
658 if (os) {
659 os->AddObserver(this, "blocklist-data-gfxItems", true);
662 return NS_OK;
665 void GfxInfoBase::GetData() {
666 if (mScreenPixels != INT64_MAX) {
667 // Already initialized.
668 return;
671 nsCOMPtr<nsIScreenManager> manager =
672 do_GetService("@mozilla.org/gfx/screenmanager;1");
673 if (!manager) {
674 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
675 return;
678 manager->GetTotalScreenPixels(&mScreenPixels);
681 NS_IMETHODIMP
682 GfxInfoBase::GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
683 int32_t* aStatus) {
684 // Ignore the gfx.blocklist.all pref on release and beta.
685 #if defined(RELEASE_OR_BETA)
686 int32_t blocklistAll = 0;
687 #else
688 int32_t blocklistAll = StaticPrefs::gfx_blocklist_all_AtStartup();
689 #endif
690 if (blocklistAll > 0) {
691 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
692 << "Forcing blocklisting all features";
693 *aStatus = FEATURE_BLOCKED_DEVICE;
694 aFailureId = "FEATURE_FAILURE_BLOCK_ALL";
695 return NS_OK;
696 } else if (blocklistAll < 0) {
697 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
698 << "Ignoring any feature blocklisting.";
699 *aStatus = FEATURE_STATUS_OK;
700 return NS_OK;
703 if (GetPrefValueForFeature(aFeature, *aStatus, aFailureId)) {
704 return NS_OK;
707 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
708 // Use the cached data received from the parent process.
709 MOZ_ASSERT(sFeatureStatus);
710 bool success = false;
711 for (const auto& fs : *sFeatureStatus) {
712 if (fs.feature() == aFeature) {
713 aFailureId = fs.failureId();
714 *aStatus = fs.status();
715 success = true;
716 break;
719 return success ? NS_OK : NS_ERROR_FAILURE;
722 nsString version;
723 nsTArray<GfxDriverInfo> driverInfo;
724 nsresult rv =
725 GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo, aFailureId);
726 return rv;
729 nsTArray<gfx::GfxInfoFeatureStatus> GfxInfoBase::GetAllFeatures() {
730 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
731 if (!sFeatureStatus) {
732 InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>());
733 for (int32_t i = 1; i <= nsIGfxInfo::FEATURE_MAX_VALUE; ++i) {
734 int32_t status = 0;
735 nsAutoCString failureId;
736 GetFeatureStatus(i, failureId, &status);
737 gfx::GfxInfoFeatureStatus gfxFeatureStatus;
738 gfxFeatureStatus.feature() = i;
739 gfxFeatureStatus.status() = status;
740 gfxFeatureStatus.failureId() = failureId;
741 sFeatureStatus->AppendElement(gfxFeatureStatus);
745 nsTArray<gfx::GfxInfoFeatureStatus> features;
746 for (const auto& status : *sFeatureStatus) {
747 gfx::GfxInfoFeatureStatus copy = status;
748 features.AppendElement(copy);
750 return features;
753 inline bool MatchingAllowStatus(int32_t aStatus) {
754 switch (aStatus) {
755 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS:
756 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED:
757 return true;
758 default:
759 return false;
763 // Matching OS go somewhat beyond the simple equality check because of the
764 // "All Windows" and "All OS X" variations.
766 // aBlockedOS is describing the system(s) we are trying to block.
767 // aSystemOS is describing the system we are running on.
769 // aSystemOS should not be "Windows" or "OSX" - it should be set to
770 // a particular version instead.
771 // However, it is valid for aBlockedOS to be one of those generic values,
772 // as we could be blocking all of the versions.
773 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS,
774 OperatingSystem aSystemOS,
775 uint32_t aSystemOSBuild) {
776 MOZ_ASSERT(aSystemOS != OperatingSystem::Windows &&
777 aSystemOS != OperatingSystem::OSX);
779 // If the block entry OS is unknown, it doesn't match
780 if (aBlockedOS == OperatingSystem::Unknown) {
781 return false;
784 #if defined(XP_WIN)
785 if (aBlockedOS == OperatingSystem::Windows) {
786 // We do want even "unknown" aSystemOS to fall under "all windows"
787 return true;
790 constexpr uint32_t kMinWin10BuildNumber = 18362;
791 if (aBlockedOS == OperatingSystem::RecentWindows10 &&
792 aSystemOS == OperatingSystem::Windows10) {
793 // For allowlist purposes, we sometimes want to restrict to only recent
794 // versions of Windows 10. This is a bit of a kludge but easier than adding
795 // complicated blocklist infrastructure for build ID comparisons like driver
796 // versions.
797 return aSystemOSBuild >= kMinWin10BuildNumber;
800 if (aBlockedOS == OperatingSystem::NotRecentWindows10) {
801 if (aSystemOS == OperatingSystem::Windows10) {
802 return aSystemOSBuild < kMinWin10BuildNumber;
803 } else {
804 return true;
807 #endif
809 #if defined(XP_MACOSX)
810 if (aBlockedOS == OperatingSystem::OSX) {
811 // We do want even "unknown" aSystemOS to fall under "all OS X"
812 return true;
814 #endif
816 return aSystemOS == aBlockedOS;
819 inline bool MatchingBattery(BatteryStatus aBatteryStatus, bool aHasBattery) {
820 switch (aBatteryStatus) {
821 case BatteryStatus::All:
822 return true;
823 case BatteryStatus::None:
824 return !aHasBattery;
825 case BatteryStatus::Present:
826 return aHasBattery;
829 MOZ_ASSERT_UNREACHABLE("bad battery status");
830 return false;
833 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus,
834 int64_t aScreenPixels) {
835 constexpr int64_t kMaxSmallPixels = 2304000; // 1920x1200
836 constexpr int64_t kMaxMediumPixels = 4953600; // 3440x1440
838 switch (aScreenStatus) {
839 case ScreenSizeStatus::All:
840 return true;
841 case ScreenSizeStatus::Small:
842 return aScreenPixels <= kMaxSmallPixels;
843 case ScreenSizeStatus::SmallAndMedium:
844 return aScreenPixels <= kMaxMediumPixels;
845 case ScreenSizeStatus::Medium:
846 return aScreenPixels > kMaxSmallPixels &&
847 aScreenPixels <= kMaxMediumPixels;
848 case ScreenSizeStatus::MediumAndLarge:
849 return aScreenPixels > kMaxSmallPixels;
850 case ScreenSizeStatus::Large:
851 return aScreenPixels > kMaxMediumPixels;
854 MOZ_ASSERT_UNREACHABLE("bad screen status");
855 return false;
858 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
859 const nsTArray<GfxDriverInfo>& info, nsAString& aSuggestedVersion,
860 int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
861 bool aForAllowing) {
862 int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
864 // Some properties are not available on all platforms.
865 nsAutoString desktopEnvironment;
866 nsresult rv = GetDesktopEnvironment(desktopEnvironment);
867 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
868 return 0;
871 nsAutoString windowProtocol;
872 rv = GetWindowProtocol(windowProtocol);
873 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
874 return 0;
877 bool hasBattery = false;
878 rv = GetHasBattery(&hasBattery);
879 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
880 return 0;
883 uint32_t osBuild = OperatingSystemBuild();
885 // Get the adapters once then reuse below
886 nsAutoString adapterVendorID[2];
887 nsAutoString adapterDeviceID[2];
888 nsAutoString adapterDriverVendor[2];
889 nsAutoString adapterDriverVersionString[2];
890 bool adapterInfoFailed[2];
892 adapterInfoFailed[0] =
893 (NS_FAILED(GetAdapterVendorID(adapterVendorID[0])) ||
894 NS_FAILED(GetAdapterDeviceID(adapterDeviceID[0])) ||
895 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor[0])) ||
896 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString[0])));
897 adapterInfoFailed[1] =
898 (NS_FAILED(GetAdapterVendorID2(adapterVendorID[1])) ||
899 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID[1])) ||
900 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor[1])) ||
901 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString[1])));
902 // No point in going on if we don't have adapter info
903 if (adapterInfoFailed[0] && adapterInfoFailed[1]) {
904 return 0;
907 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
908 uint64_t driverVersion[2] = {0, 0};
909 if (!adapterInfoFailed[0]) {
910 ParseDriverVersion(adapterDriverVersionString[0], &driverVersion[0]);
912 if (!adapterInfoFailed[1]) {
913 ParseDriverVersion(adapterDriverVersionString[1], &driverVersion[1]);
915 #endif
917 uint32_t i = 0;
918 for (; i < info.Length(); i++) {
919 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
920 // blocklisting. Only consider entries for our search mode.
921 if (MatchingAllowStatus(info[i].mFeatureStatus) != aForAllowing) {
922 continue;
925 // If we don't have the info for this GPU, no need to check further.
926 // It is unclear that we would ever have a mixture of 1st and 2nd
927 // GPU, but leaving the code in for that possibility for now.
928 // (Actually, currently mGpu2 will never be true, so this can
929 // be optimized out.)
930 uint32_t infoIndex = info[i].mGpu2 ? 1 : 0;
931 if (adapterInfoFailed[infoIndex]) {
932 continue;
935 // Do the operating system check first, no point in getting the driver
936 // info if we won't need to use it.
937 if (!MatchingOperatingSystems(info[i].mOperatingSystem, os, osBuild)) {
938 continue;
941 if (info[i].mOperatingSystemVersion &&
942 info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
943 continue;
946 if (!MatchingBattery(info[i].mBattery, hasBattery)) {
947 continue;
950 if (!MatchingScreenSize(info[i].mScreen, mScreenPixels)) {
951 continue;
954 if (!DoesDesktopEnvironmentMatch(info[i].mDesktopEnvironment,
955 desktopEnvironment)) {
956 continue;
959 if (!DoesWindowProtocolMatch(info[i].mWindowProtocol, windowProtocol)) {
960 continue;
963 if (!DoesVendorMatch(info[i].mAdapterVendor, adapterVendorID[infoIndex])) {
964 continue;
967 if (!DoesDriverVendorMatch(info[i].mDriverVendor,
968 adapterDriverVendor[infoIndex])) {
969 continue;
972 if (info[i].mDevices && !info[i].mDevices->IsEmpty()) {
973 nsresult rv = info[i].mDevices->Contains(adapterDeviceID[infoIndex]);
974 if (rv == NS_ERROR_NOT_AVAILABLE) {
975 // Not found
976 continue;
978 if (rv != NS_OK) {
979 // Failed to search, allowlist should not match, blocklist should match
980 // for safety reasons
981 if (aForAllowing) {
982 continue;
984 break;
988 bool match = false;
990 if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
991 continue;
993 if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
994 continue;
996 if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
997 continue;
999 if (!info[i].mManufacturer.IsEmpty() &&
1000 !info[i].mManufacturer.Equals(Manufacturer())) {
1001 continue;
1004 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
1005 switch (info[i].mComparisonOp) {
1006 case DRIVER_LESS_THAN:
1007 match = driverVersion[infoIndex] < info[i].mDriverVersion;
1008 break;
1009 case DRIVER_BUILD_ID_LESS_THAN:
1010 match = (driverVersion[infoIndex] & 0xFFFF) < info[i].mDriverVersion;
1011 break;
1012 case DRIVER_LESS_THAN_OR_EQUAL:
1013 match = driverVersion[infoIndex] <= info[i].mDriverVersion;
1014 break;
1015 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL:
1016 match = (driverVersion[infoIndex] & 0xFFFF) <= info[i].mDriverVersion;
1017 break;
1018 case DRIVER_GREATER_THAN:
1019 match = driverVersion[infoIndex] > info[i].mDriverVersion;
1020 break;
1021 case DRIVER_GREATER_THAN_OR_EQUAL:
1022 match = driverVersion[infoIndex] >= info[i].mDriverVersion;
1023 break;
1024 case DRIVER_EQUAL:
1025 match = driverVersion[infoIndex] == info[i].mDriverVersion;
1026 break;
1027 case DRIVER_NOT_EQUAL:
1028 match = driverVersion[infoIndex] != info[i].mDriverVersion;
1029 break;
1030 case DRIVER_BETWEEN_EXCLUSIVE:
1031 match = driverVersion[infoIndex] > info[i].mDriverVersion &&
1032 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1033 break;
1034 case DRIVER_BETWEEN_INCLUSIVE:
1035 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1036 driverVersion[infoIndex] <= info[i].mDriverVersionMax;
1037 break;
1038 case DRIVER_BETWEEN_INCLUSIVE_START:
1039 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1040 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1041 break;
1042 case DRIVER_COMPARISON_IGNORED:
1043 // We don't have a comparison op, so we match everything.
1044 match = true;
1045 break;
1046 default:
1047 NS_WARNING("Bogus op in GfxDriverInfo");
1048 break;
1050 #else
1051 // We don't care what driver version it was. We only check OS version and if
1052 // the device matches.
1053 match = true;
1054 #endif
1056 if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
1057 if (info[i].mFeature == GfxDriverInfo::allFeatures ||
1058 info[i].mFeature == aFeature) {
1059 status = info[i].mFeatureStatus;
1060 if (!info[i].mRuleId.IsEmpty()) {
1061 aFailureId = info[i].mRuleId.get();
1062 } else {
1063 aFailureId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1065 break;
1070 #if defined(XP_WIN)
1071 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1072 // as either the primary or secondary adapter. D2D is also blocked when the
1073 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1074 // If the primary GPU already matched something in the blocklist then we
1075 // ignore this special rule. See bug 1008759.
1076 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN &&
1077 (aFeature == nsIGfxInfo::FEATURE_DIRECT2D)) {
1078 if (!adapterInfoFailed[1]) {
1079 nsAString& nvVendorID =
1080 (nsAString&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA);
1081 const nsString nv310mDeviceId = u"0x0A70"_ns;
1082 if (nvVendorID.Equals(adapterVendorID[1],
1083 nsCaseInsensitiveStringComparator) &&
1084 nv310mDeviceId.Equals(adapterDeviceID[1],
1085 nsCaseInsensitiveStringComparator)) {
1086 status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
1087 aFailureId = "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1092 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1093 // back to the Windows handler, so we must handle this here.
1094 if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
1095 if (info[i].mSuggestedVersion) {
1096 aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
1097 } else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
1098 info[i].mDriverVersion != GfxDriverInfo::allDriverVersions) {
1099 aSuggestedVersion.AppendPrintf(
1100 "%lld.%lld.%lld.%lld",
1101 (info[i].mDriverVersion & 0xffff000000000000) >> 48,
1102 (info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
1103 (info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
1104 (info[i].mDriverVersion & 0x000000000000ffff));
1107 #endif
1109 return status;
1112 void GfxInfoBase::SetFeatureStatus(nsTArray<gfx::GfxInfoFeatureStatus>&& aFS) {
1113 MOZ_ASSERT(!sFeatureStatus);
1114 InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>(std::move(aFS)));
1117 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1118 const nsAString& aBlocklistDesktop, const nsAString& aDesktopEnv) {
1119 return aBlocklistDesktop.Equals(aDesktopEnv,
1120 nsCaseInsensitiveStringComparator) ||
1121 aBlocklistDesktop.Equals(
1122 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All),
1123 nsCaseInsensitiveStringComparator);
1126 bool GfxInfoBase::DoesWindowProtocolMatch(
1127 const nsAString& aBlocklistWindowProtocol,
1128 const nsAString& aWindowProtocol) {
1129 return aBlocklistWindowProtocol.Equals(aWindowProtocol,
1130 nsCaseInsensitiveStringComparator) ||
1131 aBlocklistWindowProtocol.Equals(
1132 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All),
1133 nsCaseInsensitiveStringComparator);
1136 bool GfxInfoBase::DoesVendorMatch(const nsAString& aBlocklistVendor,
1137 const nsAString& aAdapterVendor) {
1138 return aBlocklistVendor.Equals(aAdapterVendor,
1139 nsCaseInsensitiveStringComparator) ||
1140 aBlocklistVendor.Equals(
1141 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All),
1142 nsCaseInsensitiveStringComparator);
1145 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
1146 const nsAString& aDriverVendor) {
1147 return aBlocklistVendor.Equals(aDriverVendor,
1148 nsCaseInsensitiveStringComparator) ||
1149 aBlocklistVendor.Equals(
1150 GfxDriverInfo::GetDriverVendor(DriverVendor::All),
1151 nsCaseInsensitiveStringComparator);
1154 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature) const {
1155 return aFeature == nsIGfxInfo::FEATURE_WEBRENDER ||
1156 aFeature == nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE;
1159 nsresult GfxInfoBase::GetFeatureStatusImpl(
1160 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedVersion,
1161 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
1162 OperatingSystem* aOS /* = nullptr */) {
1163 if (aFeature <= 0) {
1164 gfxWarning() << "Invalid feature <= 0";
1165 return NS_OK;
1168 if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1169 // Terminate now with the status determined by the derived type (OS-specific
1170 // code).
1171 return NS_OK;
1174 if (sShutdownOccurred) {
1175 // This is futile; we've already commenced shutdown and our blocklists have
1176 // been deleted. We may want to look into resurrecting the blocklist instead
1177 // but for now, just don't even go there.
1178 return NS_OK;
1181 // Ensure any additional initialization required is complete.
1182 GetData();
1184 // If an operating system was provided by the derived GetFeatureStatusImpl,
1185 // grab it here. Otherwise, the OS is unknown.
1186 OperatingSystem os = (aOS ? *aOS : OperatingSystem::Unknown);
1188 nsAutoString adapterVendorID;
1189 nsAutoString adapterDeviceID;
1190 nsAutoString adapterDriverVersionString;
1191 if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
1192 NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
1193 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString))) {
1194 aFailureId = "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1195 *aStatus = FEATURE_BLOCKED_DEVICE;
1196 return NS_OK;
1199 // Check if the device is blocked from the downloaded blocklist. If not, check
1200 // the static list after that. This order is used so that we can later escape
1201 // out of static blocks (i.e. if we were wrong or something was patched, we
1202 // can back out our static block without doing a release).
1203 int32_t status;
1204 if (aDriverInfo.Length()) {
1205 status =
1206 FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature,
1207 aFailureId, os, /* aForAllowing */ false);
1208 } else {
1209 if (!sDriverInfo) {
1210 sDriverInfo = new nsTArray<GfxDriverInfo>();
1212 status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion,
1213 aFeature, aFailureId, os,
1214 /* aForAllowing */ false);
1217 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1218 if (IsFeatureAllowlisted(aFeature)) {
1219 // This feature is actually using the allowlist; that means after we pass
1220 // the blocklist to prevent us explicitly from getting the feature, we now
1221 // need to check the allowlist to ensure we are allowed to get it in the
1222 // first place.
1223 if (aDriverInfo.Length()) {
1224 status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion,
1225 aFeature, aFailureId, os,
1226 /* aForAllowing */ true);
1227 } else {
1228 status = FindBlocklistedDeviceInList(
1229 GetGfxDriverInfo(), aSuggestedVersion, aFeature, aFailureId, os,
1230 /* aForAllowing */ true);
1233 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1234 status = nsIGfxInfo::FEATURE_DENIED;
1236 } else {
1237 // It's now done being processed. It's safe to set the status to
1238 // STATUS_OK.
1239 status = nsIGfxInfo::FEATURE_STATUS_OK;
1243 *aStatus = status;
1244 return NS_OK;
1247 NS_IMETHODIMP
1248 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
1249 nsAString& aVersion) {
1250 nsCString version;
1251 if (GetPrefValueForDriverVersion(version)) {
1252 aVersion = NS_ConvertASCIItoUTF16(version);
1253 return NS_OK;
1256 int32_t status;
1257 nsCString discardFailureId;
1258 nsTArray<GfxDriverInfo> driverInfo;
1259 return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo,
1260 discardFailureId);
1263 void GfxInfoBase::EvaluateDownloadedBlocklist(
1264 nsTArray<GfxDriverInfo>& aDriverInfo) {
1265 int32_t features[] = {nsIGfxInfo::FEATURE_DIRECT2D,
1266 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
1267 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
1268 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
1269 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS,
1270 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE,
1271 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
1272 nsIGfxInfo::FEATURE_OPENGL_LAYERS,
1273 nsIGfxInfo::FEATURE_WEBGL_OPENGL,
1274 nsIGfxInfo::FEATURE_WEBGL_ANGLE,
1275 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE,
1276 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE,
1277 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA,
1278 nsIGfxInfo::FEATURE_STAGEFRIGHT,
1279 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264,
1280 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION,
1281 nsIGfxInfo::FEATURE_VP8_HW_DECODE,
1282 nsIGfxInfo::FEATURE_VP9_HW_DECODE,
1283 nsIGfxInfo::FEATURE_DX_INTEROP2,
1284 nsIGfxInfo::FEATURE_GPU_PROCESS,
1285 nsIGfxInfo::FEATURE_WEBGL2,
1286 nsIGfxInfo::FEATURE_ADVANCED_LAYERS,
1287 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX,
1288 nsIGfxInfo::FEATURE_WEBRENDER,
1289 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR,
1290 nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE,
1291 nsIGfxInfo::FEATURE_DX_NV12,
1292 nsIGfxInfo::FEATURE_DX_P010,
1293 nsIGfxInfo::FEATURE_DX_P016,
1294 nsIGfxInfo::FEATURE_GL_SWIZZLE,
1295 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS,
1298 // For every feature we know about, we evaluate whether this blocklist has a
1299 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1300 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1301 // anywhere permanent.
1302 int i = 0;
1303 while (features[i]) {
1304 int32_t status;
1305 nsCString failureId;
1306 nsAutoString suggestedVersion;
1307 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1308 features[i], &status, suggestedVersion, aDriverInfo, failureId))) {
1309 switch (status) {
1310 default:
1311 case nsIGfxInfo::FEATURE_STATUS_OK:
1312 RemovePrefForFeature(features[i]);
1313 break;
1315 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
1316 if (!suggestedVersion.IsEmpty()) {
1317 SetPrefValueForDriverVersion(suggestedVersion);
1318 } else {
1319 RemovePrefForDriverVersion();
1321 [[fallthrough]];
1323 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION:
1324 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
1325 case nsIGfxInfo::FEATURE_DISCOURAGED:
1326 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
1327 SetPrefValueForFeature(features[i], status, failureId);
1328 break;
1332 ++i;
1336 NS_IMETHODIMP_(void)
1337 GfxInfoBase::LogFailure(const nsACString& failure) {
1338 // gfxCriticalError has a mutex lock of its own, so we may not actually
1339 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1340 // will not return the copy of the logs unless it can get the same lock
1341 // that gfxCriticalError uses. Still, that is so much of an implementation
1342 // detail that it's nicer to just add an extra lock here and in
1343 // ::GetFailures()
1344 MutexAutoLock lock(mMutex);
1346 // By default, gfxCriticalError asserts; make it not assert in this case.
1347 gfxCriticalError(CriticalLog::DefaultOptions(false))
1348 << "(LF) " << failure.BeginReading();
1351 NS_IMETHODIMP GfxInfoBase::GetFailures(nsTArray<int32_t>& indices,
1352 nsTArray<nsCString>& failures) {
1353 MutexAutoLock lock(mMutex);
1355 LogForwarder* logForwarder = Factory::GetLogForwarder();
1356 if (!logForwarder) {
1357 return NS_ERROR_UNEXPECTED;
1360 // There are two string copies in this method, starting with this one. We are
1361 // assuming this is not a big deal, as the size of the array should be small
1362 // and the strings in it should be small as well (the error messages in the
1363 // code.) The second copy happens with the AppendElement() calls.
1364 // Technically, we don't need the mutex lock after the StringVectorCopy()
1365 // call.
1366 LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
1367 LoggingRecord::const_iterator it;
1368 for (it = loggedStrings.begin(); it != loggedStrings.end(); ++it) {
1369 failures.AppendElement(
1370 nsDependentCSubstring(Get<1>(*it).c_str(), Get<1>(*it).size()));
1371 indices.AppendElement(Get<0>(*it));
1374 return NS_OK;
1377 nsTArray<GfxInfoCollectorBase*>* sCollectors;
1379 static void InitCollectors() {
1380 if (!sCollectors) sCollectors = new nsTArray<GfxInfoCollectorBase*>;
1383 nsresult GfxInfoBase::GetInfo(JSContext* aCx,
1384 JS::MutableHandle<JS::Value> aResult) {
1385 InitCollectors();
1386 InfoObject obj(aCx);
1388 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1389 (*sCollectors)[i]->GetInfo(obj);
1392 // Some example property definitions
1393 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1394 // obj.DefineProperty("renderer", mRendererIDsString);
1395 // obj.DefineProperty("five", 5);
1397 if (!obj.mOk) {
1398 return NS_ERROR_FAILURE;
1401 aResult.setObject(*obj.mObj);
1402 return NS_OK;
1405 nsAutoCString gBaseAppVersion;
1407 const nsCString& GfxInfoBase::GetApplicationVersion() {
1408 static bool versionInitialized = false;
1409 if (!versionInitialized) {
1410 // If we fail to get the version, we will not try again.
1411 versionInitialized = true;
1413 // Get the version from xpcom/system/nsIXULAppInfo.idl
1414 nsCOMPtr<nsIXULAppInfo> app = do_GetService("@mozilla.org/xre/app-info;1");
1415 if (app) {
1416 app->GetVersion(gBaseAppVersion);
1419 return gBaseAppVersion;
1422 void GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector) {
1423 InitCollectors();
1424 sCollectors->AppendElement(collector);
1427 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector) {
1428 InitCollectors();
1429 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1430 if ((*sCollectors)[i] == collector) {
1431 sCollectors->RemoveElementAt(i);
1432 break;
1435 if (sCollectors->IsEmpty()) {
1436 delete sCollectors;
1437 sCollectors = nullptr;
1441 nsresult GfxInfoBase::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray) {
1442 // If we have no platform specific implementation for detecting monitors, we
1443 // can just get the screen size from gfxPlatform as the best guess.
1444 if (!gfxPlatform::Initialized()) {
1445 return NS_OK;
1448 // If the screen size is empty, we are probably in xpcshell.
1449 gfx::IntSize screenSize = gfxPlatform::GetPlatform()->GetScreenSize();
1451 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1453 JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value(screenSize.width));
1454 JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
1456 JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value(screenSize.height));
1457 JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
1459 JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
1460 JS_SetElement(aCx, aOutArray, 0, element);
1462 return NS_OK;
1465 NS_IMETHODIMP
1466 GfxInfoBase::GetMonitors(JSContext* aCx, JS::MutableHandleValue aResult) {
1467 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1469 nsresult rv = FindMonitors(aCx, array);
1470 if (NS_FAILED(rv)) {
1471 return rv;
1474 aResult.setObject(*array);
1475 return NS_OK;
1478 static inline bool SetJSPropertyString(JSContext* aCx,
1479 JS::Handle<JSObject*> aObj,
1480 const char* aProp, const char* aString) {
1481 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, aString));
1482 if (!str) {
1483 return false;
1486 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1487 return JS_SetProperty(aCx, aObj, aProp, val);
1490 template <typename T>
1491 static inline bool AppendJSElement(JSContext* aCx, JS::Handle<JSObject*> aObj,
1492 const T& aValue) {
1493 uint32_t index;
1494 if (!JS::GetArrayLength(aCx, aObj, &index)) {
1495 return false;
1497 return JS_SetElement(aCx, aObj, index, aValue);
1500 nsresult GfxInfoBase::GetFeatures(JSContext* aCx,
1501 JS::MutableHandle<JS::Value> aOut) {
1502 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1503 if (!obj) {
1504 return NS_ERROR_OUT_OF_MEMORY;
1506 aOut.setObject(*obj);
1508 layers::LayersBackend backend =
1509 gfxPlatform::Initialized()
1510 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1511 : layers::LayersBackend::LAYERS_NONE;
1512 const char* backendName = layers::GetLayersBackendName(backend);
1513 SetJSPropertyString(aCx, obj, "compositor", backendName);
1515 // If graphics isn't initialized yet, just stop now.
1516 if (!gfxPlatform::Initialized()) {
1517 return NS_OK;
1520 DescribeFeatures(aCx, obj);
1521 return NS_OK;
1524 nsresult GfxInfoBase::GetFeatureLog(JSContext* aCx,
1525 JS::MutableHandle<JS::Value> aOut) {
1526 JS::Rooted<JSObject*> containerObj(aCx, JS_NewPlainObject(aCx));
1527 if (!containerObj) {
1528 return NS_ERROR_OUT_OF_MEMORY;
1530 aOut.setObject(*containerObj);
1532 JS::Rooted<JSObject*> featureArray(aCx, JS::NewArrayObject(aCx, 0));
1533 if (!featureArray) {
1534 return NS_ERROR_OUT_OF_MEMORY;
1537 // Collect features.
1538 gfxConfig::ForEachFeature([&](const char* aName, const char* aDescription,
1539 FeatureState& aFeature) -> void {
1540 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1541 if (!obj) {
1542 return;
1544 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1545 !SetJSPropertyString(aCx, obj, "description", aDescription) ||
1546 !SetJSPropertyString(aCx, obj, "status",
1547 FeatureStatusToString(aFeature.GetValue()))) {
1548 return;
1551 JS::Rooted<JS::Value> log(aCx);
1552 if (!BuildFeatureStateLog(aCx, aFeature, &log)) {
1553 return;
1555 if (!JS_SetProperty(aCx, obj, "log", log)) {
1556 return;
1559 if (!AppendJSElement(aCx, featureArray, obj)) {
1560 return;
1564 JS::Rooted<JSObject*> fallbackArray(aCx, JS::NewArrayObject(aCx, 0));
1565 if (!fallbackArray) {
1566 return NS_ERROR_OUT_OF_MEMORY;
1569 // Collect fallbacks.
1570 gfxConfig::ForEachFallback(
1571 [&](const char* aName, const char* aMessage) -> void {
1572 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1573 if (!obj) {
1574 return;
1577 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1578 !SetJSPropertyString(aCx, obj, "message", aMessage)) {
1579 return;
1582 if (!AppendJSElement(aCx, fallbackArray, obj)) {
1583 return;
1587 JS::Rooted<JS::Value> val(aCx);
1589 val = JS::ObjectValue(*featureArray);
1590 JS_SetProperty(aCx, containerObj, "features", val);
1592 val = JS::ObjectValue(*fallbackArray);
1593 JS_SetProperty(aCx, containerObj, "fallbacks", val);
1595 return NS_OK;
1598 bool GfxInfoBase::BuildFeatureStateLog(JSContext* aCx,
1599 const FeatureState& aFeature,
1600 JS::MutableHandle<JS::Value> aOut) {
1601 JS::Rooted<JSObject*> log(aCx, JS::NewArrayObject(aCx, 0));
1602 if (!log) {
1603 return false;
1605 aOut.setObject(*log);
1607 aFeature.ForEachStatusChange([&](const char* aType, FeatureStatus aStatus,
1608 const char* aMessage,
1609 const nsCString& aFailureId) -> void {
1610 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1611 if (!obj) {
1612 return;
1615 if (!SetJSPropertyString(aCx, obj, "type", aType) ||
1616 !SetJSPropertyString(aCx, obj, "status",
1617 FeatureStatusToString(aStatus)) ||
1618 (aMessage && !SetJSPropertyString(aCx, obj, "message", aMessage))) {
1619 return;
1622 if (!AppendJSElement(aCx, log, obj)) {
1623 return;
1627 return true;
1630 void GfxInfoBase::DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> aObj) {
1631 JS::Rooted<JSObject*> obj(aCx);
1633 gfx::FeatureState& hwCompositing =
1634 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING);
1635 InitFeatureObject(aCx, aObj, "hwCompositing", hwCompositing, &obj);
1637 gfx::FeatureState& gpuProcess =
1638 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS);
1639 InitFeatureObject(aCx, aObj, "gpuProcess", gpuProcess, &obj);
1641 gfx::FeatureState& wrQualified =
1642 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_QUALIFIED);
1643 InitFeatureObject(aCx, aObj, "wrQualified", wrQualified, &obj);
1645 gfx::FeatureState& webrender = gfxConfig::GetFeature(gfx::Feature::WEBRENDER);
1646 InitFeatureObject(aCx, aObj, "webrender", webrender, &obj);
1648 gfx::FeatureState& wrCompositor =
1649 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR);
1650 InitFeatureObject(aCx, aObj, "wrCompositor", wrCompositor, &obj);
1652 gfx::FeatureState& wrSoftware =
1653 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_SOFTWARE);
1654 InitFeatureObject(aCx, aObj, "wrSoftware", wrSoftware, &obj);
1656 gfx::FeatureState& openglCompositing =
1657 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING);
1658 InitFeatureObject(aCx, aObj, "openglCompositing", openglCompositing, &obj);
1660 // Only include AL if the platform attempted to use it.
1661 gfx::FeatureState& advancedLayers =
1662 gfxConfig::GetFeature(gfx::Feature::ADVANCED_LAYERS);
1663 if (advancedLayers.GetValue() != FeatureStatus::Unused) {
1664 InitFeatureObject(aCx, aObj, "advancedLayers", advancedLayers, &obj);
1666 if (gfxConfig::UseFallback(Fallback::NO_CONSTANT_BUFFER_OFFSETTING)) {
1667 JS::Rooted<JS::Value> trueVal(aCx, JS::BooleanValue(true));
1668 JS_SetProperty(aCx, obj, "noConstantBufferOffsetting", trueVal);
1673 bool GfxInfoBase::InitFeatureObject(JSContext* aCx,
1674 JS::Handle<JSObject*> aContainer,
1675 const char* aName,
1676 mozilla::gfx::FeatureState& aFeatureState,
1677 JS::MutableHandle<JSObject*> aOutObj) {
1678 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1679 if (!obj) {
1680 return false;
1683 nsCString status;
1684 auto value = aFeatureState.GetValue();
1685 switch (value) {
1686 case FeatureStatus::Blocklisted:
1687 case FeatureStatus::Disabled:
1688 case FeatureStatus::Unavailable:
1689 case FeatureStatus::UnavailableNoAngle:
1690 case FeatureStatus::Blocked:
1691 status.AppendPrintf("%s:%s", FeatureStatusToString(value),
1692 aFeatureState.GetFailureId().get());
1693 break;
1694 default:
1695 status.Append(FeatureStatusToString(value));
1696 break;
1699 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, status.get()));
1700 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1701 JS_SetProperty(aCx, obj, "status", val);
1703 // Add the feature object to the container.
1705 JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
1706 JS_SetProperty(aCx, aContainer, aName, val);
1709 aOutObj.set(obj);
1710 return true;
1713 nsresult GfxInfoBase::GetActiveCrashGuards(JSContext* aCx,
1714 JS::MutableHandle<JS::Value> aOut) {
1715 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1716 if (!array) {
1717 return NS_ERROR_OUT_OF_MEMORY;
1719 aOut.setObject(*array);
1721 DriverCrashGuard::ForEachActiveCrashGuard(
1722 [&](const char* aName, const char* aPrefName) -> void {
1723 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1724 if (!obj) {
1725 return;
1727 if (!SetJSPropertyString(aCx, obj, "type", aName)) {
1728 return;
1730 if (!SetJSPropertyString(aCx, obj, "prefName", aPrefName)) {
1731 return;
1733 if (!AppendJSElement(aCx, array, obj)) {
1734 return;
1738 return NS_OK;
1741 NS_IMETHODIMP
1742 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled) {
1743 *aWebRenderEnabled = gfxVars::UseWebRender();
1744 return NS_OK;
1747 NS_IMETHODIMP
1748 GfxInfoBase::GetUsesTiling(bool* aUsesTiling) {
1749 *aUsesTiling = gfxPlatform::GetPlatform()->UsesTiling();
1750 return NS_OK;
1753 NS_IMETHODIMP
1754 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling) {
1755 *aUsesTiling = gfxPlatform::GetPlatform()->ContentUsesTiling();
1756 return NS_OK;
1759 NS_IMETHODIMP
1760 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled) {
1761 *aOffMainThreadPaintEnabled = gfxConfig::IsEnabled(gfx::Feature::OMTP);
1762 return NS_OK;
1765 NS_IMETHODIMP
1766 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1767 int32_t* aOffMainThreadPaintWorkerCount) {
1768 if (gfxConfig::IsEnabled(gfx::Feature::OMTP)) {
1769 *aOffMainThreadPaintWorkerCount =
1770 layers::PaintThread::CalculatePaintWorkerCount();
1771 } else {
1772 *aOffMainThreadPaintWorkerCount = 0;
1774 return NS_OK;
1777 NS_IMETHODIMP
1778 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate) {
1779 *aTargetFrameRate = gfxPlatform::TargetFrameRate();
1780 return NS_OK;
1783 NS_IMETHODIMP
1784 GfxInfoBase::GetIsHeadless(bool* aIsHeadless) {
1785 *aIsHeadless = gfxPlatform::IsHeadless();
1786 return NS_OK;
1789 NS_IMETHODIMP
1790 GfxInfoBase::GetContentBackend(nsAString& aContentBackend) {
1791 BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1792 nsString outStr;
1794 switch (backend) {
1795 case BackendType::DIRECT2D1_1: {
1796 outStr.AppendPrintf("Direct2D 1.1");
1797 break;
1799 case BackendType::SKIA: {
1800 outStr.AppendPrintf("Skia");
1801 break;
1803 case BackendType::CAIRO: {
1804 outStr.AppendPrintf("Cairo");
1805 break;
1807 default:
1808 return NS_ERROR_FAILURE;
1811 aContentBackend.Assign(outStr);
1812 return NS_OK;
1815 NS_IMETHODIMP
1816 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue) {
1817 GPUProcessManager* gpu = GPUProcessManager::Get();
1818 if (!gpu) {
1819 // Not supported in content processes.
1820 return NS_ERROR_FAILURE;
1823 *aOutValue = !!gpu->GetGPUChild();
1824 return NS_OK;
1827 NS_IMETHODIMP
1828 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) {
1829 gfxPlatform::GetPlatform();
1831 GPUProcessManager* gpm = GPUProcessManager::Get();
1832 if (aEnable) {
1833 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS)) {
1834 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1836 gpm->LaunchGPUProcess();
1837 gpm->EnsureGPUReady();
1838 } else {
1839 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1840 gpm->KillProcess();
1843 *_retval = true;
1844 return NS_OK;
1847 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1848 GfxInfoBase::AddCollector(this);
1851 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1852 GfxInfoBase::RemoveCollector(this);