Bug 1614864 [wpt PR 21746] - [webnfc] Add WPT tests for smart poster, a=testonly
[gecko.git] / widget / GfxInfoBase.cpp
blob27e7a67312173d9e1021c7e07bcd2f32cefa14f2
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 "GfxDriverInfo.h"
13 #include "js/Array.h" // JS::GetArrayLength, JS::NewArrayObject
14 #include "nsCOMPtr.h"
15 #include "nsCOMArray.h"
16 #include "nsString.h"
17 #include "nsUnicharUtils.h"
18 #include "nsVersionComparator.h"
19 #include "mozilla/Services.h"
20 #include "mozilla/Observer.h"
21 #include "nsIObserver.h"
22 #include "nsIObserverService.h"
23 #include "nsIScreenManager.h"
24 #include "nsTArray.h"
25 #include "nsXULAppAPI.h"
26 #include "nsIXULAppInfo.h"
27 #include "mozilla/Preferences.h"
28 #include "mozilla/StaticPrefs_gfx.h"
29 #include "mozilla/gfx/2D.h"
30 #include "mozilla/gfx/GPUProcessManager.h"
31 #include "mozilla/gfx/Logging.h"
32 #include "mozilla/gfx/gfxVars.h"
33 #include "mozilla/layers/PaintThread.h"
35 #include "gfxPlatform.h"
36 #include "gfxConfig.h"
37 #include "DriverCrashGuard.h"
39 using namespace mozilla::widget;
40 using namespace mozilla;
41 using mozilla::MutexAutoLock;
43 nsTArray<GfxDriverInfo>* GfxInfoBase::sDriverInfo;
44 nsTArray<dom::GfxInfoFeatureStatus>* GfxInfoBase::sFeatureStatus;
45 bool GfxInfoBase::sDriverInfoObserverInitialized;
46 bool GfxInfoBase::sShutdownOccurred;
48 // Observes for shutdown so that the child GfxDriverInfo list is freed.
49 class ShutdownObserver : public nsIObserver {
50 virtual ~ShutdownObserver() {}
52 public:
53 ShutdownObserver() {}
55 NS_DECL_ISUPPORTS
57 NS_IMETHOD Observe(nsISupports* subject, const char* aTopic,
58 const char16_t* aData) override {
59 MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
61 delete GfxInfoBase::sDriverInfo;
62 GfxInfoBase::sDriverInfo = nullptr;
64 delete GfxInfoBase::sFeatureStatus;
65 GfxInfoBase::sFeatureStatus = nullptr;
67 for (auto& deviceFamily : GfxDriverInfo::sDeviceFamilies) {
68 delete deviceFamily;
69 deviceFamily = nullptr;
72 for (auto& desktop : GfxDriverInfo::sDesktopEnvironment) {
73 delete desktop;
74 desktop = nullptr;
77 for (auto& windowProtocol : GfxDriverInfo::sWindowProtocol) {
78 delete windowProtocol;
79 windowProtocol = nullptr;
82 for (auto& deviceVendor : GfxDriverInfo::sDeviceVendors) {
83 delete deviceVendor;
84 deviceVendor = nullptr;
87 for (auto& driverVendor : GfxDriverInfo::sDriverVendors) {
88 delete driverVendor;
89 driverVendor = nullptr;
92 GfxInfoBase::sShutdownOccurred = true;
94 return NS_OK;
98 NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
100 static void InitGfxDriverInfoShutdownObserver() {
101 if (GfxInfoBase::sDriverInfoObserverInitialized) return;
103 GfxInfoBase::sDriverInfoObserverInitialized = true;
105 nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
106 if (!observerService) {
107 NS_WARNING("Could not get observer service!");
108 return;
111 ShutdownObserver* obs = new ShutdownObserver();
112 observerService->AddObserver(obs, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
115 using namespace mozilla::widget;
116 using namespace mozilla::gfx;
117 using namespace mozilla;
119 NS_IMPL_ISUPPORTS(GfxInfoBase, nsIGfxInfo, nsIObserver,
120 nsISupportsWeakReference)
122 #define BLACKLIST_PREF_BRANCH "gfx.blacklist."
123 #define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
124 #define BLACKLIST_ENTRY_TAG_NAME "gfxBlacklistEntry"
126 static const char* GetPrefNameForFeature(int32_t aFeature) {
127 const char* name = nullptr;
128 switch (aFeature) {
129 case nsIGfxInfo::FEATURE_DIRECT2D:
130 name = BLACKLIST_PREF_BRANCH "direct2d";
131 break;
132 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
133 name = BLACKLIST_PREF_BRANCH "layers.direct3d9";
134 break;
135 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
136 name = BLACKLIST_PREF_BRANCH "layers.direct3d10";
137 break;
138 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
139 name = BLACKLIST_PREF_BRANCH "layers.direct3d10-1";
140 break;
141 case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS:
142 name = BLACKLIST_PREF_BRANCH "layers.direct3d11";
143 break;
144 case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE:
145 name = BLACKLIST_PREF_BRANCH "direct3d11angle";
146 break;
147 case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING:
148 name = BLACKLIST_PREF_BRANCH "hardwarevideodecoding";
149 break;
150 case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
151 name = BLACKLIST_PREF_BRANCH "layers.opengl";
152 break;
153 case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
154 name = BLACKLIST_PREF_BRANCH "webgl.opengl";
155 break;
156 case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
157 name = BLACKLIST_PREF_BRANCH "webgl.angle";
158 break;
159 case nsIGfxInfo::FEATURE_WEBGL_MSAA:
160 name = BLACKLIST_PREF_BRANCH "webgl.msaa";
161 break;
162 case nsIGfxInfo::FEATURE_STAGEFRIGHT:
163 name = BLACKLIST_PREF_BRANCH "stagefright";
164 break;
165 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264:
166 name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.h264";
167 break;
168 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE:
169 name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.encode";
170 break;
171 case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE:
172 name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.decode";
173 break;
174 case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION:
175 name = BLACKLIST_PREF_BRANCH "canvas2d.acceleration";
176 break;
177 case nsIGfxInfo::FEATURE_DX_INTEROP2:
178 name = BLACKLIST_PREF_BRANCH "dx.interop2";
179 break;
180 case nsIGfxInfo::FEATURE_GPU_PROCESS:
181 name = BLACKLIST_PREF_BRANCH "gpu.process";
182 break;
183 case nsIGfxInfo::FEATURE_WEBGL2:
184 name = BLACKLIST_PREF_BRANCH "webgl2";
185 break;
186 case nsIGfxInfo::FEATURE_ADVANCED_LAYERS:
187 name = BLACKLIST_PREF_BRANCH "layers.advanced";
188 break;
189 case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX:
190 name = BLACKLIST_PREF_BRANCH "d3d11.keyed.mutex";
191 break;
192 case nsIGfxInfo::FEATURE_WEBRENDER:
193 name = BLACKLIST_PREF_BRANCH "webrender";
194 break;
195 case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR:
196 name = BLACKLIST_PREF_BRANCH "webrender.compositor";
197 break;
198 case nsIGfxInfo::FEATURE_DX_NV12:
199 name = BLACKLIST_PREF_BRANCH "dx.nv12";
200 break;
201 case nsIGfxInfo::FEATURE_DX_P010:
202 name = BLACKLIST_PREF_BRANCH "dx.p010";
203 break;
204 case nsIGfxInfo::FEATURE_DX_P016:
205 name = BLACKLIST_PREF_BRANCH "dx.p016";
206 break;
207 case nsIGfxInfo::FEATURE_VP8_HW_DECODE:
208 case nsIGfxInfo::FEATURE_VP9_HW_DECODE:
209 // We don't provide prefs for these features as these are
210 // not handling downloadable blocklist.
211 break;
212 case nsIGfxInfo::FEATURE_GL_SWIZZLE:
213 name = BLACKLIST_PREF_BRANCH "gl.swizzle";
214 break;
215 default:
216 MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
217 break;
220 return name;
223 // Returns the value of the pref for the relevant feature in aValue.
224 // If the pref doesn't exist, aValue is not touched, and returns false.
225 static bool GetPrefValueForFeature(int32_t aFeature, int32_t& aValue,
226 nsACString& aFailureId) {
227 const char* prefname = GetPrefNameForFeature(aFeature);
228 if (!prefname) return false;
230 aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
231 if (!NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue))) {
232 return false;
235 nsCString failureprefname(prefname);
236 failureprefname += ".failureid";
237 nsAutoCString failureValue;
238 nsresult rv = Preferences::GetCString(failureprefname.get(), failureValue);
239 if (NS_SUCCEEDED(rv)) {
240 aFailureId = failureValue.get();
241 } else {
242 aFailureId = "FEATURE_FAILURE_BLACKLIST_PREF";
245 return true;
248 static void SetPrefValueForFeature(int32_t aFeature, int32_t aValue,
249 const nsACString& aFailureId) {
250 const char* prefname = GetPrefNameForFeature(aFeature);
251 if (!prefname) return;
252 if (XRE_IsParentProcess()) {
253 delete GfxInfoBase::sFeatureStatus;
254 GfxInfoBase::sFeatureStatus = nullptr;
257 Preferences::SetInt(prefname, aValue);
258 if (!aFailureId.IsEmpty()) {
259 nsCString failureprefname(prefname);
260 failureprefname += ".failureid";
261 Preferences::SetCString(failureprefname.get(), aFailureId);
265 static void RemovePrefForFeature(int32_t aFeature) {
266 const char* prefname = GetPrefNameForFeature(aFeature);
267 if (!prefname) return;
269 if (XRE_IsParentProcess()) {
270 delete GfxInfoBase::sFeatureStatus;
271 GfxInfoBase::sFeatureStatus = nullptr;
273 Preferences::ClearUser(prefname);
276 static bool GetPrefValueForDriverVersion(nsCString& aVersion) {
277 return NS_SUCCEEDED(
278 Preferences::GetCString(SUGGESTED_VERSION_PREF, aVersion));
281 static void SetPrefValueForDriverVersion(const nsAString& aVersion) {
282 Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion);
285 static void RemovePrefForDriverVersion() {
286 Preferences::ClearUser(SUGGESTED_VERSION_PREF);
289 static OperatingSystem BlacklistOSToOperatingSystem(const nsAString& os) {
290 if (os.EqualsLiteral("WINNT 6.1"))
291 return OperatingSystem::Windows7;
292 else if (os.EqualsLiteral("WINNT 6.2"))
293 return OperatingSystem::Windows8;
294 else if (os.EqualsLiteral("WINNT 6.3"))
295 return OperatingSystem::Windows8_1;
296 else if (os.EqualsLiteral("WINNT 10.0"))
297 return OperatingSystem::Windows10;
298 else if (os.EqualsLiteral("Linux"))
299 return OperatingSystem::Linux;
300 else if (os.EqualsLiteral("Darwin 9"))
301 return OperatingSystem::OSX10_5;
302 else if (os.EqualsLiteral("Darwin 10"))
303 return OperatingSystem::OSX10_6;
304 else if (os.EqualsLiteral("Darwin 11"))
305 return OperatingSystem::OSX10_7;
306 else if (os.EqualsLiteral("Darwin 12"))
307 return OperatingSystem::OSX10_8;
308 else if (os.EqualsLiteral("Darwin 13"))
309 return OperatingSystem::OSX10_9;
310 else if (os.EqualsLiteral("Darwin 14"))
311 return OperatingSystem::OSX10_10;
312 else if (os.EqualsLiteral("Darwin 15"))
313 return OperatingSystem::OSX10_11;
314 else if (os.EqualsLiteral("Darwin 16"))
315 return OperatingSystem::OSX10_12;
316 else if (os.EqualsLiteral("Darwin 17"))
317 return OperatingSystem::OSX10_13;
318 else if (os.EqualsLiteral("Darwin 18"))
319 return OperatingSystem::OSX10_14;
320 else if (os.EqualsLiteral("Darwin 19"))
321 return OperatingSystem::OSX10_15;
322 else if (os.EqualsLiteral("Android"))
323 return OperatingSystem::Android;
324 // For historical reasons, "All" in blocklist means "All Windows"
325 else if (os.EqualsLiteral("All"))
326 return OperatingSystem::Windows;
328 return OperatingSystem::Unknown;
331 static GfxDeviceFamily* BlacklistDevicesToDeviceFamily(
332 nsTArray<nsCString>& devices) {
333 if (devices.Length() == 0) return nullptr;
335 // For each device, get its device ID, and return a freshly-allocated
336 // GfxDeviceFamily with the contents of that array.
337 GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
339 for (uint32_t i = 0; i < devices.Length(); ++i) {
340 // We make sure we don't add any "empty" device entries to the array, so
341 // we don't need to check if devices[i] is empty.
342 deviceIds->Append(NS_ConvertUTF8toUTF16(devices[i]));
345 return deviceIds;
348 static int32_t BlacklistFeatureToGfxFeature(const nsAString& aFeature) {
349 MOZ_ASSERT(!aFeature.IsEmpty());
350 if (aFeature.EqualsLiteral("DIRECT2D"))
351 return nsIGfxInfo::FEATURE_DIRECT2D;
352 else if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS"))
353 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
354 else if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS"))
355 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
356 else if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
357 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
358 else if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS"))
359 return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
360 else if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE"))
361 return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
362 else if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
363 return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
364 else if (aFeature.EqualsLiteral("OPENGL_LAYERS"))
365 return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
366 else if (aFeature.EqualsLiteral("WEBGL_OPENGL"))
367 return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
368 else if (aFeature.EqualsLiteral("WEBGL_ANGLE"))
369 return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
370 else if (aFeature.EqualsLiteral("WEBGL_MSAA"))
371 return nsIGfxInfo::FEATURE_WEBGL_MSAA;
372 else if (aFeature.EqualsLiteral("STAGEFRIGHT"))
373 return nsIGfxInfo::FEATURE_STAGEFRIGHT;
374 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
375 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
376 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
377 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
378 else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264"))
379 return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264;
380 else if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION"))
381 return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
382 else if (aFeature.EqualsLiteral("DX_INTEROP2"))
383 return nsIGfxInfo::FEATURE_DX_INTEROP2;
384 else if (aFeature.EqualsLiteral("GPU_PROCESS"))
385 return nsIGfxInfo::FEATURE_GPU_PROCESS;
386 else if (aFeature.EqualsLiteral("WEBGL2"))
387 return nsIGfxInfo::FEATURE_WEBGL2;
388 else if (aFeature.EqualsLiteral("ADVANCED_LAYERS"))
389 return nsIGfxInfo::FEATURE_ADVANCED_LAYERS;
390 else if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX"))
391 return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
392 else if (aFeature.EqualsLiteral("WEBRENDER"))
393 return nsIGfxInfo::FEATURE_WEBRENDER;
394 else if (aFeature.EqualsLiteral("WEBRENDER_COMPOSITOR"))
395 return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR;
396 else if (aFeature.EqualsLiteral("DX_NV12"))
397 return nsIGfxInfo::FEATURE_DX_NV12;
398 // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
399 // in downloadable blocklist.
400 else if (aFeature.EqualsLiteral("GL_SWIZZLE"))
401 return nsIGfxInfo::FEATURE_GL_SWIZZLE;
403 // If we don't recognize the feature, it may be new, and something
404 // this version doesn't understand. So, nothing to do. This is
405 // different from feature not being specified at all, in which case
406 // this method should not get called and we should continue with the
407 // "all features" blocklisting.
408 return -1;
411 static int32_t BlacklistFeatureStatusToGfxFeatureStatus(
412 const nsAString& aStatus) {
413 if (aStatus.EqualsLiteral("STATUS_OK"))
414 return nsIGfxInfo::FEATURE_STATUS_OK;
415 else if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
416 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
417 else if (aStatus.EqualsLiteral("BLOCKED_DEVICE"))
418 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
419 else if (aStatus.EqualsLiteral("DISCOURAGED"))
420 return nsIGfxInfo::FEATURE_DISCOURAGED;
421 else if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION"))
422 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
423 else if (aStatus.EqualsLiteral("DENIED"))
424 return nsIGfxInfo::FEATURE_DENIED;
425 else if (aStatus.EqualsLiteral("ALLOW_QUALIFIED"))
426 return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
427 else if (aStatus.EqualsLiteral("ALLOW_ALWAYS"))
428 return nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
430 // Do not allow it to set STATUS_UNKNOWN. Also, we are not
431 // expecting the "mismatch" status showing up here.
433 return nsIGfxInfo::FEATURE_STATUS_OK;
436 static VersionComparisonOp BlacklistComparatorToComparisonOp(
437 const nsAString& op) {
438 if (op.EqualsLiteral("LESS_THAN"))
439 return DRIVER_LESS_THAN;
440 else if (op.EqualsLiteral("BUILD_ID_LESS_THAN"))
441 return DRIVER_BUILD_ID_LESS_THAN;
442 else if (op.EqualsLiteral("LESS_THAN_OR_EQUAL"))
443 return DRIVER_LESS_THAN_OR_EQUAL;
444 else if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
445 return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL;
446 else if (op.EqualsLiteral("GREATER_THAN"))
447 return DRIVER_GREATER_THAN;
448 else if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
449 return DRIVER_GREATER_THAN_OR_EQUAL;
450 else if (op.EqualsLiteral("EQUAL"))
451 return DRIVER_EQUAL;
452 else if (op.EqualsLiteral("NOT_EQUAL"))
453 return DRIVER_NOT_EQUAL;
454 else if (op.EqualsLiteral("BETWEEN_EXCLUSIVE"))
455 return DRIVER_BETWEEN_EXCLUSIVE;
456 else if (op.EqualsLiteral("BETWEEN_INCLUSIVE"))
457 return DRIVER_BETWEEN_INCLUSIVE;
458 else if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
459 return DRIVER_BETWEEN_INCLUSIVE_START;
461 return DRIVER_COMPARISON_IGNORED;
465 Deserialize Blacklist entries from string.
466 e.g:
467 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
469 static bool BlacklistEntryToDriverInfo(nsCString& aBlacklistEntry,
470 GfxDriverInfo& aDriverInfo) {
471 // If we get an application version to be zero, something is not working
472 // and we are not going to bother checking the blocklist versions.
473 // See TestGfxWidgets.cpp for how version comparison works.
474 // <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
475 static mozilla::Version zeroV("0");
476 static mozilla::Version appV(GfxInfoBase::GetApplicationVersion().get());
477 if (appV <= zeroV) {
478 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
479 << "Invalid application version "
480 << GfxInfoBase::GetApplicationVersion().get();
483 nsTArray<nsCString> keyValues;
484 ParseString(aBlacklistEntry, '\t', keyValues);
486 aDriverInfo.mRuleId =
487 NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_NO_ID");
489 for (uint32_t i = 0; i < keyValues.Length(); ++i) {
490 nsCString keyValue = keyValues[i];
491 nsTArray<nsCString> splitted;
492 ParseString(keyValue, ':', splitted);
493 if (splitted.Length() != 2) {
494 // If we don't recognize the input data, we do not want to proceed.
495 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
496 << "Unrecognized data " << keyValue.get();
497 return false;
499 nsCString key = splitted[0];
500 nsCString value = splitted[1];
501 NS_ConvertUTF8toUTF16 dataValue(value);
503 if (value.Length() == 0) {
504 // Safety check for empty values.
505 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
506 << "Empty value for " << key.get();
507 return false;
510 if (key.EqualsLiteral("blockID")) {
511 nsCString blockIdStr =
512 NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_") + value;
513 aDriverInfo.mRuleId = blockIdStr.get();
514 } else if (key.EqualsLiteral("os")) {
515 aDriverInfo.mOperatingSystem = BlacklistOSToOperatingSystem(dataValue);
516 } else if (key.EqualsLiteral("osversion")) {
517 aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
518 } else if (key.EqualsLiteral("desktopEnvironment")) {
519 aDriverInfo.mDesktopEnvironment = dataValue;
520 } else if (key.EqualsLiteral("windowProtocol")) {
521 aDriverInfo.mWindowProtocol = dataValue;
522 } else if (key.EqualsLiteral("vendor")) {
523 aDriverInfo.mAdapterVendor = dataValue;
524 } else if (key.EqualsLiteral("driverVendor")) {
525 aDriverInfo.mDriverVendor = dataValue;
526 } else if (key.EqualsLiteral("feature")) {
527 aDriverInfo.mFeature = BlacklistFeatureToGfxFeature(dataValue);
528 if (aDriverInfo.mFeature < 0) {
529 // If we don't recognize the feature, we do not want to proceed.
530 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
531 << "Unrecognized feature " << value.get();
532 return false;
534 } else if (key.EqualsLiteral("featureStatus")) {
535 aDriverInfo.mFeatureStatus =
536 BlacklistFeatureStatusToGfxFeatureStatus(dataValue);
537 } else if (key.EqualsLiteral("driverVersion")) {
538 uint64_t version;
539 if (ParseDriverVersion(dataValue, &version))
540 aDriverInfo.mDriverVersion = version;
541 } else if (key.EqualsLiteral("driverVersionMax")) {
542 uint64_t version;
543 if (ParseDriverVersion(dataValue, &version))
544 aDriverInfo.mDriverVersionMax = version;
545 } else if (key.EqualsLiteral("driverVersionComparator")) {
546 aDriverInfo.mComparisonOp = BlacklistComparatorToComparisonOp(dataValue);
547 } else if (key.EqualsLiteral("model")) {
548 aDriverInfo.mModel = dataValue;
549 } else if (key.EqualsLiteral("product")) {
550 aDriverInfo.mProduct = dataValue;
551 } else if (key.EqualsLiteral("manufacturer")) {
552 aDriverInfo.mManufacturer = dataValue;
553 } else if (key.EqualsLiteral("hardware")) {
554 aDriverInfo.mHardware = dataValue;
555 } else if (key.EqualsLiteral("versionRange")) {
556 nsTArray<nsCString> versionRange;
557 ParseString(value, ',', versionRange);
558 if (versionRange.Length() != 2) {
559 gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
560 << "Unrecognized versionRange " << value.get();
561 return false;
563 nsCString minValue = versionRange[0];
564 nsCString maxValue = versionRange[1];
566 mozilla::Version minV(minValue.get());
567 mozilla::Version maxV(maxValue.get());
569 if (minV > zeroV && !(appV >= minV)) {
570 // The version of the application is less than the minimal version
571 // this blocklist entry applies to, so we can just ignore it by
572 // returning false and letting the caller deal with it.
573 return false;
575 if (maxV > zeroV && !(appV <= maxV)) {
576 // The version of the application is more than the maximal version
577 // this blocklist entry applies to, so we can just ignore it by
578 // returning false and letting the caller deal with it.
579 return false;
581 } else if (key.EqualsLiteral("devices")) {
582 nsTArray<nsCString> devices;
583 ParseString(value, ',', devices);
584 GfxDeviceFamily* deviceIds = BlacklistDevicesToDeviceFamily(devices);
585 if (deviceIds) {
586 // Get GfxDriverInfo to adopt the devices array we created.
587 aDriverInfo.mDeleteDevices = true;
588 aDriverInfo.mDevices = deviceIds;
591 // We explicitly ignore unknown elements.
594 return true;
597 static void BlacklistEntriesToDriverInfo(nsTArray<nsCString>& aBlacklistEntries,
598 nsTArray<GfxDriverInfo>& aDriverInfo) {
599 aDriverInfo.Clear();
600 aDriverInfo.SetLength(aBlacklistEntries.Length());
602 for (uint32_t i = 0; i < aBlacklistEntries.Length(); ++i) {
603 nsCString blacklistEntry = aBlacklistEntries[i];
604 GfxDriverInfo di;
605 if (BlacklistEntryToDriverInfo(blacklistEntry, di)) {
606 aDriverInfo[i] = di;
607 // Prevent di falling out of scope from destroying the devices.
608 di.mDeleteDevices = false;
613 NS_IMETHODIMP
614 GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
615 const char16_t* aData) {
616 if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
617 nsTArray<GfxDriverInfo> driverInfo;
618 nsTArray<nsCString> blacklistEntries;
619 nsCString utf8Data = NS_ConvertUTF16toUTF8(aData);
620 if (utf8Data.Length() > 0) {
621 ParseString(utf8Data, '\n', blacklistEntries);
623 BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
624 EvaluateDownloadedBlacklist(driverInfo);
627 return NS_OK;
630 GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX), mMutex("GfxInfoBase") {}
632 GfxInfoBase::~GfxInfoBase() {}
634 nsresult GfxInfoBase::Init() {
635 InitGfxDriverInfoShutdownObserver();
637 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
638 if (os) {
639 os->AddObserver(this, "blocklist-data-gfxItems", true);
642 return NS_OK;
645 void GfxInfoBase::GetData() {
646 if (mScreenPixels != INT64_MAX) {
647 // Already initialized.
648 return;
651 nsCOMPtr<nsIScreenManager> manager =
652 do_GetService("@mozilla.org/gfx/screenmanager;1");
653 if (!manager) {
654 MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
655 return;
658 manager->GetTotalScreenPixels(&mScreenPixels);
661 NS_IMETHODIMP
662 GfxInfoBase::GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
663 int32_t* aStatus) {
664 // Ignore the gfx.blocklist.all pref on release and beta.
665 #if defined(RELEASE_OR_BETA)
666 int32_t blocklistAll = 0;
667 #else
668 int32_t blocklistAll = StaticPrefs::gfx_blocklist_all_AtStartup();
669 #endif
670 if (blocklistAll > 0) {
671 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
672 << "Forcing blocklisting all features";
673 *aStatus = FEATURE_BLOCKED_DEVICE;
674 aFailureId = "FEATURE_FAILURE_BLOCK_ALL";
675 return NS_OK;
676 } else if (blocklistAll < 0) {
677 gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
678 << "Ignoring any feature blocklisting.";
679 *aStatus = FEATURE_STATUS_OK;
680 return NS_OK;
683 if (GetPrefValueForFeature(aFeature, *aStatus, aFailureId)) {
684 return NS_OK;
687 if (XRE_IsContentProcess()) {
688 // Use the cached data received from the parent process.
689 MOZ_ASSERT(sFeatureStatus);
690 bool success = false;
691 for (const auto& fs : *sFeatureStatus) {
692 if (fs.feature() == aFeature) {
693 aFailureId = fs.failureId();
694 *aStatus = fs.status();
695 success = true;
696 break;
699 return success ? NS_OK : NS_ERROR_FAILURE;
702 nsString version;
703 nsTArray<GfxDriverInfo> driverInfo;
704 nsresult rv =
705 GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo, aFailureId);
706 return rv;
709 void GfxInfoBase::GetAllFeatures(dom::XPCOMInitData& xpcomInit) {
710 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
711 if (!sFeatureStatus) {
712 sFeatureStatus = new nsTArray<dom::GfxInfoFeatureStatus>();
713 for (int32_t i = 1; i <= nsIGfxInfo::FEATURE_MAX_VALUE; ++i) {
714 int32_t status = 0;
715 nsAutoCString failureId;
716 GetFeatureStatus(i, failureId, &status);
717 dom::GfxInfoFeatureStatus gfxFeatureStatus;
718 gfxFeatureStatus.feature() = i;
719 gfxFeatureStatus.status() = status;
720 gfxFeatureStatus.failureId() = failureId;
721 sFeatureStatus->AppendElement(gfxFeatureStatus);
724 for (const auto& status : *sFeatureStatus) {
725 dom::GfxInfoFeatureStatus copy = status;
726 xpcomInit.gfxFeatureStatus().AppendElement(copy);
730 inline bool MatchingAllowStatus(int32_t aStatus) {
731 switch (aStatus) {
732 case nsIGfxInfo::FEATURE_ALLOW_ALWAYS:
733 case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED:
734 return true;
735 default:
736 return false;
740 // Matching OS go somewhat beyond the simple equality check because of the
741 // "All Windows" and "All OS X" variations.
743 // aBlockedOS is describing the system(s) we are trying to block.
744 // aSystemOS is describing the system we are running on.
746 // aSystemOS should not be "Windows" or "OSX" - it should be set to
747 // a particular version instead.
748 // However, it is valid for aBlockedOS to be one of those generic values,
749 // as we could be blocking all of the versions.
750 inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS,
751 OperatingSystem aSystemOS,
752 uint32_t aSystemOSBuild) {
753 MOZ_ASSERT(aSystemOS != OperatingSystem::Windows &&
754 aSystemOS != OperatingSystem::OSX);
756 // If the block entry OS is unknown, it doesn't match
757 if (aBlockedOS == OperatingSystem::Unknown) {
758 return false;
761 #if defined(XP_WIN)
762 if (aBlockedOS == OperatingSystem::Windows) {
763 // We do want even "unknown" aSystemOS to fall under "all windows"
764 return true;
767 constexpr uint32_t kMinWin10BuildNumber = 18362;
768 if (aSystemOSBuild && aBlockedOS == OperatingSystem::RecentWindows10 &&
769 aSystemOS == OperatingSystem::Windows10) {
770 // For allowlist purposes, we sometimes want to restrict to only recent
771 // versions of Windows 10. This is a bit of a kludge but easier than adding
772 // complicated blocklist infrastructure for build ID comparisons like driver
773 // versions.
774 return aSystemOSBuild >= kMinWin10BuildNumber;
776 #endif
778 #if defined(XP_MACOSX)
779 if (aBlockedOS == OperatingSystem::OSX) {
780 // We do want even "unknown" aSystemOS to fall under "all OS X"
781 return true;
783 #endif
785 return aSystemOS == aBlockedOS;
788 inline bool MatchingBattery(BatteryStatus aBatteryStatus, bool aHasBattery) {
789 switch (aBatteryStatus) {
790 case BatteryStatus::All:
791 return true;
792 case BatteryStatus::None:
793 return !aHasBattery;
794 case BatteryStatus::Present:
795 return aHasBattery;
798 MOZ_ASSERT_UNREACHABLE("bad battery status");
799 return false;
802 inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus,
803 int64_t aScreenPixels) {
804 constexpr int64_t kMaxSmallPixels = 2304000; // 1920x1200
805 constexpr int64_t kMaxMediumPixels = 4953600; // 3440x1440
807 switch (aScreenStatus) {
808 case ScreenSizeStatus::All:
809 return true;
810 case ScreenSizeStatus::Small:
811 return aScreenPixels <= kMaxSmallPixels;
812 case ScreenSizeStatus::SmallAndMedium:
813 return aScreenPixels <= kMaxMediumPixels;
814 case ScreenSizeStatus::Medium:
815 return aScreenPixels > kMaxSmallPixels &&
816 aScreenPixels <= kMaxMediumPixels;
817 case ScreenSizeStatus::MediumAndLarge:
818 return aScreenPixels > kMaxSmallPixels;
819 case ScreenSizeStatus::Large:
820 return aScreenPixels > kMaxMediumPixels;
823 MOZ_ASSERT_UNREACHABLE("bad screen status");
824 return false;
827 int32_t GfxInfoBase::FindBlocklistedDeviceInList(
828 const nsTArray<GfxDriverInfo>& info, nsAString& aSuggestedVersion,
829 int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
830 bool aForAllowing) {
831 int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
833 // Some properties are not available on all platforms.
834 nsAutoString desktopEnvironment;
835 nsresult rv = GetDesktopEnvironment(desktopEnvironment);
836 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
837 return 0;
840 nsAutoString windowProtocol;
841 rv = GetWindowProtocol(windowProtocol);
842 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
843 return 0;
846 bool hasBattery = false;
847 rv = GetHasBattery(&hasBattery);
848 if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
849 return 0;
852 // OS build number is only used for the allowlist.
853 uint32_t osBuild = aForAllowing ? OperatingSystemBuild() : 0;
855 // Get the adapters once then reuse below
856 nsAutoString adapterVendorID[2];
857 nsAutoString adapterDeviceID[2];
858 nsAutoString adapterDriverVendor[2];
859 nsAutoString adapterDriverVersionString[2];
860 bool adapterInfoFailed[2];
862 adapterInfoFailed[0] =
863 (NS_FAILED(GetAdapterVendorID(adapterVendorID[0])) ||
864 NS_FAILED(GetAdapterDeviceID(adapterDeviceID[0])) ||
865 NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor[0])) ||
866 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString[0])));
867 adapterInfoFailed[1] =
868 (NS_FAILED(GetAdapterVendorID2(adapterVendorID[1])) ||
869 NS_FAILED(GetAdapterDeviceID2(adapterDeviceID[1])) ||
870 NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor[1])) ||
871 NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString[1])));
872 // No point in going on if we don't have adapter info
873 if (adapterInfoFailed[0] && adapterInfoFailed[1]) {
874 return 0;
877 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
878 uint64_t driverVersion[2] = {0, 0};
879 if (!adapterInfoFailed[0]) {
880 ParseDriverVersion(adapterDriverVersionString[0], &driverVersion[0]);
882 if (!adapterInfoFailed[1]) {
883 ParseDriverVersion(adapterDriverVersionString[1], &driverVersion[1]);
885 #endif
887 uint32_t i = 0;
888 for (; i < info.Length(); i++) {
889 // If the status is FEATURE_ALLOW_*, then it is for the allowlist, not
890 // blocklisting. Only consider entries for our search mode.
891 if (MatchingAllowStatus(info[i].mFeatureStatus) != aForAllowing) {
892 continue;
895 // If we don't have the info for this GPU, no need to check further.
896 // It is unclear that we would ever have a mixture of 1st and 2nd
897 // GPU, but leaving the code in for that possibility for now.
898 // (Actually, currently mGpu2 will never be true, so this can
899 // be optimized out.)
900 uint32_t infoIndex = info[i].mGpu2 ? 1 : 0;
901 if (adapterInfoFailed[infoIndex]) {
902 continue;
905 // Do the operating system check first, no point in getting the driver
906 // info if we won't need to use it.
907 if (!MatchingOperatingSystems(info[i].mOperatingSystem, os, osBuild)) {
908 continue;
911 if (info[i].mOperatingSystemVersion &&
912 info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
913 continue;
916 if (!MatchingBattery(info[i].mBattery, hasBattery)) {
917 continue;
920 if (!MatchingScreenSize(info[i].mScreen, mScreenPixels)) {
921 continue;
924 if (!DoesDesktopEnvironmentMatch(info[i].mDesktopEnvironment,
925 desktopEnvironment)) {
926 continue;
929 if (!DoesWindowProtocolMatch(info[i].mWindowProtocol, windowProtocol)) {
930 continue;
933 if (!DoesVendorMatch(info[i].mAdapterVendor, adapterVendorID[infoIndex])) {
934 continue;
937 if (!DoesDriverVendorMatch(info[i].mDriverVendor,
938 adapterDriverVendor[infoIndex])) {
939 continue;
942 if (info[i].mDevices && !info[i].mDevices->IsEmpty()) {
943 nsresult rv = info[i].mDevices->Contains(adapterDeviceID[infoIndex]);
944 if (rv == NS_ERROR_NOT_AVAILABLE) {
945 // Not found
946 continue;
948 if (rv != NS_OK) {
949 // Failed to search, allowlist should not match, blocklist should match
950 // for safety reasons
951 if (aForAllowing) {
952 continue;
954 break;
958 bool match = false;
960 if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
961 continue;
963 if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
964 continue;
966 if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
967 continue;
969 if (!info[i].mManufacturer.IsEmpty() &&
970 !info[i].mManufacturer.Equals(Manufacturer())) {
971 continue;
974 #if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
975 switch (info[i].mComparisonOp) {
976 case DRIVER_LESS_THAN:
977 match = driverVersion[infoIndex] < info[i].mDriverVersion;
978 break;
979 case DRIVER_BUILD_ID_LESS_THAN:
980 match = (driverVersion[infoIndex] & 0xFFFF) < info[i].mDriverVersion;
981 break;
982 case DRIVER_LESS_THAN_OR_EQUAL:
983 match = driverVersion[infoIndex] <= info[i].mDriverVersion;
984 break;
985 case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL:
986 match = (driverVersion[infoIndex] & 0xFFFF) <= info[i].mDriverVersion;
987 break;
988 case DRIVER_GREATER_THAN:
989 match = driverVersion[infoIndex] > info[i].mDriverVersion;
990 break;
991 case DRIVER_GREATER_THAN_OR_EQUAL:
992 match = driverVersion[infoIndex] >= info[i].mDriverVersion;
993 break;
994 case DRIVER_EQUAL:
995 match = driverVersion[infoIndex] == info[i].mDriverVersion;
996 break;
997 case DRIVER_NOT_EQUAL:
998 match = driverVersion[infoIndex] != info[i].mDriverVersion;
999 break;
1000 case DRIVER_BETWEEN_EXCLUSIVE:
1001 match = driverVersion[infoIndex] > info[i].mDriverVersion &&
1002 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1003 break;
1004 case DRIVER_BETWEEN_INCLUSIVE:
1005 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1006 driverVersion[infoIndex] <= info[i].mDriverVersionMax;
1007 break;
1008 case DRIVER_BETWEEN_INCLUSIVE_START:
1009 match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
1010 driverVersion[infoIndex] < info[i].mDriverVersionMax;
1011 break;
1012 case DRIVER_COMPARISON_IGNORED:
1013 // We don't have a comparison op, so we match everything.
1014 match = true;
1015 break;
1016 default:
1017 NS_WARNING("Bogus op in GfxDriverInfo");
1018 break;
1020 #else
1021 // We don't care what driver version it was. We only check OS version and if
1022 // the device matches.
1023 match = true;
1024 #endif
1026 if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
1027 if (info[i].mFeature == GfxDriverInfo::allFeatures ||
1028 info[i].mFeature == aFeature) {
1029 status = info[i].mFeatureStatus;
1030 if (!info[i].mRuleId.IsEmpty()) {
1031 aFailureId = info[i].mRuleId.get();
1032 } else {
1033 aFailureId = "FEATURE_FAILURE_DL_BLACKLIST_NO_ID";
1035 break;
1040 #if defined(XP_WIN)
1041 // As a very special case, we block D2D on machines with an NVidia 310M GPU
1042 // as either the primary or secondary adapter. D2D is also blocked when the
1043 // NV 310M is the primary adapter (using the standard blocklisting mechanism).
1044 // If the primary GPU already matched something in the blocklist then we
1045 // ignore this special rule. See bug 1008759.
1046 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN &&
1047 (aFeature == nsIGfxInfo::FEATURE_DIRECT2D)) {
1048 if (!adapterInfoFailed[1]) {
1049 nsAString& nvVendorID =
1050 (nsAString&)GfxDriverInfo::GetDeviceVendor(DeviceVendor::NVIDIA);
1051 const nsString nv310mDeviceId = NS_LITERAL_STRING("0x0A70");
1052 if (nvVendorID.Equals(adapterVendorID[1],
1053 nsCaseInsensitiveStringComparator()) &&
1054 nv310mDeviceId.Equals(adapterDeviceID[1],
1055 nsCaseInsensitiveStringComparator())) {
1056 status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
1057 aFailureId = "FEATURE_FAILURE_D2D_NV310M_BLOCK";
1062 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
1063 // back to the Windows handler, so we must handle this here.
1064 if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
1065 if (info[i].mSuggestedVersion) {
1066 aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
1067 } else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
1068 info[i].mDriverVersion != GfxDriverInfo::allDriverVersions) {
1069 aSuggestedVersion.AppendPrintf(
1070 "%lld.%lld.%lld.%lld",
1071 (info[i].mDriverVersion & 0xffff000000000000) >> 48,
1072 (info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
1073 (info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
1074 (info[i].mDriverVersion & 0x000000000000ffff));
1077 #endif
1079 return status;
1082 void GfxInfoBase::SetFeatureStatus(
1083 const nsTArray<dom::GfxInfoFeatureStatus>& aFS) {
1084 MOZ_ASSERT(!sFeatureStatus);
1085 sFeatureStatus = new nsTArray<dom::GfxInfoFeatureStatus>(aFS);
1088 bool GfxInfoBase::DoesDesktopEnvironmentMatch(
1089 const nsAString& aBlocklistDesktop, const nsAString& aDesktopEnv) {
1090 return aBlocklistDesktop.Equals(aDesktopEnv,
1091 nsCaseInsensitiveStringComparator()) ||
1092 aBlocklistDesktop.Equals(
1093 GfxDriverInfo::GetDesktopEnvironment(DesktopEnvironment::All),
1094 nsCaseInsensitiveStringComparator());
1097 bool GfxInfoBase::DoesWindowProtocolMatch(
1098 const nsAString& aBlocklistWindowProtocol,
1099 const nsAString& aWindowProtocol) {
1100 return aBlocklistWindowProtocol.Equals(aWindowProtocol,
1101 nsCaseInsensitiveStringComparator()) ||
1102 aBlocklistWindowProtocol.Equals(
1103 GfxDriverInfo::GetWindowProtocol(WindowProtocol::All),
1104 nsCaseInsensitiveStringComparator());
1107 bool GfxInfoBase::DoesVendorMatch(const nsAString& aBlocklistVendor,
1108 const nsAString& aAdapterVendor) {
1109 return aBlocklistVendor.Equals(aAdapterVendor,
1110 nsCaseInsensitiveStringComparator()) ||
1111 aBlocklistVendor.Equals(
1112 GfxDriverInfo::GetDeviceVendor(DeviceVendor::All),
1113 nsCaseInsensitiveStringComparator());
1116 bool GfxInfoBase::DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
1117 const nsAString& aDriverVendor) {
1118 return aBlocklistVendor.Equals(aDriverVendor,
1119 nsCaseInsensitiveStringComparator()) ||
1120 aBlocklistVendor.Equals(
1121 GfxDriverInfo::GetDriverVendor(DriverVendor::All),
1122 nsCaseInsensitiveStringComparator());
1125 bool GfxInfoBase::IsFeatureAllowlisted(int32_t aFeature) const { return false; }
1127 nsresult GfxInfoBase::GetFeatureStatusImpl(
1128 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedVersion,
1129 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
1130 OperatingSystem* aOS /* = nullptr */) {
1131 if (aFeature <= 0) {
1132 gfxWarning() << "Invalid feature <= 0";
1133 return NS_OK;
1136 if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1137 // Terminate now with the status determined by the derived type (OS-specific
1138 // code).
1139 return NS_OK;
1142 if (sShutdownOccurred) {
1143 // This is futile; we've already commenced shutdown and our blocklists have
1144 // been deleted. We may want to look into resurrecting the blocklist instead
1145 // but for now, just don't even go there.
1146 return NS_OK;
1149 // Ensure any additional initialization required is complete.
1150 GetData();
1152 // If an operating system was provided by the derived GetFeatureStatusImpl,
1153 // grab it here. Otherwise, the OS is unknown.
1154 OperatingSystem os = (aOS ? *aOS : OperatingSystem::Unknown);
1156 nsAutoString adapterVendorID;
1157 nsAutoString adapterDeviceID;
1158 nsAutoString adapterDriverVersionString;
1159 if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
1160 NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
1161 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString))) {
1162 aFailureId = "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
1163 *aStatus = FEATURE_BLOCKED_DEVICE;
1164 return NS_OK;
1167 // Check if the device is blocked from the downloaded blocklist. If not, check
1168 // the static list after that. This order is used so that we can later escape
1169 // out of static blocks (i.e. if we were wrong or something was patched, we
1170 // can back out our static block without doing a release).
1171 int32_t status;
1172 if (aDriverInfo.Length()) {
1173 status =
1174 FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature,
1175 aFailureId, os, /* aForAllowing */ false);
1176 } else {
1177 if (!sDriverInfo) {
1178 sDriverInfo = new nsTArray<GfxDriverInfo>();
1180 status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion,
1181 aFeature, aFailureId, os,
1182 /* aForAllowing */ false);
1185 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1186 if (IsFeatureAllowlisted(aFeature)) {
1187 // This feature is actually using the allowlist; that means after we pass
1188 // the blocklist to prevent us explicitly from getting the feature, we now
1189 // need to check the allowlist to ensure we are allowed to get it in the
1190 // first place.
1191 if (aDriverInfo.Length()) {
1192 status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion,
1193 aFeature, aFailureId, os,
1194 /* aForAllowing */ true);
1195 } else {
1196 status = FindBlocklistedDeviceInList(
1197 GetGfxDriverInfo(), aSuggestedVersion, aFeature, aFailureId, os,
1198 /* aForAllowing */ true);
1201 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
1202 status = nsIGfxInfo::FEATURE_DENIED;
1204 } else {
1205 // It's now done being processed. It's safe to set the status to
1206 // STATUS_OK.
1207 status = nsIGfxInfo::FEATURE_STATUS_OK;
1211 *aStatus = status;
1212 return NS_OK;
1215 NS_IMETHODIMP
1216 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
1217 nsAString& aVersion) {
1218 nsCString version;
1219 if (GetPrefValueForDriverVersion(version)) {
1220 aVersion = NS_ConvertASCIItoUTF16(version);
1221 return NS_OK;
1224 int32_t status;
1225 nsCString discardFailureId;
1226 nsTArray<GfxDriverInfo> driverInfo;
1227 return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo,
1228 discardFailureId);
1231 void GfxInfoBase::EvaluateDownloadedBlacklist(
1232 nsTArray<GfxDriverInfo>& aDriverInfo) {
1233 int32_t features[] = {nsIGfxInfo::FEATURE_DIRECT2D,
1234 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
1235 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
1236 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
1237 nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS,
1238 nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE,
1239 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
1240 nsIGfxInfo::FEATURE_OPENGL_LAYERS,
1241 nsIGfxInfo::FEATURE_WEBGL_OPENGL,
1242 nsIGfxInfo::FEATURE_WEBGL_ANGLE,
1243 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE,
1244 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE,
1245 nsIGfxInfo::FEATURE_WEBGL_MSAA,
1246 nsIGfxInfo::FEATURE_STAGEFRIGHT,
1247 nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264,
1248 nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION,
1249 nsIGfxInfo::FEATURE_VP8_HW_DECODE,
1250 nsIGfxInfo::FEATURE_VP9_HW_DECODE,
1251 nsIGfxInfo::FEATURE_DX_INTEROP2,
1252 nsIGfxInfo::FEATURE_GPU_PROCESS,
1253 nsIGfxInfo::FEATURE_WEBGL2,
1254 nsIGfxInfo::FEATURE_ADVANCED_LAYERS,
1255 nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX,
1256 nsIGfxInfo::FEATURE_WEBRENDER,
1257 nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR,
1258 nsIGfxInfo::FEATURE_DX_NV12,
1259 nsIGfxInfo::FEATURE_DX_P010,
1260 nsIGfxInfo::FEATURE_DX_P016,
1261 nsIGfxInfo::FEATURE_GL_SWIZZLE,
1264 // For every feature we know about, we evaluate whether this blacklist has a
1265 // non-STATUS_OK status. If it does, we set the pref we evaluate in
1266 // GetFeatureStatus above, so we don't need to hold on to this blacklist
1267 // anywhere permanent.
1268 int i = 0;
1269 while (features[i]) {
1270 int32_t status;
1271 nsCString failureId;
1272 nsAutoString suggestedVersion;
1273 if (NS_SUCCEEDED(GetFeatureStatusImpl(
1274 features[i], &status, suggestedVersion, aDriverInfo, failureId))) {
1275 switch (status) {
1276 default:
1277 case nsIGfxInfo::FEATURE_STATUS_OK:
1278 RemovePrefForFeature(features[i]);
1279 break;
1281 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
1282 if (!suggestedVersion.IsEmpty()) {
1283 SetPrefValueForDriverVersion(suggestedVersion);
1284 } else {
1285 RemovePrefForDriverVersion();
1287 [[fallthrough]];
1289 case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION:
1290 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
1291 case nsIGfxInfo::FEATURE_DISCOURAGED:
1292 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
1293 SetPrefValueForFeature(features[i], status, failureId);
1294 break;
1298 ++i;
1302 NS_IMETHODIMP_(void)
1303 GfxInfoBase::LogFailure(const nsACString& failure) {
1304 // gfxCriticalError has a mutex lock of its own, so we may not actually
1305 // need this lock. ::GetFailures() accesses the data but the LogForwarder
1306 // will not return the copy of the logs unless it can get the same lock
1307 // that gfxCriticalError uses. Still, that is so much of an implementation
1308 // detail that it's nicer to just add an extra lock here and in
1309 // ::GetFailures()
1310 MutexAutoLock lock(mMutex);
1312 // By default, gfxCriticalError asserts; make it not assert in this case.
1313 gfxCriticalError(CriticalLog::DefaultOptions(false))
1314 << "(LF) " << failure.BeginReading();
1317 NS_IMETHODIMP GfxInfoBase::GetFailures(nsTArray<int32_t>& indices,
1318 nsTArray<nsCString>& failures) {
1319 MutexAutoLock lock(mMutex);
1321 LogForwarder* logForwarder = Factory::GetLogForwarder();
1322 if (!logForwarder) {
1323 return NS_ERROR_UNEXPECTED;
1326 // There are two string copies in this method, starting with this one. We are
1327 // assuming this is not a big deal, as the size of the array should be small
1328 // and the strings in it should be small as well (the error messages in the
1329 // code.) The second copy happens with the AppendElement() calls.
1330 // Technically, we don't need the mutex lock after the StringVectorCopy()
1331 // call.
1332 LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
1333 LoggingRecord::const_iterator it;
1334 for (it = loggedStrings.begin(); it != loggedStrings.end(); ++it) {
1335 failures.AppendElement(
1336 nsDependentCSubstring(Get<1>(*it).c_str(), Get<1>(*it).size()));
1337 indices.AppendElement(Get<0>(*it));
1340 return NS_OK;
1343 nsTArray<GfxInfoCollectorBase*>* sCollectors;
1345 static void InitCollectors() {
1346 if (!sCollectors) sCollectors = new nsTArray<GfxInfoCollectorBase*>;
1349 nsresult GfxInfoBase::GetInfo(JSContext* aCx,
1350 JS::MutableHandle<JS::Value> aResult) {
1351 InitCollectors();
1352 InfoObject obj(aCx);
1354 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1355 (*sCollectors)[i]->GetInfo(obj);
1358 // Some example property definitions
1359 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
1360 // obj.DefineProperty("renderer", mRendererIDsString);
1361 // obj.DefineProperty("five", 5);
1363 if (!obj.mOk) {
1364 return NS_ERROR_FAILURE;
1367 aResult.setObject(*obj.mObj);
1368 return NS_OK;
1371 nsAutoCString gBaseAppVersion;
1373 const nsCString& GfxInfoBase::GetApplicationVersion() {
1374 static bool versionInitialized = false;
1375 if (!versionInitialized) {
1376 // If we fail to get the version, we will not try again.
1377 versionInitialized = true;
1379 // Get the version from xpcom/system/nsIXULAppInfo.idl
1380 nsCOMPtr<nsIXULAppInfo> app = do_GetService("@mozilla.org/xre/app-info;1");
1381 if (app) {
1382 app->GetVersion(gBaseAppVersion);
1385 return gBaseAppVersion;
1388 void GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector) {
1389 InitCollectors();
1390 sCollectors->AppendElement(collector);
1393 void GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector) {
1394 InitCollectors();
1395 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
1396 if ((*sCollectors)[i] == collector) {
1397 sCollectors->RemoveElementAt(i);
1398 break;
1401 if (sCollectors->IsEmpty()) {
1402 delete sCollectors;
1403 sCollectors = nullptr;
1407 nsresult GfxInfoBase::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray) {
1408 // If we have no platform specific implementation for detecting monitors, we
1409 // can just get the screen size from gfxPlatform as the best guess.
1410 if (!gfxPlatform::Initialized()) {
1411 return NS_OK;
1414 // If the screen size is empty, we are probably in xpcshell.
1415 gfx::IntSize screenSize = gfxPlatform::GetPlatform()->GetScreenSize();
1417 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1419 JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value(screenSize.width));
1420 JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
1422 JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value(screenSize.height));
1423 JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
1425 JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
1426 JS_SetElement(aCx, aOutArray, 0, element);
1428 return NS_OK;
1431 NS_IMETHODIMP
1432 GfxInfoBase::GetMonitors(JSContext* aCx, JS::MutableHandleValue aResult) {
1433 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1435 nsresult rv = FindMonitors(aCx, array);
1436 if (NS_FAILED(rv)) {
1437 return rv;
1440 aResult.setObject(*array);
1441 return NS_OK;
1444 static inline bool SetJSPropertyString(JSContext* aCx,
1445 JS::Handle<JSObject*> aObj,
1446 const char* aProp, const char* aString) {
1447 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, aString));
1448 if (!str) {
1449 return false;
1452 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1453 return JS_SetProperty(aCx, aObj, aProp, val);
1456 template <typename T>
1457 static inline bool AppendJSElement(JSContext* aCx, JS::Handle<JSObject*> aObj,
1458 const T& aValue) {
1459 uint32_t index;
1460 if (!JS::GetArrayLength(aCx, aObj, &index)) {
1461 return false;
1463 return JS_SetElement(aCx, aObj, index, aValue);
1466 nsresult GfxInfoBase::GetFeatures(JSContext* aCx,
1467 JS::MutableHandle<JS::Value> aOut) {
1468 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1469 if (!obj) {
1470 return NS_ERROR_OUT_OF_MEMORY;
1472 aOut.setObject(*obj);
1474 layers::LayersBackend backend =
1475 gfxPlatform::Initialized()
1476 ? gfxPlatform::GetPlatform()->GetCompositorBackend()
1477 : layers::LayersBackend::LAYERS_NONE;
1478 const char* backendName = layers::GetLayersBackendName(backend);
1479 SetJSPropertyString(aCx, obj, "compositor", backendName);
1481 // If graphics isn't initialized yet, just stop now.
1482 if (!gfxPlatform::Initialized()) {
1483 return NS_OK;
1486 DescribeFeatures(aCx, obj);
1487 return NS_OK;
1490 nsresult GfxInfoBase::GetFeatureLog(JSContext* aCx,
1491 JS::MutableHandle<JS::Value> aOut) {
1492 JS::Rooted<JSObject*> containerObj(aCx, JS_NewPlainObject(aCx));
1493 if (!containerObj) {
1494 return NS_ERROR_OUT_OF_MEMORY;
1496 aOut.setObject(*containerObj);
1498 JS::Rooted<JSObject*> featureArray(aCx, JS::NewArrayObject(aCx, 0));
1499 if (!featureArray) {
1500 return NS_ERROR_OUT_OF_MEMORY;
1503 // Collect features.
1504 gfxConfig::ForEachFeature([&](const char* aName, const char* aDescription,
1505 FeatureState& aFeature) -> void {
1506 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1507 if (!obj) {
1508 return;
1510 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1511 !SetJSPropertyString(aCx, obj, "description", aDescription) ||
1512 !SetJSPropertyString(aCx, obj, "status",
1513 FeatureStatusToString(aFeature.GetValue()))) {
1514 return;
1517 JS::Rooted<JS::Value> log(aCx);
1518 if (!BuildFeatureStateLog(aCx, aFeature, &log)) {
1519 return;
1521 if (!JS_SetProperty(aCx, obj, "log", log)) {
1522 return;
1525 if (!AppendJSElement(aCx, featureArray, obj)) {
1526 return;
1530 JS::Rooted<JSObject*> fallbackArray(aCx, JS::NewArrayObject(aCx, 0));
1531 if (!fallbackArray) {
1532 return NS_ERROR_OUT_OF_MEMORY;
1535 // Collect fallbacks.
1536 gfxConfig::ForEachFallback(
1537 [&](const char* aName, const char* aMessage) -> void {
1538 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1539 if (!obj) {
1540 return;
1543 if (!SetJSPropertyString(aCx, obj, "name", aName) ||
1544 !SetJSPropertyString(aCx, obj, "message", aMessage)) {
1545 return;
1548 if (!AppendJSElement(aCx, fallbackArray, obj)) {
1549 return;
1553 JS::Rooted<JS::Value> val(aCx);
1555 val = JS::ObjectValue(*featureArray);
1556 JS_SetProperty(aCx, containerObj, "features", val);
1558 val = JS::ObjectValue(*fallbackArray);
1559 JS_SetProperty(aCx, containerObj, "fallbacks", val);
1561 return NS_OK;
1564 bool GfxInfoBase::BuildFeatureStateLog(JSContext* aCx,
1565 const FeatureState& aFeature,
1566 JS::MutableHandle<JS::Value> aOut) {
1567 JS::Rooted<JSObject*> log(aCx, JS::NewArrayObject(aCx, 0));
1568 if (!log) {
1569 return false;
1571 aOut.setObject(*log);
1573 aFeature.ForEachStatusChange([&](const char* aType, FeatureStatus aStatus,
1574 const char* aMessage) -> void {
1575 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1576 if (!obj) {
1577 return;
1580 if (!SetJSPropertyString(aCx, obj, "type", aType) ||
1581 !SetJSPropertyString(aCx, obj, "status",
1582 FeatureStatusToString(aStatus)) ||
1583 (aMessage && !SetJSPropertyString(aCx, obj, "message", aMessage))) {
1584 return;
1587 if (!AppendJSElement(aCx, log, obj)) {
1588 return;
1592 return true;
1595 void GfxInfoBase::DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> aObj) {
1596 JS::Rooted<JSObject*> obj(aCx);
1598 gfx::FeatureStatus gpuProcess =
1599 gfxConfig::GetValue(gfx::Feature::GPU_PROCESS);
1600 InitFeatureObject(aCx, aObj, "gpuProcess", gpuProcess, &obj);
1602 gfx::FeatureStatus wrQualified =
1603 gfxConfig::GetValue(gfx::Feature::WEBRENDER_QUALIFIED);
1604 InitFeatureObject(aCx, aObj, "wrQualified", wrQualified, &obj);
1606 gfx::FeatureStatus webrender = gfxConfig::GetValue(gfx::Feature::WEBRENDER);
1607 InitFeatureObject(aCx, aObj, "webrender", webrender, &obj);
1609 // Only include AL if the platform attempted to use it.
1610 gfx::FeatureStatus advancedLayers =
1611 gfxConfig::GetValue(gfx::Feature::ADVANCED_LAYERS);
1612 if (advancedLayers != FeatureStatus::Unused) {
1613 InitFeatureObject(aCx, aObj, "advancedLayers", advancedLayers, &obj);
1615 if (gfxConfig::UseFallback(Fallback::NO_CONSTANT_BUFFER_OFFSETTING)) {
1616 JS::Rooted<JS::Value> trueVal(aCx, JS::BooleanValue(true));
1617 JS_SetProperty(aCx, obj, "noConstantBufferOffsetting", trueVal);
1622 bool GfxInfoBase::InitFeatureObject(JSContext* aCx,
1623 JS::Handle<JSObject*> aContainer,
1624 const char* aName,
1625 mozilla::gfx::FeatureStatus& aFeatureStatus,
1626 JS::MutableHandle<JSObject*> aOutObj) {
1627 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1628 if (!obj) {
1629 return false;
1632 // Set "status".
1633 const char* status = FeatureStatusToString(aFeatureStatus);
1635 JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, status));
1636 JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
1637 JS_SetProperty(aCx, obj, "status", val);
1639 // Add the feature object to the container.
1641 JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
1642 JS_SetProperty(aCx, aContainer, aName, val);
1645 aOutObj.set(obj);
1646 return true;
1649 nsresult GfxInfoBase::GetActiveCrashGuards(JSContext* aCx,
1650 JS::MutableHandle<JS::Value> aOut) {
1651 JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
1652 if (!array) {
1653 return NS_ERROR_OUT_OF_MEMORY;
1655 aOut.setObject(*array);
1657 DriverCrashGuard::ForEachActiveCrashGuard(
1658 [&](const char* aName, const char* aPrefName) -> void {
1659 JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
1660 if (!obj) {
1661 return;
1663 if (!SetJSPropertyString(aCx, obj, "type", aName)) {
1664 return;
1666 if (!SetJSPropertyString(aCx, obj, "prefName", aPrefName)) {
1667 return;
1669 if (!AppendJSElement(aCx, array, obj)) {
1670 return;
1674 return NS_OK;
1677 NS_IMETHODIMP
1678 GfxInfoBase::GetWebRenderEnabled(bool* aWebRenderEnabled) {
1679 *aWebRenderEnabled = gfxVars::UseWebRender();
1680 return NS_OK;
1683 NS_IMETHODIMP
1684 GfxInfoBase::GetUsesTiling(bool* aUsesTiling) {
1685 *aUsesTiling = gfxPlatform::GetPlatform()->UsesTiling();
1686 return NS_OK;
1689 NS_IMETHODIMP
1690 GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling) {
1691 *aUsesTiling = gfxPlatform::GetPlatform()->ContentUsesTiling();
1692 return NS_OK;
1695 NS_IMETHODIMP
1696 GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled) {
1697 *aOffMainThreadPaintEnabled = gfxConfig::IsEnabled(gfx::Feature::OMTP);
1698 return NS_OK;
1701 NS_IMETHODIMP
1702 GfxInfoBase::GetOffMainThreadPaintWorkerCount(
1703 int32_t* aOffMainThreadPaintWorkerCount) {
1704 if (gfxConfig::IsEnabled(gfx::Feature::OMTP)) {
1705 *aOffMainThreadPaintWorkerCount =
1706 layers::PaintThread::CalculatePaintWorkerCount();
1707 } else {
1708 *aOffMainThreadPaintWorkerCount = 0;
1710 return NS_OK;
1713 NS_IMETHODIMP
1714 GfxInfoBase::GetTargetFrameRate(uint32_t* aTargetFrameRate) {
1715 *aTargetFrameRate = gfxPlatform::TargetFrameRate();
1716 return NS_OK;
1719 NS_IMETHODIMP
1720 GfxInfoBase::GetIsHeadless(bool* aIsHeadless) {
1721 *aIsHeadless = gfxPlatform::IsHeadless();
1722 return NS_OK;
1725 NS_IMETHODIMP
1726 GfxInfoBase::GetContentBackend(nsAString& aContentBackend) {
1727 BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend();
1728 nsString outStr;
1730 switch (backend) {
1731 case BackendType::DIRECT2D1_1: {
1732 outStr.AppendPrintf("Direct2D 1.1");
1733 break;
1735 case BackendType::SKIA: {
1736 outStr.AppendPrintf("Skia");
1737 break;
1739 case BackendType::CAIRO: {
1740 outStr.AppendPrintf("Cairo");
1741 break;
1743 default:
1744 return NS_ERROR_FAILURE;
1747 aContentBackend.Assign(outStr);
1748 return NS_OK;
1751 NS_IMETHODIMP
1752 GfxInfoBase::GetUsingGPUProcess(bool* aOutValue) {
1753 GPUProcessManager* gpu = GPUProcessManager::Get();
1754 if (!gpu) {
1755 // Not supported in content processes.
1756 return NS_ERROR_FAILURE;
1759 *aOutValue = !!gpu->GetGPUChild();
1760 return NS_OK;
1763 NS_IMETHODIMP
1764 GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) {
1765 gfxPlatform::GetPlatform();
1767 GPUProcessManager* gpm = GPUProcessManager::Get();
1768 if (aEnable) {
1769 if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS)) {
1770 gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1772 gpm->LaunchGPUProcess();
1773 gpm->EnsureGPUReady();
1774 } else {
1775 gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
1776 gpm->KillProcess();
1779 *_retval = true;
1780 return NS_OK;
1783 GfxInfoCollectorBase::GfxInfoCollectorBase() {
1784 GfxInfoBase::AddCollector(this);
1787 GfxInfoCollectorBase::~GfxInfoCollectorBase() {
1788 GfxInfoBase::RemoveCollector(this);