Bug 1646817 - Support DocumentChannel process switching in sidebars and popups r...
[gecko.git] / widget / GfxInfoBase.cpp
bloba195ebf799059c0dd6c76956b102367af845c7b9
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::OSX11_0;
341 } else if (os.EqualsLiteral("Android")) {
342 return OperatingSystem::Android;
343 // For historical reasons, "All" in blocklist means "All Windows"
344 } else if (os.EqualsLiteral("All")) {
345 return OperatingSystem::Windows;
346 } else if (os.EqualsLiteral("Darwin")) {
347 return OperatingSystem::OSX;
350 return OperatingSystem::Unknown;
353 static GfxDeviceFamily* BlocklistDevicesToDeviceFamily(
354 nsTArray<nsCString>& devices) {
355 if (devices.Length() == 0) return nullptr;
357 // For each device, get its device ID, and return a freshly-allocated
358 // GfxDeviceFamily with the contents of that array.
359 GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
361 for (uint32_t i = 0; i < devices.Length(); ++i) {
362 // We make sure we don't add any "empty" device entries to the array, so
363 // we don't need to check if devices[i] is empty.
364 deviceIds->Append(NS_ConvertUTF8toUTF16(devices[i]));
367 return deviceIds;
370 static int32_t BlocklistFeatureToGfxFeature(const nsAString& aFeature) {
371 MOZ_ASSERT(!aFeature.IsEmpty());
372 if (aFeature.EqualsLiteral("DIRECT2D"))
373 return nsIGfxInfo::FEATURE_DIRECT2D;
374 else if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS"))
375 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
376 else if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS"))
377 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
378 else if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
379 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
380 else if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS"))
381 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
382 else if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE"))
383 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
384 else if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
385 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
386 else if (aFeature.EqualsLiteral("OPENGL_LAYERS"))
387 return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
388 else if (aFeature.EqualsLiteral("WEBGL_OPENGL"))
389 return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
390 else if (aFeature.EqualsLiteral("WEBGL_ANGLE"))
391 return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
392 else if (aFeature.EqualsLiteral("WEBGL_MSAA"))
393 return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA;
394 else if (aFeature.EqualsLiteral("STAGEFRIGHT"))
395 return nsIGfxInfo::FEATURE_STAGEFRIGHT;
396 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
397 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
398 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
399 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
400 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264"))
401 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264;
402 else if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION"))
403 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
404 else if (aFeature.EqualsLiteral("DX_INTEROP2"))
405 return nsIGfxInfo::FEATURE_DX_INTEROP2;
406 else if (aFeature.EqualsLiteral("GPU_PROCESS"))
407 return nsIGfxInfo::FEATURE_GPU_PROCESS;
408 else if (aFeature.EqualsLiteral("WEBGL2"))
409 return nsIGfxInfo::FEATURE_WEBGL2;
410 else if (aFeature.EqualsLiteral("ADVANCED_LAYERS"))
411 return nsIGfxInfo::FEATURE_ADVANCED_LAYERS;
412 else if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX"))
413 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
414 else if (aFeature.EqualsLiteral("WEBRENDER"))
415 return nsIGfxInfo::FEATURE_WEBRENDER;
416 else if (aFeature.EqualsLiteral("WEBRENDER_COMPOSITOR"))
417 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR;
418 else if (aFeature.EqualsLiteral("DX_NV12"))
419 return nsIGfxInfo::FEATURE_DX_NV12;
420 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
421 // in downloadable blocklist.
422 else if (aFeature.EqualsLiteral("GL_SWIZZLE"))
423 return nsIGfxInfo::FEATURE_GL_SWIZZLE;
424 else if (aFeature.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS"))
425 return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS;
426 else if (aFeature.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS"))
427 return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS;
428 else if (aFeature.EqualsLiteral("THREADSAFE_GL"))
429 return nsIGfxInfo::FEATURE_THREADSAFE_GL;
430 else if (aFeature.EqualsLiteral("WEBRENDER_SOFTWARE"))
431 return nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE;
433 // If we don't recognize the feature, it may be new, and something
434 // this version doesn't understand. So, nothing to do. This is
435 // different from feature not being specified at all, in which case
436 // this method should not get called and we should continue with the
437 // "all features" blocklisting.
438 return -1;
441 static int32_t BlocklistFeatureStatusToGfxFeatureStatus(
442 const nsAString& aStatus) {
443 if (aStatus.EqualsLiteral("STATUS_OK"))
444 return nsIGfxInfo::FEATURE_STATUS_OK;
445 else if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
446 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
447 else if (aStatus.EqualsLiteral("BLOCKED_DEVICE"))
448 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
449 else if (aStatus.EqualsLiteral("DISCOURAGED"))
450 return nsIGfxInfo::FEATURE_DISCOURAGED;
451 else if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION"))
452 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
453 else if (aStatus.EqualsLiteral("DENIED"))
454 return nsIGfxInfo::FEATURE_DENIED;
455 else if (aStatus.EqualsLiteral("ALLOW_QUALIFIED"))
456 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
457 else if (aStatus.EqualsLiteral("ALLOW_ALWAYS"))
458 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
460 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
461 // expecting the "mismatch" status showing up here.
463 return nsIGfxInfo::FEATURE_STATUS_OK;
466 static VersionComparisonOp BlocklistComparatorToComparisonOp(
467 const nsAString& op) {
468 if (op.EqualsLiteral("LESS_THAN"))
469 return DRIVER_LESS_THAN;
470 else if (op.EqualsLiteral("BUILD_ID_LESS_THAN"))
471 return DRIVER_BUILD_ID_LESS_THAN;
472 else if (op.EqualsLiteral("LESS_THAN_OR_EQUAL"))
473 return DRIVER_LESS_THAN_OR_EQUAL;
474 else if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
475 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL;
476 else if (op.EqualsLiteral("GREATER_THAN"))
477 return DRIVER_GREATER_THAN;
478 else if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
479 return DRIVER_GREATER_THAN_OR_EQUAL;
480 else if (op.EqualsLiteral("EQUAL"))
481 return DRIVER_EQUAL;
482 else if (op.EqualsLiteral("NOT_EQUAL"))
483 return DRIVER_NOT_EQUAL;
484 else if (op.EqualsLiteral("BETWEEN_EXCLUSIVE"))
485 return DRIVER_BETWEEN_EXCLUSIVE;
486 else if (op.EqualsLiteral("BETWEEN_INCLUSIVE"))
487 return DRIVER_BETWEEN_INCLUSIVE;
488 else if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
489 return DRIVER_BETWEEN_INCLUSIVE_START;
491 return DRIVER_COMPARISON_IGNORED;
495 Deserialize Blocklist entries from string.
496 e.g:
497 os:WINNT 6.0\tvendor:0x8086\tdevices:0x2582,0x2782\tfeature:DIRECT3D_10_LAYERS\tfeatureStatus:BLOCKED_DRIVER_VERSION\tdriverVersion:8.52.322.2202\tdriverVersionComparator:LESS_THAN_OR_EQUAL
499 static bool BlocklistEntryToDriverInfo(const nsACString& aBlocklistEntry,
500 GfxDriverInfo& aDriverInfo) {
501 // If we get an application version to be zero, something is not working
502 // and we are not going to bother checking the blocklist versions.
503 // See TestGfxWidgets.cpp for how version comparison works.
504 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
505 static mozilla::Version zeroV("0");
506 static mozilla::Version appV(GfxInfoBase::GetApplicationVersion().get());
507 if (appV <= zeroV) {
508 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
509 << "Invalid application version "
510 << GfxInfoBase::GetApplicationVersion().get();
513 aDriverInfo.mRuleId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns;
515 for (const auto& keyValue : aBlocklistEntry.Split('\t')) {
516 nsTArray<nsCString> splitted;
517 ParseString(keyValue, ':', splitted);
518 if (splitted.Length() != 2) {
519 // If we don't recognize the input data, we do not want to proceed.
520 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
521 << "Unrecognized data " << nsCString(keyValue).get();
522 return false;
524 const nsCString& key = splitted[0];
525 const nsCString& value = splitted[1];
526 NS_ConvertUTF8toUTF16 dataValue(value);
528 if (value.Length() == 0) {
529 // Safety check for empty values.
530 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
531 << "Empty value for " << key.get();
532 return false;
535 if (key.EqualsLiteral("blockID")) {
536 nsCString blockIdStr = "FEATURE_FAILURE_DL_BLOCKLIST_"_ns + value;
537 aDriverInfo.mRuleId = blockIdStr.get();
538 } else if (key.EqualsLiteral("os")) {
539 aDriverInfo.mOperatingSystem = BlocklistOSToOperatingSystem(dataValue);
540 } else if (key.EqualsLiteral("osversion")) {
541 aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
542 } else if (key.EqualsLiteral("desktopEnvironment")) {
543 aDriverInfo.mDesktopEnvironment = dataValue;
544 } else if (key.EqualsLiteral("windowProtocol")) {
545 aDriverInfo.mWindowProtocol = dataValue;
546 } else if (key.EqualsLiteral("vendor")) {
547 aDriverInfo.mAdapterVendor = dataValue;
548 } else if (key.EqualsLiteral("driverVendor")) {
549 aDriverInfo.mDriverVendor = dataValue;
550 } else if (key.EqualsLiteral("feature")) {
551 aDriverInfo.mFeature = BlocklistFeatureToGfxFeature(dataValue);
552 if (aDriverInfo.mFeature < 0) {
553 // If we don't recognize the feature, we do not want to proceed.
554 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
555 << "Unrecognized feature " << value.get();
556 return false;
558 } else if (key.EqualsLiteral("featureStatus")) {
559 aDriverInfo.mFeatureStatus =
560 BlocklistFeatureStatusToGfxFeatureStatus(dataValue);
561 } else if (key.EqualsLiteral("driverVersion")) {
562 uint64_t version;
563 if (ParseDriverVersion(dataValue, &version))
564 aDriverInfo.mDriverVersion = version;
565 } else if (key.EqualsLiteral("driverVersionMax")) {
566 uint64_t version;
567 if (ParseDriverVersion(dataValue, &version))
568 aDriverInfo.mDriverVersionMax = version;
569 } else if (key.EqualsLiteral("driverVersionComparator")) {
570 aDriverInfo.mComparisonOp = BlocklistComparatorToComparisonOp(dataValue);
571 } else if (key.EqualsLiteral("model")) {
572 aDriverInfo.mModel = dataValue;
573 } else if (key.EqualsLiteral("product")) {
574 aDriverInfo.mProduct = dataValue;
575 } else if (key.EqualsLiteral("manufacturer")) {
576 aDriverInfo.mManufacturer = dataValue;
577 } else if (key.EqualsLiteral("hardware")) {
578 aDriverInfo.mHardware = dataValue;
579 } else if (key.EqualsLiteral("versionRange")) {
580 nsTArray<nsCString> versionRange;
581 ParseString(value, ',', versionRange);
582 if (versionRange.Length() != 2) {
583 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
584 << "Unrecognized versionRange " << value.get();
585 return false;
587 const nsCString& minValue = versionRange[0];
588 const nsCString& maxValue = versionRange[1];
590 mozilla::Version minV(minValue.get());
591 mozilla::Version maxV(maxValue.get());
593 if (minV > zeroV && !(appV >= minV)) {
594 // The version of the application is less than the minimal version
595 // this blocklist entry applies to, so we can just ignore it by
596 // returning false and letting the caller deal with it.
597 return false;
599 if (maxV > zeroV && !(appV <= maxV)) {
600 // The version of the application is more than the maximal version
601 // this blocklist entry applies to, so we can just ignore it by
602 // returning false and letting the caller deal with it.
603 return false;
605 } else if (key.EqualsLiteral("devices")) {
606 nsTArray<nsCString> devices;
607 ParseString(value, ',', devices);
608 GfxDeviceFamily* deviceIds = BlocklistDevicesToDeviceFamily(devices);
609 if (deviceIds) {
610 // Get GfxDriverInfo to adopt the devices array we created.
611 aDriverInfo.mDeleteDevices = true;
612 aDriverInfo.mDevices = deviceIds;
615 // We explicitly ignore unknown elements.
618 return true;
621 NS_IMETHODIMP
622 GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
623 const char16_t* aData) {
624 if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
625 nsTArray<GfxDriverInfo> driverInfo;
626 NS_ConvertUTF16toUTF8 utf8Data(aData);
628 for (const auto& blocklistEntry : utf8Data.Split('\n')) {
629 GfxDriverInfo di;
630 if (BlocklistEntryToDriverInfo(blocklistEntry, di)) {
631 // XXX Changing this to driverInfo.AppendElement(di) causes leaks.
632 // Probably some non-standard semantics of the copy/move operations?
633 *driverInfo.AppendElement() = di;
634 // Prevent di falling out of scope from destroying the devices.
635 di.mDeleteDevices = false;
636 } else {
637 driverInfo.AppendElement();
641 EvaluateDownloadedBlocklist(driverInfo);
644 return NS_OK;
647 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX), mMutex("GfxInfoBase") {}
649 GfxInfoBase::~GfxInfoBase() = default;
651 nsresult GfxInfoBase::Init() {
652 InitGfxDriverInfoShutdownObserver();
654 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
655 if (os) {
656 os->AddObserver(this, "blocklist-data-gfxItems", true);
659 return NS_OK;
662 void GfxInfoBase::GetData() {
663 if (mScreenPixels != INT64_MAX) {
664 // Already initialized.
665 return;
668 nsCOMPtr<nsIScreenManager> manager =
669 do_GetService("@mozilla.org/gfx/screenmanager;1");
670 if (!manager) {
671 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
672 return;
675 manager->GetTotalScreenPixels(&mScreenPixels);
678 NS_IMETHODIMP
679 GfxInfoBase::GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
680 int32_t* aStatus) {
681 // Ignore the gfx.blocklist.all pref on release and beta.
682 #if defined(RELEASE_OR_BETA)
683 int32_t blocklistAll = 0;
684 #else
685 int32_t blocklistAll = StaticPrefs::gfx_blocklist_all_AtStartup();
686 #endif
687 if (blocklistAll > 0) {
688 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
689 << "Forcing blocklisting all features";
690 *aStatus = FEATURE_BLOCKED_DEVICE;
691 aFailureId = "FEATURE_FAILURE_BLOCK_ALL";
692 return NS_OK;
693 } else if (blocklistAll < 0) {
694 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
695 << "Ignoring any feature blocklisting.";
696 *aStatus = FEATURE_STATUS_OK;
697 return NS_OK;
700 if (GetPrefValueForFeature(aFeature, *aStatus, aFailureId)) {
701 return NS_OK;
704 if (XRE_IsContentProcess() || XRE_IsGPUProcess()) {
705 // Use the cached data received from the parent process.
706 MOZ_ASSERT(sFeatureStatus);
707 bool success = false;
708 for (const auto& fs : *sFeatureStatus) {
709 if (fs.feature() == aFeature) {
710 aFailureId = fs.failureId();
711 *aStatus = fs.status();
712 success = true;
713 break;
716 return success ? NS_OK : NS_ERROR_FAILURE;
719 nsString version;
720 nsTArray<GfxDriverInfo> driverInfo;
721 nsresult rv =
722 GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo, aFailureId);
723 return rv;
726 nsTArray<gfx::GfxInfoFeatureStatus> GfxInfoBase::GetAllFeatures() {
727 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
728 if (!sFeatureStatus) {
729 InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>());
730 for (int32_t i = 1; i <= nsIGfxInfo::FEATURE_MAX_VALUE; ++i) {
731 int32_t status = 0;
732 nsAutoCString failureId;
733 GetFeatureStatus(i, failureId, &status);
734 gfx::GfxInfoFeatureStatus gfxFeatureStatus;
735 gfxFeatureStatus.feature() = i;
736 gfxFeatureStatus.status() = status;
737 gfxFeatureStatus.failureId() = failureId;
738 sFeatureStatus->AppendElement(gfxFeatureStatus);
742 nsTArray<gfx::GfxInfoFeatureStatus> features;
743 for (const auto& status : *sFeatureStatus) {
744 gfx::GfxInfoFeatureStatus copy = status;
745 features.AppendElement(copy);
747 return features;
750 inline bool MatchingAllowStatus(int32_t aStatus) {
751 switch (aStatus) {
752 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS:
753 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED:
754 return true;
755 default:
756 return false;
760 // Matching OS go somewhat beyond the simple equality check because of the
761 // "All Windows" and "All OS X" variations.
763 // aBlockedOS is describing the system(s) we are trying to block.
764 // aSystemOS is describing the system we are running on.
766 // aSystemOS should not be "Windows" or "OSX" - it should be set to
767 // a particular version instead.
768 // However, it is valid for aBlockedOS to be one of those generic values,
769 // as we could be blocking all of the versions.
770 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS,
771 OperatingSystem aSystemOS,
772 uint32_t aSystemOSBuild) {
773 MOZ_ASSERT(aSystemOS != OperatingSystem::Windows &&
774 aSystemOS != OperatingSystem::OSX);
776 // If the block entry OS is unknown, it doesn't match
777 if (aBlockedOS == OperatingSystem::Unknown) {
778 return false;
781 #if defined(XP_WIN)
782 if (aBlockedOS == OperatingSystem::Windows) {
783 // We do want even "unknown" aSystemOS to fall under "all windows"
784 return true;
787 constexpr uint32_t kMinWin10BuildNumber = 18362;
788 if (aBlockedOS == OperatingSystem::RecentWindows10 &&
789 aSystemOS == OperatingSystem::Windows10) {
790 // For allowlist purposes, we sometimes want to restrict to only recent
791 // versions of Windows 10. This is a bit of a kludge but easier than adding
792 // complicated blocklist infrastructure for build ID comparisons like driver
793 // versions.
794 return aSystemOSBuild >= kMinWin10BuildNumber;
797 if (aBlockedOS == OperatingSystem::NotRecentWindows10) {
798 if (aSystemOS == OperatingSystem::Windows10) {
799 return aSystemOSBuild < kMinWin10BuildNumber;
800 } else {
801 return true;
804 #endif
806 #if defined(XP_MACOSX)
807 if (aBlockedOS == OperatingSystem::OSX) {
808 // We do want even "unknown" aSystemOS to fall under "all OS X"
809 return true;
811 #endif
813 return aSystemOS == aBlockedOS;
816 inline bool MatchingBattery(BatteryStatus aBatteryStatus, bool aHasBattery) {
817 switch (aBatteryStatus) {
818 case BatteryStatus::All:
819 return true;
820 case BatteryStatus::None:
821 return !aHasBattery;
822 case BatteryStatus::Present:
823 return aHasBattery;
826 MOZ_ASSERT_UNREACHABLE("bad battery status");
827 return false;
830 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus,
831 int64_t aScreenPixels) {
832 constexpr int64_t kMaxSmallPixels = 2304000; // 1920x1200
833 constexpr int64_t kMaxMediumPixels = 4953600; // 3440x1440
835 switch (aScreenStatus) {
836 case ScreenSizeStatus::All:
837 return true;
838 case ScreenSizeStatus::Small:
839 return aScreenPixels <= kMaxSmallPixels;
840 case ScreenSizeStatus::SmallAndMedium:
841 return aScreenPixels <= kMaxMediumPixels;
842 case ScreenSizeStatus::Medium:
843 return aScreenPixels > kMaxSmallPixels &&
844 aScreenPixels <= kMaxMediumPixels;
845 case ScreenSizeStatus::MediumAndLarge:
846 return aScreenPixels > kMaxSmallPixels;
847 case ScreenSizeStatus::Large:
848 return aScreenPixels > kMaxMediumPixels;
851 MOZ_ASSERT_UNREACHABLE("bad screen status");
852 return false;
855 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
856 const nsTArray<GfxDriverInfo>& info, nsAString& aSuggestedVersion,
857 int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
858 bool aForAllowing) {
859 int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
861 // Some properties are not available on all platforms.
862 nsAutoString desktopEnvironment;
863 nsresult rv = GetDesktopEnvironment(desktopEnvironment);
864 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
865 return 0;
868 nsAutoString windowProtocol;
869 rv = GetWindowProtocol(windowProtocol);
870 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
871 return 0;
874 bool hasBattery = false;
875 rv = GetHasBattery(&hasBattery);
876 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
877 return 0;
880 uint32_t osBuild = OperatingSystemBuild();
882 // Get the adapters once then reuse below
883 nsAutoString adapterVendorID[2];
884 nsAutoString adapterDeviceID[2];
885 nsAutoString adapterDriverVendor[2];
886 nsAutoString adapterDriverVersionString[2];
887 bool adapterInfoFailed[2];
889 adapterInfoFailed[0] =
890 (NS_FAILED(GetAdapterVendorID(adapterVendorID[0])) ||
891 NS_FAILED(GetAdapterDeviceID(adapterDeviceID[0])) ||
892 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor[0])) ||
893 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString[0])));
894 adapterInfoFailed[1] =
895 (NS_FAILED(GetAdapterVendorID2(adapterVendorID[1])) ||
896 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID[1])) ||
897 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor[1])) ||
898 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString[1])));
899 // No point in going on if we don't have adapter info
900 if (adapterInfoFailed[0] && adapterInfoFailed[1]) {
901 return 0;
904 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
905 uint64_t driverVersion[2] = {0, 0};
906 if (!adapterInfoFailed[0]) {
907 ParseDriverVersion(adapterDriverVersionString[0], &driverVersion[0]);
909 if (!adapterInfoFailed[1]) {
910 ParseDriverVersion(adapterDriverVersionString[1], &driverVersion[1]);
912 #endif
914 uint32_t i = 0;
915 for (; i < info.Length(); i++) {
916 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
917 // blocklisting. Only consider entries for our search mode.
918 if (MatchingAllowStatus(info[i].mFeatureStatus) != aForAllowing) {
919 continue;
922 // If we don't have the info for this GPU, no need to check further.
923 // It is unclear that we would ever have a mixture of 1st and 2nd
924 // GPU, but leaving the code in for that possibility for now.
925 // (Actually, currently mGpu2 will never be true, so this can
926 // be optimized out.)
927 uint32_t infoIndex = info[i].mGpu2 ? 1 : 0;
928 if (adapterInfoFailed[infoIndex]) {
929 continue;
932 // Do the operating system check first, no point in getting the driver
933 // info if we won't need to use it.
934 if (!MatchingOperatingSystems(info[i].mOperatingSystem, os, osBuild)) {
935 continue;
938 if (info[i].mOperatingSystemVersion &&
939 info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
940 continue;
943 if (!MatchingBattery(info[i].mBattery, hasBattery)) {
944 continue;
947 if (!MatchingScreenSize(info[i].mScreen, mScreenPixels)) {
948 continue;
951 if (!DoesDesktopEnvironmentMatch(info[i].mDesktopEnvironment,
952 desktopEnvironment)) {
953 continue;
956 if (!DoesWindowProtocolMatch(info[i].mWindowProtocol, windowProtocol)) {
957 continue;
960 if (!DoesVendorMatch(info[i].mAdapterVendor, adapterVendorID[infoIndex])) {
961 continue;
964 if (!DoesDriverVendorMatch(info[i].mDriverVendor,
965 adapterDriverVendor[infoIndex])) {
966 continue;
969 if (info[i].mDevices && !info[i].mDevices->IsEmpty()) {
970 nsresult rv = info[i].mDevices->Contains(adapterDeviceID[infoIndex]);
971 if (rv == NS_ERROR_NOT_AVAILABLE) {
972 // Not found
973 continue;
975 if (rv != NS_OK) {
976 // Failed to search, allowlist should not match, blocklist should match
977 // for safety reasons
978 if (aForAllowing) {
979 continue;
981 break;
985 bool match = false;
987 if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
988 continue;
990 if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
991 continue;
993 if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
994 continue;
996 if (!info[i].mManufacturer.IsEmpty() &&
997 !info[i].mManufacturer.Equals(Manufacturer())) {
998 continue;
1001 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
1002 switch (info[i].mComparisonOp) {
1003 case DRIVER_LESS_THAN:
1004 match = driverVersion[infoIndex] < info[i].mDriverVersion;
1005 break;
1006 case DRIVER_BUILD_ID_LESS_THAN:
1007 match = (driverVersion[infoIndex] & 0xFFFF) < info[i].mDriverVersion;
1008 break;
1009 case DRIVER_LESS_THAN_OR_EQUAL:
1010 match = driverVersion[infoIndex] <= info[i].mDriverVersion;
1011 break;
1012 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL:
1013 match = (driverVersion[infoIndex] & 0xFFFF) <= info[i].mDriverVersion;
1014 break;
1015 case DRIVER_GREATER_THAN:
1016 match = driverVersion[infoIndex] > info[i].mDriverVersion;
1017 break;
1018 case DRIVER_GREATER_THAN_OR_EQUAL:
1019 match = driverVersion[infoIndex] >= info[i].mDriverVersion;
1020 break;
1021 case DRIVER_EQUAL:
1022 match = driverVersion[infoIndex] == info[i].mDriverVersion;
1023 break;
1024 case DRIVER_NOT_EQUAL:
1025 match = driverVersion[infoIndex] != info[i].mDriverVersion;
1026 break;
1027 case DRIVER_BETWEEN_EXCLUSIVE:
1028 match = driverVersion[infoIndex] > info[i].mDriverVersion &&
1029 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1030 break;
1031 case DRIVER_BETWEEN_INCLUSIVE:
1032 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1033 driverVersion[infoIndex] <= info[i].mDriverVersionMax;
1034 break;
1035 case DRIVER_BETWEEN_INCLUSIVE_START:
1036 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1037 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1038 break;
1039 case DRIVER_COMPARISON_IGNORED:
1040 // We don't have a comparison op, so we match everything.
1041 match = true;
1042 break;
1043 default:
1044 NS_WARNING("Bogus op in GfxDriverInfo");
1045 break;
1047 #else
1048 // We don't care what driver version it was. We only check OS version and if
1049 // the device matches.
1050 match = true;
1051 #endif
1053 if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
1054 if ((info[i].mFeature == GfxDriverInfo::allFeatures &&
1055 aFeature != nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE) ||
1056 info[i].mFeature == aFeature) {
1057 status = info[i].mFeatureStatus;
1058 if (!info[i].mRuleId.IsEmpty()) {
1059 aFailureId = info[i].mRuleId.get();
1060 } else {
1061 aFailureId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID";
1063 break;
1068 #if defined(XP_WIN)
1069 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1070 // as either the primary or secondary adapter. D2D is also blocked when the
1071 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1072 // If the primary GPU already matched something in the blocklist then we
1073 // ignore this special rule. See bug 1008759.
1074 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN &&
1075 (aFeature == nsIGfxInfo::FEATURE_DIRECT2D)) {
1076 if (!adapterInfoFailed[1]) {
1077 nsAString& nvVendorID =
1078 (nsAString&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA);
1079 const nsString nv310mDeviceId = u"0x0A70"_ns;
1080 if (nvVendorID.Equals(adapterVendorID[1],
1081 nsCaseInsensitiveStringComparator) &&
1082 nv310mDeviceId.Equals(adapterDeviceID[1],
1083 nsCaseInsensitiveStringComparator)) {
1084 status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
1085 aFailureId = "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1090 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1091 // back to the Windows handler, so we must handle this here.
1092 if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
1093 if (info[i].mSuggestedVersion) {
1094 aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
1095 } else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
1096 info[i].mDriverVersion != GfxDriverInfo::allDriverVersions) {
1097 aSuggestedVersion.AppendPrintf(
1098 "%lld.%lld.%lld.%lld",
1099 (info[i].mDriverVersion & 0xffff000000000000) >> 48,
1100 (info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
1101 (info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
1102 (info[i].mDriverVersion & 0x000000000000ffff));
1105 #endif
1107 return status;
1110 void GfxInfoBase::SetFeatureStatus(nsTArray<gfx::GfxInfoFeatureStatus>&& aFS) {
1111 MOZ_ASSERT(!sFeatureStatus);
1112 InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>(std::move(aFS)));
1115 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1116 const nsAString& aBlocklistDesktop, const nsAString& aDesktopEnv) {
1117 return aBlocklistDesktop.Equals(aDesktopEnv,
1118 nsCaseInsensitiveStringComparator) ||
1119 aBlocklistDesktop.Equals(
1120 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All),
1121 nsCaseInsensitiveStringComparator);
1124 bool GfxInfoBase::DoesWindowProtocolMatch(
1125 const nsAString& aBlocklistWindowProtocol,
1126 const nsAString& aWindowProtocol) {
1127 return aBlocklistWindowProtocol.Equals(aWindowProtocol,
1128 nsCaseInsensitiveStringComparator) ||
1129 aBlocklistWindowProtocol.Equals(
1130 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All),
1131 nsCaseInsensitiveStringComparator);
1134 bool GfxInfoBase::DoesVendorMatch(const nsAString& aBlocklistVendor,
1135 const nsAString& aAdapterVendor) {
1136 return aBlocklistVendor.Equals(aAdapterVendor,
1137 nsCaseInsensitiveStringComparator) ||
1138 aBlocklistVendor.Equals(
1139 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All),
1140 nsCaseInsensitiveStringComparator);
1143 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
1144 const nsAString& aDriverVendor) {
1145 return aBlocklistVendor.Equals(aDriverVendor,
1146 nsCaseInsensitiveStringComparator) ||
1147 aBlocklistVendor.Equals(
1148 GfxDriverInfo::GetDriverVendor(DriverVendor::All),
1149 nsCaseInsensitiveStringComparator);
1152 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature) const {
1153 return aFeature == nsIGfxInfo::FEATURE_WEBRENDER ||
1154 aFeature == nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE;
1157 nsresult GfxInfoBase::GetFeatureStatusImpl(
1158 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedVersion,
1159 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
1160 OperatingSystem* aOS /* = nullptr */) {
1161 if (aFeature <= 0) {
1162 gfxWarning() << "Invalid feature <= 0";
1163 return NS_OK;
1166 if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1167 // Terminate now with the status determined by the derived type (OS-specific
1168 // code).
1169 return NS_OK;
1172 if (sShutdownOccurred) {
1173 // This is futile; we've already commenced shutdown and our blocklists have
1174 // been deleted. We may want to look into resurrecting the blocklist instead
1175 // but for now, just don't even go there.
1176 return NS_OK;
1179 // Ensure any additional initialization required is complete.
1180 GetData();
1182 // If an operating system was provided by the derived GetFeatureStatusImpl,
1183 // grab it here. Otherwise, the OS is unknown.
1184 OperatingSystem os = (aOS ? *aOS : OperatingSystem::Unknown);
1186 nsAutoString adapterVendorID;
1187 nsAutoString adapterDeviceID;
1188 nsAutoString adapterDriverVersionString;
1189 if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
1190 NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
1191 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString))) {
1192 aFailureId = "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1193 *aStatus = FEATURE_BLOCKED_DEVICE;
1194 return NS_OK;
1197 // Check if the device is blocked from the downloaded blocklist. If not, check
1198 // the static list after that. This order is used so that we can later escape
1199 // out of static blocks (i.e. if we were wrong or something was patched, we
1200 // can back out our static block without doing a release).
1201 int32_t status;
1202 if (aDriverInfo.Length()) {
1203 status =
1204 FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature,
1205 aFailureId, os, /* aForAllowing */ false);
1206 } else {
1207 if (!sDriverInfo) {
1208 sDriverInfo = new nsTArray<GfxDriverInfo>();
1210 status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion,
1211 aFeature, aFailureId, os,
1212 /* aForAllowing */ false);
1215 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1216 if (IsFeatureAllowlisted(aFeature)) {
1217 // This feature is actually using the allowlist; that means after we pass
1218 // the blocklist to prevent us explicitly from getting the feature, we now
1219 // need to check the allowlist to ensure we are allowed to get it in the
1220 // first place.
1221 if (aDriverInfo.Length()) {
1222 status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion,
1223 aFeature, aFailureId, os,
1224 /* aForAllowing */ true);
1225 } else {
1226 status = FindBlocklistedDeviceInList(
1227 GetGfxDriverInfo(), aSuggestedVersion, aFeature, aFailureId, os,
1228 /* aForAllowing */ true);
1231 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1232 status = nsIGfxInfo::FEATURE_DENIED;
1234 } else {
1235 // It's now done being processed. It's safe to set the status to
1236 // STATUS_OK.
1237 status = nsIGfxInfo::FEATURE_STATUS_OK;
1241 *aStatus = status;
1242 return NS_OK;
1245 NS_IMETHODIMP
1246 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
1247 nsAString& aVersion) {
1248 nsCString version;
1249 if (GetPrefValueForDriverVersion(version)) {
1250 aVersion = NS_ConvertASCIItoUTF16(version);
1251 return NS_OK;
1254 int32_t status;
1255 nsCString discardFailureId;
1256 nsTArray<GfxDriverInfo> driverInfo;
1257 return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo,
1258 discardFailureId);
1261 void GfxInfoBase::EvaluateDownloadedBlocklist(
1262 nsTArray<GfxDriverInfo>& aDriverInfo) {
1263 int32_t features[] = {nsIGfxInfo::FEATURE_DIRECT2D,
1264 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
1265 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
1266 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
1267 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS,
1268 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE,
1269 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
1270 nsIGfxInfo::FEATURE_OPENGL_LAYERS,
1271 nsIGfxInfo::FEATURE_WEBGL_OPENGL,
1272 nsIGfxInfo::FEATURE_WEBGL_ANGLE,
1273 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE,
1274 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE,
1275 nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA,
1276 nsIGfxInfo::FEATURE_STAGEFRIGHT,
1277 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264,
1278 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION,
1279 nsIGfxInfo::FEATURE_VP8_HW_DECODE,
1280 nsIGfxInfo::FEATURE_VP9_HW_DECODE,
1281 nsIGfxInfo::FEATURE_DX_INTEROP2,
1282 nsIGfxInfo::FEATURE_GPU_PROCESS,
1283 nsIGfxInfo::FEATURE_WEBGL2,
1284 nsIGfxInfo::FEATURE_ADVANCED_LAYERS,
1285 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX,
1286 nsIGfxInfo::FEATURE_WEBRENDER,
1287 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR,
1288 nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE,
1289 nsIGfxInfo::FEATURE_DX_NV12,
1290 nsIGfxInfo::FEATURE_DX_P010,
1291 nsIGfxInfo::FEATURE_DX_P016,
1292 nsIGfxInfo::FEATURE_GL_SWIZZLE,
1293 nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS,
1296 // For every feature we know about, we evaluate whether this blocklist has a
1297 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1298 // GetFeatureStatus above, so we don't need to hold on to this blocklist
1299 // anywhere permanent.
1300 int i = 0;
1301 while (features[i]) {
1302 int32_t status;
1303 nsCString failureId;
1304 nsAutoString suggestedVersion;
1305 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1306 features[i], &status, suggestedVersion, aDriverInfo, failureId))) {
1307 switch (status) {
1308 default:
1309 case nsIGfxInfo::FEATURE_STATUS_OK:
1310 RemovePrefForFeature(features[i]);
1311 break;
1313 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
1314 if (!suggestedVersion.IsEmpty()) {
1315 SetPrefValueForDriverVersion(suggestedVersion);
1316 } else {
1317 RemovePrefForDriverVersion();
1319 [[fallthrough]];
1321 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION:
1322 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
1323 case nsIGfxInfo::FEATURE_DISCOURAGED:
1324 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
1325 SetPrefValueForFeature(features[i], status, failureId);
1326 break;
1330 ++i;
1334 NS_IMETHODIMP_(void)
1335 GfxInfoBase::LogFailure(const nsACString& failure) {
1336 // gfxCriticalError has a mutex lock of its own, so we may not actually
1337 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1338 // will not return the copy of the logs unless it can get the same lock
1339 // that gfxCriticalError uses. Still, that is so much of an implementation
1340 // detail that it's nicer to just add an extra lock here and in
1341 // ::GetFailures()
1342 MutexAutoLock lock(mMutex);
1344 // By default, gfxCriticalError asserts; make it not assert in this case.
1345 gfxCriticalError(CriticalLog::DefaultOptions(false))
1346 << "(LF) " << failure.BeginReading();
1349 NS_IMETHODIMP GfxInfoBase::GetFailures(nsTArray<int32_t>& indices,
1350 nsTArray<nsCString>& failures) {
1351 MutexAutoLock lock(mMutex);
1353 LogForwarder* logForwarder = Factory::GetLogForwarder();
1354 if (!logForwarder) {
1355 return NS_ERROR_UNEXPECTED;
1358 // There are two string copies in this method, starting with this one. We are
1359 // assuming this is not a big deal, as the size of the array should be small
1360 // and the strings in it should be small as well (the error messages in the
1361 // code.) The second copy happens with the AppendElement() calls.
1362 // Technically, we don't need the mutex lock after the StringVectorCopy()
1363 // call.
1364 LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
1365 LoggingRecord::const_iterator it;
1366 for (it = loggedStrings.begin(); it != loggedStrings.end(); ++it) {
1367 failures.AppendElement(
1368 nsDependentCSubstring(Get<1>(*it).c_str(), Get<1>(*it).size()));
1369 indices.AppendElement(Get<0>(*it));
1372 return NS_OK;
1375 nsTArray<GfxInfoCollectorBase*>* sCollectors;
1377 static void InitCollectors() {
1378 if (!sCollectors) sCollectors = new nsTArray<GfxInfoCollectorBase*>;
1381 nsresult GfxInfoBase::GetInfo(JSContext* aCx,
1382 JS::MutableHandle<JS::Value> aResult) {
1383 InitCollectors();
1384 InfoObject obj(aCx);
1386 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1387 (*sCollectors)[i]->GetInfo(obj);
1390 // Some example property definitions
1391 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1392 // obj.DefineProperty("renderer", mRendererIDsString);
1393 // obj.DefineProperty("five", 5);
1395 if (!obj.mOk) {
1396 return NS_ERROR_FAILURE;
1399 aResult.setObject(*obj.mObj);
1400 return NS_OK;
1403 nsAutoCString gBaseAppVersion;
1405 const nsCString& GfxInfoBase::GetApplicationVersion() {
1406 static bool versionInitialized = false;
1407 if (!versionInitialized) {
1408 // If we fail to get the version, we will not try again.
1409 versionInitialized = true;
1411 // Get the version from xpcom/system/nsIXULAppInfo.idl
1412 nsCOMPtr<nsIXULAppInfo> app = do_GetService("@mozilla.org/xre/app-info;1");
1413 if (app) {
1414 app->GetVersion(gBaseAppVersion);
1417 return gBaseAppVersion;
1420 void GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector) {
1421 InitCollectors();
1422 sCollectors->AppendElement(collector);
1425 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector) {
1426 InitCollectors();
1427 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1428 if ((*sCollectors)[i] == collector) {
1429 sCollectors->RemoveElementAt(i);
1430 break;
1433 if (sCollectors->IsEmpty()) {
1434 delete sCollectors;
1435 sCollectors = nullptr;
1439 nsresult GfxInfoBase::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray) {
1440 // If we have no platform specific implementation for detecting monitors, we
1441 // can just get the screen size from gfxPlatform as the best guess.
1442 if (!gfxPlatform::Initialized()) {
1443 return NS_OK;
1446 // If the screen size is empty, we are probably in xpcshell.
1447 gfx::IntSize screenSize = gfxPlatform::GetPlatform()->GetScreenSize();
1449 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1451 JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value(screenSize.width));
1452 JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
1454 JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value(screenSize.height));
1455 JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
1457 JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
1458 JS_SetElement(aCx, aOutArray, 0, element);
1460 return NS_OK;
1463 NS_IMETHODIMP
1464 GfxInfoBase::GetMonitors(JSContext* aCx, JS::MutableHandleValue aResult) {
1465 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1467 nsresult rv = FindMonitors(aCx, array);
1468 if (NS_FAILED(rv)) {
1469 return rv;
1472 aResult.setObject(*array);
1473 return NS_OK;
1476 static inline bool SetJSPropertyString(JSContext* aCx,
1477 JS::Handle<JSObject*> aObj,
1478 const char* aProp, const char* aString) {
1479 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, aString));
1480 if (!str) {
1481 return false;
1484 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1485 return JS_SetProperty(aCx, aObj, aProp, val);
1488 template <typename T>
1489 static inline bool AppendJSElement(JSContext* aCx, JS::Handle<JSObject*> aObj,
1490 const T& aValue) {
1491 uint32_t index;
1492 if (!JS::GetArrayLength(aCx, aObj, &index)) {
1493 return false;
1495 return JS_SetElement(aCx, aObj, index, aValue);
1498 nsresult GfxInfoBase::GetFeatures(JSContext* aCx,
1499 JS::MutableHandle<JS::Value> aOut) {
1500 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1501 if (!obj) {
1502 return NS_ERROR_OUT_OF_MEMORY;
1504 aOut.setObject(*obj);
1506 layers::LayersBackend backend =
1507 gfxPlatform::Initialized()
1508 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1509 : layers::LayersBackend::LAYERS_NONE;
1510 const char* backendName = layers::GetLayersBackendName(backend);
1511 SetJSPropertyString(aCx, obj, "compositor", backendName);
1513 // If graphics isn't initialized yet, just stop now.
1514 if (!gfxPlatform::Initialized()) {
1515 return NS_OK;
1518 DescribeFeatures(aCx, obj);
1519 return NS_OK;
1522 nsresult GfxInfoBase::GetFeatureLog(JSContext* aCx,
1523 JS::MutableHandle<JS::Value> aOut) {
1524 JS::Rooted<JSObject*> containerObj(aCx, JS_NewPlainObject(aCx));
1525 if (!containerObj) {
1526 return NS_ERROR_OUT_OF_MEMORY;
1528 aOut.setObject(*containerObj);
1530 JS::Rooted<JSObject*> featureArray(aCx, JS::NewArrayObject(aCx, 0));
1531 if (!featureArray) {
1532 return NS_ERROR_OUT_OF_MEMORY;
1535 // Collect features.
1536 gfxConfig::ForEachFeature([&](const char* aName, const char* aDescription,
1537 FeatureState& aFeature) -> void {
1538 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1539 if (!obj) {
1540 return;
1542 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1543 !SetJSPropertyString(aCx, obj, "description", aDescription) ||
1544 !SetJSPropertyString(aCx, obj, "status",
1545 FeatureStatusToString(aFeature.GetValue()))) {
1546 return;
1549 JS::Rooted<JS::Value> log(aCx);
1550 if (!BuildFeatureStateLog(aCx, aFeature, &log)) {
1551 return;
1553 if (!JS_SetProperty(aCx, obj, "log", log)) {
1554 return;
1557 if (!AppendJSElement(aCx, featureArray, obj)) {
1558 return;
1562 JS::Rooted<JSObject*> fallbackArray(aCx, JS::NewArrayObject(aCx, 0));
1563 if (!fallbackArray) {
1564 return NS_ERROR_OUT_OF_MEMORY;
1567 // Collect fallbacks.
1568 gfxConfig::ForEachFallback(
1569 [&](const char* aName, const char* aMessage) -> void {
1570 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1571 if (!obj) {
1572 return;
1575 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1576 !SetJSPropertyString(aCx, obj, "message", aMessage)) {
1577 return;
1580 if (!AppendJSElement(aCx, fallbackArray, obj)) {
1581 return;
1585 JS::Rooted<JS::Value> val(aCx);
1587 val = JS::ObjectValue(*featureArray);
1588 JS_SetProperty(aCx, containerObj, "features", val);
1590 val = JS::ObjectValue(*fallbackArray);
1591 JS_SetProperty(aCx, containerObj, "fallbacks", val);
1593 return NS_OK;
1596 bool GfxInfoBase::BuildFeatureStateLog(JSContext* aCx,
1597 const FeatureState& aFeature,
1598 JS::MutableHandle<JS::Value> aOut) {
1599 JS::Rooted<JSObject*> log(aCx, JS::NewArrayObject(aCx, 0));
1600 if (!log) {
1601 return false;
1603 aOut.setObject(*log);
1605 aFeature.ForEachStatusChange([&](const char* aType, FeatureStatus aStatus,
1606 const char* aMessage,
1607 const nsCString& aFailureId) -> void {
1608 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1609 if (!obj) {
1610 return;
1613 if (!SetJSPropertyString(aCx, obj, "type", aType) ||
1614 !SetJSPropertyString(aCx, obj, "status",
1615 FeatureStatusToString(aStatus)) ||
1616 (aMessage && !SetJSPropertyString(aCx, obj, "message", aMessage))) {
1617 return;
1620 if (!AppendJSElement(aCx, log, obj)) {
1621 return;
1625 return true;
1628 void GfxInfoBase::DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> aObj) {
1629 JS::Rooted<JSObject*> obj(aCx);
1631 gfx::FeatureState& hwCompositing =
1632 gfxConfig::GetFeature(gfx::Feature::HW_COMPOSITING);
1633 InitFeatureObject(aCx, aObj, "hwCompositing", hwCompositing, &obj);
1635 gfx::FeatureState& gpuProcess =
1636 gfxConfig::GetFeature(gfx::Feature::GPU_PROCESS);
1637 InitFeatureObject(aCx, aObj, "gpuProcess", gpuProcess, &obj);
1639 gfx::FeatureState& wrQualified =
1640 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_QUALIFIED);
1641 InitFeatureObject(aCx, aObj, "wrQualified", wrQualified, &obj);
1643 gfx::FeatureState& webrender = gfxConfig::GetFeature(gfx::Feature::WEBRENDER);
1644 InitFeatureObject(aCx, aObj, "webrender", webrender, &obj);
1646 gfx::FeatureState& wrCompositor =
1647 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_COMPOSITOR);
1648 InitFeatureObject(aCx, aObj, "wrCompositor", wrCompositor, &obj);
1650 gfx::FeatureState& wrSoftware =
1651 gfxConfig::GetFeature(gfx::Feature::WEBRENDER_SOFTWARE);
1652 InitFeatureObject(aCx, aObj, "wrSoftware", wrSoftware, &obj);
1654 gfx::FeatureState& openglCompositing =
1655 gfxConfig::GetFeature(gfx::Feature::OPENGL_COMPOSITING);
1656 InitFeatureObject(aCx, aObj, "openglCompositing", openglCompositing, &obj);
1658 gfx::FeatureState& omtp =
1659 gfxConfig::GetFeature(gfx::Feature::OMTP);
1660 InitFeatureObject(aCx, aObj, "omtp", omtp, &obj);
1662 // Only include AL if the platform attempted to use it.
1663 gfx::FeatureState& advancedLayers =
1664 gfxConfig::GetFeature(gfx::Feature::ADVANCED_LAYERS);
1665 if (advancedLayers.GetValue() != FeatureStatus::Unused) {
1666 InitFeatureObject(aCx, aObj, "advancedLayers", advancedLayers, &obj);
1668 if (gfxConfig::UseFallback(Fallback::NO_CONSTANT_BUFFER_OFFSETTING)) {
1669 JS::Rooted<JS::Value> trueVal(aCx, JS::BooleanValue(true));
1670 JS_SetProperty(aCx, obj, "noConstantBufferOffsetting", trueVal);
1675 bool GfxInfoBase::InitFeatureObject(JSContext* aCx,
1676 JS::Handle<JSObject*> aContainer,
1677 const char* aName,
1678 mozilla::gfx::FeatureState& aFeatureState,
1679 JS::MutableHandle<JSObject*> aOutObj) {
1680 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1681 if (!obj) {
1682 return false;
1685 nsCString status;
1686 auto value = aFeatureState.GetValue();
1687 switch (value) {
1688 case FeatureStatus::Blocklisted:
1689 case FeatureStatus::Disabled:
1690 case FeatureStatus::Unavailable:
1691 case FeatureStatus::UnavailableNoAngle:
1692 case FeatureStatus::Blocked:
1693 status.AppendPrintf("%s:%s", FeatureStatusToString(value),
1694 aFeatureState.GetFailureId().get());
1695 break;
1696 default:
1697 status.Append(FeatureStatusToString(value));
1698 break;
1701 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, status.get()));
1702 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1703 JS_SetProperty(aCx, obj, "status", val);
1705 // Add the feature object to the container.
1707 JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
1708 JS_SetProperty(aCx, aContainer, aName, val);
1711 aOutObj.set(obj);
1712 return true;
1715 nsresult GfxInfoBase::GetActiveCrashGuards(JSContext* aCx,
1716 JS::MutableHandle<JS::Value> aOut) {
1717 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1718 if (!array) {
1719 return NS_ERROR_OUT_OF_MEMORY;
1721 aOut.setObject(*array);
1723 DriverCrashGuard::ForEachActiveCrashGuard(
1724 [&](const char* aName, const char* aPrefName) -> void {
1725 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1726 if (!obj) {
1727 return;
1729 if (!SetJSPropertyString(aCx, obj, "type", aName)) {
1730 return;
1732 if (!SetJSPropertyString(aCx, obj, "prefName", aPrefName)) {
1733 return;
1735 if (!AppendJSElement(aCx, array, obj)) {
1736 return;
1740 return NS_OK;
1743 NS_IMETHODIMP
1744 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled) {
1745 *aWebRenderEnabled = gfxVars::UseWebRender();
1746 return NS_OK;
1749 NS_IMETHODIMP
1750 GfxInfoBase::GetUsesTiling(bool* aUsesTiling) {
1751 *aUsesTiling = gfxPlatform::GetPlatform()->UsesTiling();
1752 return NS_OK;
1755 NS_IMETHODIMP
1756 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling) {
1757 *aUsesTiling = gfxPlatform::GetPlatform()->ContentUsesTiling();
1758 return NS_OK;
1761 NS_IMETHODIMP
1762 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled) {
1763 *aOffMainThreadPaintEnabled = gfxConfig::IsEnabled(gfx::Feature::OMTP);
1764 return NS_OK;
1767 NS_IMETHODIMP
1768 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1769 int32_t* aOffMainThreadPaintWorkerCount) {
1770 if (gfxConfig::IsEnabled(gfx::Feature::OMTP)) {
1771 *aOffMainThreadPaintWorkerCount =
1772 layers::PaintThread::CalculatePaintWorkerCount();
1773 } else {
1774 *aOffMainThreadPaintWorkerCount = 0;
1776 return NS_OK;
1779 NS_IMETHODIMP
1780 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate) {
1781 *aTargetFrameRate = gfxPlatform::TargetFrameRate();
1782 return NS_OK;
1785 NS_IMETHODIMP
1786 GfxInfoBase::GetIsHeadless(bool* aIsHeadless) {
1787 *aIsHeadless = gfxPlatform::IsHeadless();
1788 return NS_OK;
1791 NS_IMETHODIMP
1792 GfxInfoBase::GetContentBackend(nsAString& aContentBackend) {
1793 BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1794 nsString outStr;
1796 switch (backend) {
1797 case BackendType::DIRECT2D1_1: {
1798 outStr.AppendPrintf("Direct2D 1.1");
1799 break;
1801 case BackendType::SKIA: {
1802 outStr.AppendPrintf("Skia");
1803 break;
1805 case BackendType::CAIRO: {
1806 outStr.AppendPrintf("Cairo");
1807 break;
1809 default:
1810 return NS_ERROR_FAILURE;
1813 aContentBackend.Assign(outStr);
1814 return NS_OK;
1817 NS_IMETHODIMP
1818 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue) {
1819 GPUProcessManager* gpu = GPUProcessManager::Get();
1820 if (!gpu) {
1821 // Not supported in content processes.
1822 return NS_ERROR_FAILURE;
1825 *aOutValue = !!gpu->GetGPUChild();
1826 return NS_OK;
1829 NS_IMETHODIMP
1830 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) {
1831 gfxPlatform::GetPlatform();
1833 GPUProcessManager* gpm = GPUProcessManager::Get();
1834 if (aEnable) {
1835 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS)) {
1836 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1838 gpm->LaunchGPUProcess();
1839 gpm->EnsureGPUReady();
1840 } else {
1841 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1842 gpm->KillProcess();
1845 *_retval = true;
1846 return NS_OK;
1849 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1850 GfxInfoBase::AddCollector(this);
1853 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1854 GfxInfoBase::RemoveCollector(this);