1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __mozilla_widget_GfxDriverInfo_h__
7 #define __mozilla_widget_GfxDriverInfo_h__
12 // Macros for adding a blocklist item to the static list. _EXT variants
13 // allow one to specify all available parameters, including those available
14 // only on specific platforms (e.g. desktop environment and driver vendor
17 #define APPEND_TO_DRIVER_BLOCKLIST_EXT( \
18 os, screen, battery, desktopEnv, windowProtocol, driverVendor, devices, \
19 feature, featureStatus, driverComparator, driverVersion, ruleId, \
21 sDriverInfo->AppendElement(GfxDriverInfo( \
22 os, screen, battery, \
23 (nsAString&)GfxDriverInfo::GetDesktopEnvironment(desktopEnv), \
24 (nsAString&)GfxDriverInfo::GetWindowProtocol(windowProtocol), \
25 (nsAString&)GfxDriverInfo::GetDeviceVendor(devices), \
26 (nsAString&)GfxDriverInfo::GetDriverVendor(driverVendor), \
27 (GfxDeviceFamily*)GfxDriverInfo::GetDeviceFamily(devices), feature, \
28 featureStatus, driverComparator, driverVersion, ruleId, \
31 #define APPEND_TO_DRIVER_BLOCKLIST(os, devices, feature, featureStatus, \
32 driverComparator, driverVersion, ruleId, \
34 APPEND_TO_DRIVER_BLOCKLIST_EXT( \
35 os, ScreenSizeStatus::All, BatteryStatus::All, DesktopEnvironment::All, \
36 WindowProtocol::All, DriverVendor::All, devices, feature, featureStatus, \
37 driverComparator, driverVersion, ruleId, suggestedVersion)
39 #define APPEND_TO_DRIVER_BLOCKLIST2_EXT( \
40 os, screen, battery, desktopEnv, windowProtocol, driverVendor, devices, \
41 feature, featureStatus, driverComparator, driverVersion, ruleId) \
42 sDriverInfo->AppendElement(GfxDriverInfo( \
43 os, screen, battery, \
44 (nsAString&)GfxDriverInfo::GetDesktopEnvironment(desktopEnv), \
45 (nsAString&)GfxDriverInfo::GetWindowProtocol(windowProtocol), \
46 (nsAString&)GfxDriverInfo::GetDeviceVendor(devices), \
47 (nsAString&)GfxDriverInfo::GetDriverVendor(driverVendor), \
48 (GfxDeviceFamily*)GfxDriverInfo::GetDeviceFamily(devices), feature, \
49 featureStatus, driverComparator, driverVersion, ruleId))
51 #define APPEND_TO_DRIVER_BLOCKLIST2(os, devices, feature, featureStatus, \
52 driverComparator, driverVersion, ruleId) \
53 APPEND_TO_DRIVER_BLOCKLIST2_EXT( \
54 os, ScreenSizeStatus::All, BatteryStatus::All, DesktopEnvironment::All, \
55 WindowProtocol::All, DriverVendor::All, devices, feature, featureStatus, \
56 driverComparator, driverVersion, ruleId)
58 #define APPEND_TO_DRIVER_BLOCKLIST_RANGE_EXT( \
59 os, screen, battery, desktopEnv, windowProtocol, driverVendor, devices, \
60 feature, featureStatus, driverComparator, driverVersion, driverVersionMax, \
61 ruleId, suggestedVersion) \
63 MOZ_ASSERT((driverComparator) == DRIVER_BETWEEN_EXCLUSIVE || \
64 (driverComparator) == DRIVER_BETWEEN_INCLUSIVE || \
65 (driverComparator) == DRIVER_BETWEEN_INCLUSIVE_START); \
67 os, screen, battery, \
68 (nsAString&)GfxDriverInfo::GetDesktopEnvironment(desktopEnv), \
69 (nsAString&)GfxDriverInfo::GetWindowProtocol(windowProtocol), \
70 (nsAString&)GfxDriverInfo::GetDeviceVendor(devices), \
71 (nsAString&)GfxDriverInfo::GetDriverVendor(driverVendor), \
72 (GfxDeviceFamily*)GfxDriverInfo::GetDeviceFamily(devices), feature, \
73 featureStatus, driverComparator, driverVersion, ruleId, \
75 info.mDriverVersionMax = driverVersionMax; \
76 sDriverInfo->AppendElement(info); \
79 #define APPEND_TO_DRIVER_BLOCKLIST_RANGE( \
80 os, devices, feature, featureStatus, driverComparator, driverVersion, \
81 driverVersionMax, ruleId, suggestedVersion) \
82 APPEND_TO_DRIVER_BLOCKLIST_RANGE_EXT( \
83 os, ScreenSizeStatus::All, BatteryStatus::All, DesktopEnvironment::All, \
84 WindowProtocol::All, DriverVendor::All, devices, feature, featureStatus, \
85 driverComparator, driverVersion, driverVersionMax, ruleId, \
88 #define APPEND_TO_DRIVER_BLOCKLIST_RANGE_GPU2_EXT( \
89 os, screen, battery, desktopEnv, windowProtocol, driverVendor, devices, \
90 feature, featureStatus, driverComparator, driverVersion, driverVersionMax, \
91 ruleId, suggestedVersion) \
93 MOZ_ASSERT((driverComparator) == DRIVER_BETWEEN_EXCLUSIVE || \
94 (driverComparator) == DRIVER_BETWEEN_INCLUSIVE || \
95 (driverComparator) == DRIVER_BETWEEN_INCLUSIVE_START); \
97 os, screen, battery, \
98 (nsAString&)GfxDriverInfo::GetDesktopEnvironment(desktopEnv), \
99 (nsAString&)GfxDriverInfo::GetWindowProtocol(windowProtocol), \
100 (nsAString&)GfxDriverInfo::GetDeviceVendor(devices), \
101 (nsAString&)GfxDriverInfo::GetDriverVendor(driverVendor), \
102 (GfxDeviceFamily*)GfxDriverInfo::GetDeviceFamily(devices), feature, \
103 featureStatus, driverComparator, driverVersion, ruleId, \
104 suggestedVersion, false, true); \
105 info.mDriverVersionMax = driverVersionMax; \
106 sDriverInfo->AppendElement(info); \
109 #define APPEND_TO_DRIVER_BLOCKLIST_RANGE_GPU2( \
110 os, devices, feature, featureStatus, driverComparator, driverVersion, \
111 driverVersionMax, ruleId, suggestedVersion) \
112 APPEND_TO_DRIVER_BLOCKLIST_RANGE_GPU2_EXT( \
113 os, ScreenSizeStatus::All, BatteryStatus::All, DesktopEnvironment::All, \
114 WindowProtocol::All, DriverVendor::All, devices, feature, featureStatus, \
115 driverComparator, driverVersion, driverVersionMax, ruleId, \
121 enum class OperatingSystem
: uint8_t {
151 enum VersionComparisonOp
{
152 DRIVER_LESS_THAN
, // driver < version
153 DRIVER_BUILD_ID_LESS_THAN
, // driver build id < version
154 DRIVER_LESS_THAN_OR_EQUAL
, // driver <= version
155 DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
, // driver build id <= version
156 DRIVER_GREATER_THAN
, // driver > version
157 DRIVER_GREATER_THAN_OR_EQUAL
, // driver >= version
158 DRIVER_EQUAL
, // driver == version
159 DRIVER_NOT_EQUAL
, // driver != version
160 DRIVER_BETWEEN_EXCLUSIVE
, // driver > version && driver < versionMax
161 DRIVER_BETWEEN_INCLUSIVE
, // driver >= version && driver <= versionMax
162 DRIVER_BETWEEN_INCLUSIVE_START
, // driver >= version && driver < versionMax
163 DRIVER_COMPARISON_IGNORED
166 enum class DeviceFamily
: uint8_t {
182 IntelHDGraphicsToIvyBridge
,
183 IntelHDGraphicsToSandyBridge
,
187 IntelMobileHDGraphics
,
188 NvidiaBlockD3D9Layers
,
200 NvidiaBlockWebRender
,
201 NvidiaRolloutWebRender
,
202 IntelRolloutWebRender
,
203 IntelModernRolloutWebRender
,
209 enum class DeviceVendor
: uint8_t {
210 All
, // There is an assumption that this is the first enum
227 enum DriverVendor
: uint8_t {
228 All
, // There is an assumption that this is the first enum
229 // Wildcard for all Mesa drivers.
231 // Note that the following list of Mesa drivers is not comprehensive; we pull
232 // the DRI driver at runtime. These drivers are provided for convenience when
233 // populating the local blocklist.
237 // Nouveau: Open-source nvidia
239 // A generic ID to be provided when we can't determine the DRI driver on Mesa.
241 // Wildcard for all non-Mesa drivers.
243 // Wildcard for all hardware Mesa drivers.
245 // Wildcard for all software Mesa drivers.
251 enum class DesktopEnvironment
: uint8_t {
252 All
, // There is an assumption that this is the first enum
272 enum class WindowProtocol
: uint8_t {
273 All
, // There is an assumption that this is the first enum
278 // Wildcard for all Wayland variants, excluding XWayland.
280 // Wildcard for all X11 variants, including XWayland.
285 enum class BatteryStatus
: uint8_t { All
, Present
, None
};
287 enum class ScreenSizeStatus
: uint8_t {
289 Small
, // <= 1900x1200
290 SmallAndMedium
, // <= 3440x1440
291 Medium
, // <= 3440x1440 && > 1900x1200
292 MediumAndLarge
, // >1900x1200
296 /* Array of devices to match, or an empty array for all devices */
297 class GfxDeviceFamily final
{
299 GfxDeviceFamily() = default;
301 void Append(const nsAString
& aDeviceId
);
302 void AppendRange(int32_t aBeginDeviceId
, int32_t aEndDeviceId
);
304 bool IsEmpty() const { return mIds
.IsEmpty() && mRanges
.IsEmpty(); }
306 nsresult
Contains(nsAString
& aDeviceId
) const;
314 CopyableTArray
<nsString
> mIds
;
315 CopyableTArray
<DeviceRange
> mRanges
;
318 struct GfxDriverInfo
{
319 // If |ownDevices| is true, you are transferring ownership of the devices
320 // array, and it will be deleted when this GfxDriverInfo is destroyed.
321 GfxDriverInfo(OperatingSystem os
, ScreenSizeStatus aScreen
,
322 BatteryStatus aBattery
, const nsAString
& desktopEnv
,
323 const nsAString
& windowProtocol
, const nsAString
& vendor
,
324 const nsAString
& driverVendor
, GfxDeviceFamily
* devices
,
325 int32_t feature
, int32_t featureStatus
, VersionComparisonOp op
,
326 uint64_t driverVersion
, const char* ruleId
,
327 const char* suggestedVersion
= nullptr, bool ownDevices
= false,
331 GfxDriverInfo(const GfxDriverInfo
&);
334 OperatingSystem mOperatingSystem
;
335 uint32_t mOperatingSystemVersion
;
336 ScreenSizeStatus mScreen
;
337 BatteryStatus mBattery
;
338 nsString mDesktopEnvironment
;
339 nsString mWindowProtocol
;
341 nsString mAdapterVendor
;
342 nsString mDriverVendor
;
344 const GfxDeviceFamily
* mDevices
;
346 // Whether the mDevices array should be deleted when this structure is
347 // deallocated. False by default.
350 /* A feature from nsIGfxInfo, or all features */
352 static int32_t allFeatures
;
354 /* A feature status from nsIGfxInfo */
355 int32_t mFeatureStatus
;
357 VersionComparisonOp mComparisonOp
;
359 /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
360 uint64_t mDriverVersion
;
361 uint64_t mDriverVersionMax
;
362 static uint64_t allDriverVersions
;
364 const char* mSuggestedVersion
;
367 static const GfxDeviceFamily
* GetDeviceFamily(DeviceFamily id
);
368 static GfxDeviceFamily
*
369 sDeviceFamilies
[static_cast<size_t>(DeviceFamily::Max
)];
371 static const nsAString
& GetDesktopEnvironment(DesktopEnvironment id
);
373 sDesktopEnvironment
[static_cast<size_t>(DesktopEnvironment::Max
)];
375 static const nsAString
& GetWindowProtocol(WindowProtocol id
);
376 static nsAString
* sWindowProtocol
[static_cast<size_t>(WindowProtocol::Max
)];
378 static const nsAString
& GetDeviceVendor(DeviceVendor id
);
379 static const nsAString
& GetDeviceVendor(DeviceFamily id
);
380 static nsAString
* sDeviceVendors
[static_cast<size_t>(DeviceVendor::Max
)];
382 static const nsAString
& GetDriverVendor(DriverVendor id
);
383 static nsAString
* sDriverVendors
[static_cast<size_t>(DriverVendor::Max
)];
385 nsString mModel
, mHardware
, mProduct
, mManufacturer
;
390 #define GFX_DRIVER_VERSION(a, b, c, d) \
391 ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | \
394 inline uint64_t V(uint32_t a
, uint32_t b
, uint32_t c
, uint32_t d
) {
395 // We make sure every driver number is padded by 0s, this will allow us the
396 // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
397 // more extensive explanation of this approach.
398 while (b
> 0 && b
< 1000) {
401 while (c
> 0 && c
< 1000) {
404 while (d
> 0 && d
< 1000) {
407 return GFX_DRIVER_VERSION(a
, b
, c
, d
);
410 // All destination string storage needs to have at least 5 bytes available.
411 inline bool SplitDriverVersion(const char* aSource
, char* aAStr
, char* aBStr
,
412 char* aCStr
, char* aDStr
) {
413 // sscanf doesn't do what we want here to we parse this manually.
414 int len
= strlen(aSource
);
416 // This "4" is hardcoded in a few places, including once as a 3.
417 char* dest
[4] = {aAStr
, aBStr
, aCStr
, aDStr
};
418 unsigned destIdx
= 0;
419 unsigned destPos
= 0;
421 for (int i
= 0; i
< len
; i
++) {
423 // Invalid format found. Ensure we don't access dest beyond bounds.
427 if (aSource
[i
] == '.') {
428 MOZ_ASSERT(destIdx
< 4 && destPos
<= 4);
429 dest
[destIdx
++][destPos
] = 0;
435 // Ignore more than 4 chars. Ensure we never access dest[destIdx]
436 // beyond its bounds.
440 MOZ_ASSERT(destIdx
< 4 && destPos
< 4);
441 dest
[destIdx
][destPos
++] = aSource
[i
];
444 // Take care of the trailing period
449 // Add last terminator.
450 MOZ_ASSERT(destIdx
< 4 && destPos
<= 4);
451 dest
[destIdx
][destPos
] = 0;
459 // This allows us to pad driver version 'substrings' with 0s, this
460 // effectively allows us to treat the version numbers as 'decimals'. This is
461 // a little strange but this method seems to do the right thing for all
462 // different vendor's driver strings. i.e. .98 will become 9800, which is
463 // larger than .978 which would become 9780.
464 inline void PadDriverDecimal(char* aString
) {
465 for (int i
= 0; i
< 4; i
++) {
467 for (int c
= i
; c
< 4; c
++) {
476 inline bool ParseDriverVersion(const nsAString
& aVersion
,
477 uint64_t* aNumericVersion
) {
478 *aNumericVersion
= 0;
480 #if defined(XP_WIN) || defined(MOZ_X11)
482 char aStr
[8], bStr
[8], cStr
[8], dStr
[8];
483 /* honestly, why do I even bother */
484 if (!SplitDriverVersion(NS_LossyConvertUTF16toASCII(aVersion
).get(), aStr
,
488 PadDriverDecimal(bStr
);
489 PadDriverDecimal(cStr
);
490 PadDriverDecimal(dStr
);
497 if (a
< 0 || a
> 0xffff) return false;
498 if (b
< 0 || b
> 0xffff) return false;
499 if (c
< 0 || c
> 0xffff) return false;
500 if (d
< 0 || d
> 0xffff) return false;
502 *aNumericVersion
= GFX_DRIVER_VERSION(a
, b
, c
, d
);
503 MOZ_ASSERT(*aNumericVersion
!= GfxDriverInfo::allDriverVersions
);
505 #elif defined(ANDROID)
506 // Can't use aVersion.ToInteger() because that's not compiled into our code
507 // unless we have XPCOM_GLUE_AVOID_NSPR disabled.
508 *aNumericVersion
= atoi(NS_LossyConvertUTF16toASCII(aVersion
).get());
509 MOZ_ASSERT(*aNumericVersion
!= GfxDriverInfo::allDriverVersions
);
516 } // namespace widget
517 } // namespace mozilla
519 #endif /*__mozilla_widget_GfxDriverInfo_h__ */