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 {
150 enum VersionComparisonOp
{
151 DRIVER_LESS_THAN
, // driver < version
152 DRIVER_BUILD_ID_LESS_THAN
, // driver build id < version
153 DRIVER_LESS_THAN_OR_EQUAL
, // driver <= version
154 DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL
, // driver build id <= version
155 DRIVER_GREATER_THAN
, // driver > version
156 DRIVER_GREATER_THAN_OR_EQUAL
, // driver >= version
157 DRIVER_EQUAL
, // driver == version
158 DRIVER_NOT_EQUAL
, // driver != version
159 DRIVER_BETWEEN_EXCLUSIVE
, // driver > version && driver < versionMax
160 DRIVER_BETWEEN_INCLUSIVE
, // driver >= version && driver <= versionMax
161 DRIVER_BETWEEN_INCLUSIVE_START
, // driver >= version && driver < versionMax
162 DRIVER_COMPARISON_IGNORED
165 enum class DeviceFamily
: uint8_t {
179 IntelHDGraphicsToIvyBridge
,
180 IntelHDGraphicsToSandyBridge
,
184 IntelMobileHDGraphics
,
185 NvidiaBlockD3D9Layers
,
196 NvidiaBlockWebRender
,
197 NvidiaRolloutWebRender
,
198 IntelRolloutWebRender
,
199 IntelModernRolloutWebRender
,
205 enum class DeviceVendor
: uint8_t {
206 All
, // There is an assumption that this is the first enum
221 enum DriverVendor
: uint8_t {
222 All
, // There is an assumption that this is the first enum
223 // Wildcard for all Mesa drivers.
225 // Note that the following list of Mesa drivers is not comprehensive; we pull
226 // the DRI driver at runtime. These drivers are provided for convenience when
227 // populating the local blocklist.
231 // A generic ID to be provided when we can't determine the DRI driver on Mesa.
233 // Wildcard for all non-Mesa drivers.
239 enum class DesktopEnvironment
: uint8_t {
240 All
, // There is an assumption that this is the first enum
260 enum class WindowProtocol
: uint8_t {
261 All
, // There is an assumption that this is the first enum
266 // Wildcard for all Wayland variants, excluding XWayland.
268 // Wildcard for all X11 variants, including XWayland.
273 enum class BatteryStatus
: uint8_t { All
, Present
, None
};
275 enum class ScreenSizeStatus
: uint8_t {
277 Small
, // <= 1900x1200
278 SmallAndMedium
, // <= 3440x1440
279 Medium
, // <= 3440x1440 && > 1900x1200
280 MediumAndLarge
, // >1900x1200
284 /* Array of devices to match, or an empty array for all devices */
285 class GfxDeviceFamily final
{
287 GfxDeviceFamily() = default;
289 void Append(const nsAString
& aDeviceId
);
290 void AppendRange(int32_t aBeginDeviceId
, int32_t aEndDeviceId
);
292 bool IsEmpty() const { return mIds
.IsEmpty() && mRanges
.IsEmpty(); }
294 nsresult
Contains(nsAString
& aDeviceId
) const;
302 CopyableTArray
<nsString
> mIds
;
303 CopyableTArray
<DeviceRange
> mRanges
;
306 struct GfxDriverInfo
{
307 // If |ownDevices| is true, you are transferring ownership of the devices
308 // array, and it will be deleted when this GfxDriverInfo is destroyed.
309 GfxDriverInfo(OperatingSystem os
, ScreenSizeStatus aScreen
,
310 BatteryStatus aBattery
, const nsAString
& desktopEnv
,
311 const nsAString
& windowProtocol
, const nsAString
& vendor
,
312 const nsAString
& driverVendor
, GfxDeviceFamily
* devices
,
313 int32_t feature
, int32_t featureStatus
, VersionComparisonOp op
,
314 uint64_t driverVersion
, const char* ruleId
,
315 const char* suggestedVersion
= nullptr, bool ownDevices
= false,
319 GfxDriverInfo(const GfxDriverInfo
&);
322 OperatingSystem mOperatingSystem
;
323 uint32_t mOperatingSystemVersion
;
324 ScreenSizeStatus mScreen
;
325 BatteryStatus mBattery
;
326 nsString mDesktopEnvironment
;
327 nsString mWindowProtocol
;
329 nsString mAdapterVendor
;
330 nsString mDriverVendor
;
332 const GfxDeviceFamily
* mDevices
;
334 // Whether the mDevices array should be deleted when this structure is
335 // deallocated. False by default.
338 /* A feature from nsIGfxInfo, or all features */
340 static int32_t allFeatures
;
342 /* A feature status from nsIGfxInfo */
343 int32_t mFeatureStatus
;
345 VersionComparisonOp mComparisonOp
;
347 /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
348 uint64_t mDriverVersion
;
349 uint64_t mDriverVersionMax
;
350 static uint64_t allDriverVersions
;
352 const char* mSuggestedVersion
;
355 static const GfxDeviceFamily
* GetDeviceFamily(DeviceFamily id
);
356 static GfxDeviceFamily
*
357 sDeviceFamilies
[static_cast<size_t>(DeviceFamily::Max
)];
359 static const nsAString
& GetDesktopEnvironment(DesktopEnvironment id
);
361 sDesktopEnvironment
[static_cast<size_t>(DesktopEnvironment::Max
)];
363 static const nsAString
& GetWindowProtocol(WindowProtocol id
);
364 static nsAString
* sWindowProtocol
[static_cast<size_t>(WindowProtocol::Max
)];
366 static const nsAString
& GetDeviceVendor(DeviceVendor id
);
367 static const nsAString
& GetDeviceVendor(DeviceFamily id
);
368 static nsAString
* sDeviceVendors
[static_cast<size_t>(DeviceVendor::Max
)];
370 static const nsAString
& GetDriverVendor(DriverVendor id
);
371 static nsAString
* sDriverVendors
[static_cast<size_t>(DriverVendor::Max
)];
373 nsString mModel
, mHardware
, mProduct
, mManufacturer
;
378 #define GFX_DRIVER_VERSION(a, b, c, d) \
379 ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | \
382 inline uint64_t V(uint32_t a
, uint32_t b
, uint32_t c
, uint32_t d
) {
383 // We make sure every driver number is padded by 0s, this will allow us the
384 // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
385 // more extensive explanation of this approach.
386 while (b
> 0 && b
< 1000) {
389 while (c
> 0 && c
< 1000) {
392 while (d
> 0 && d
< 1000) {
395 return GFX_DRIVER_VERSION(a
, b
, c
, d
);
398 // All destination string storage needs to have at least 5 bytes available.
399 inline bool SplitDriverVersion(const char* aSource
, char* aAStr
, char* aBStr
,
400 char* aCStr
, char* aDStr
) {
401 // sscanf doesn't do what we want here to we parse this manually.
402 int len
= strlen(aSource
);
404 // This "4" is hardcoded in a few places, including once as a 3.
405 char* dest
[4] = {aAStr
, aBStr
, aCStr
, aDStr
};
406 unsigned destIdx
= 0;
407 unsigned destPos
= 0;
409 for (int i
= 0; i
< len
; i
++) {
411 // Invalid format found. Ensure we don't access dest beyond bounds.
415 if (aSource
[i
] == '.') {
416 MOZ_ASSERT(destIdx
< 4 && destPos
<= 4);
417 dest
[destIdx
++][destPos
] = 0;
423 // Ignore more than 4 chars. Ensure we never access dest[destIdx]
424 // beyond its bounds.
428 MOZ_ASSERT(destIdx
< 4 && destPos
< 4);
429 dest
[destIdx
][destPos
++] = aSource
[i
];
432 // Take care of the trailing period
437 // Add last terminator.
438 MOZ_ASSERT(destIdx
< 4 && destPos
<= 4);
439 dest
[destIdx
][destPos
] = 0;
447 // This allows us to pad driver version 'substrings' with 0s, this
448 // effectively allows us to treat the version numbers as 'decimals'. This is
449 // a little strange but this method seems to do the right thing for all
450 // different vendor's driver strings. i.e. .98 will become 9800, which is
451 // larger than .978 which would become 9780.
452 inline void PadDriverDecimal(char* aString
) {
453 for (int i
= 0; i
< 4; i
++) {
455 for (int c
= i
; c
< 4; c
++) {
464 inline bool ParseDriverVersion(const nsAString
& aVersion
,
465 uint64_t* aNumericVersion
) {
466 *aNumericVersion
= 0;
468 #if defined(XP_WIN) || defined(MOZ_X11)
470 char aStr
[8], bStr
[8], cStr
[8], dStr
[8];
471 /* honestly, why do I even bother */
472 if (!SplitDriverVersion(NS_LossyConvertUTF16toASCII(aVersion
).get(), aStr
,
476 PadDriverDecimal(bStr
);
477 PadDriverDecimal(cStr
);
478 PadDriverDecimal(dStr
);
485 if (a
< 0 || a
> 0xffff) return false;
486 if (b
< 0 || b
> 0xffff) return false;
487 if (c
< 0 || c
> 0xffff) return false;
488 if (d
< 0 || d
> 0xffff) return false;
490 *aNumericVersion
= GFX_DRIVER_VERSION(a
, b
, c
, d
);
491 MOZ_ASSERT(*aNumericVersion
!= GfxDriverInfo::allDriverVersions
);
493 #elif defined(ANDROID)
494 // Can't use aVersion.ToInteger() because that's not compiled into our code
495 // unless we have XPCOM_GLUE_AVOID_NSPR disabled.
496 *aNumericVersion
= atoi(NS_LossyConvertUTF16toASCII(aVersion
).get());
497 MOZ_ASSERT(*aNumericVersion
!= GfxDriverInfo::allDriverVersions
);
504 } // namespace widget
505 } // namespace mozilla
507 #endif /*__mozilla_widget_GfxDriverInfo_h__ */