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
,
181 IntelHDGraphicsToHaswell
,
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
217 enum DriverVendor
: uint8_t {
218 All
, // There is an assumption that this is the first enum
219 // Wildcard for all Mesa drivers.
221 // Note that the following list of Mesa drivers is not comprehensive; we pull
222 // the DRI driver at runtime. These drivers are provided for convenience when
223 // populating the local blocklist.
227 // A generic ID to be provided when we can't determine the DRI driver on Mesa.
229 // Wildcard for all non-Mesa drivers.
235 enum class DesktopEnvironment
: uint8_t {
236 All
, // There is an assumption that this is the first enum
254 enum class WindowProtocol
: uint8_t {
255 All
, // There is an assumption that this is the first enum
259 // Wildcard for all Wayland variants.
264 enum class BatteryStatus
: uint8_t { All
, Present
, None
};
266 enum class ScreenSizeStatus
: uint8_t {
268 Small
, // <= 1900x1200
269 SmallAndMedium
, // <= 3440x1440
270 Medium
, // <= 3440x1440 && > 1900x1200
271 MediumAndLarge
, // >1900x1200
275 /* Array of devices to match, or an empty array for all devices */
276 class GfxDeviceFamily final
{
278 GfxDeviceFamily() = default;
280 void Append(const nsAString
& aDeviceId
);
281 void AppendRange(int32_t aBeginDeviceId
, int32_t aEndDeviceId
);
283 bool IsEmpty() const { return mIds
.IsEmpty() && mRanges
.IsEmpty(); }
285 nsresult
Contains(nsAString
& aDeviceId
) const;
293 nsTArray
<nsString
> mIds
;
294 nsTArray
<DeviceRange
> mRanges
;
297 struct GfxDriverInfo
{
298 // If |ownDevices| is true, you are transferring ownership of the devices
299 // array, and it will be deleted when this GfxDriverInfo is destroyed.
300 GfxDriverInfo(OperatingSystem os
, ScreenSizeStatus aScreen
,
301 BatteryStatus aBattery
, const nsAString
& desktopEnv
,
302 const nsAString
& windowProtocol
, const nsAString
& vendor
,
303 const nsAString
& driverVendor
, GfxDeviceFamily
* devices
,
304 int32_t feature
, int32_t featureStatus
, VersionComparisonOp op
,
305 uint64_t driverVersion
, const char* ruleId
,
306 const char* suggestedVersion
= nullptr, bool ownDevices
= false,
310 GfxDriverInfo(const GfxDriverInfo
&);
313 OperatingSystem mOperatingSystem
;
314 uint32_t mOperatingSystemVersion
;
315 ScreenSizeStatus mScreen
;
316 BatteryStatus mBattery
;
317 nsString mDesktopEnvironment
;
318 nsString mWindowProtocol
;
320 nsString mAdapterVendor
;
321 nsString mDriverVendor
;
323 const GfxDeviceFamily
* mDevices
;
325 // Whether the mDevices array should be deleted when this structure is
326 // deallocated. False by default.
329 /* A feature from nsIGfxInfo, or all features */
331 static int32_t allFeatures
;
333 /* A feature status from nsIGfxInfo */
334 int32_t mFeatureStatus
;
336 VersionComparisonOp mComparisonOp
;
338 /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
339 uint64_t mDriverVersion
;
340 uint64_t mDriverVersionMax
;
341 static uint64_t allDriverVersions
;
343 const char* mSuggestedVersion
;
346 static const GfxDeviceFamily
* GetDeviceFamily(DeviceFamily id
);
347 static GfxDeviceFamily
*
348 sDeviceFamilies
[static_cast<size_t>(DeviceFamily::Max
)];
350 static const nsAString
& GetDesktopEnvironment(DesktopEnvironment id
);
352 sDesktopEnvironment
[static_cast<size_t>(DesktopEnvironment::Max
)];
354 static const nsAString
& GetWindowProtocol(WindowProtocol id
);
355 static nsAString
* sWindowProtocol
[static_cast<size_t>(WindowProtocol::Max
)];
357 static const nsAString
& GetDeviceVendor(DeviceVendor id
);
358 static const nsAString
& GetDeviceVendor(DeviceFamily id
);
359 static nsAString
* sDeviceVendors
[static_cast<size_t>(DeviceVendor::Max
)];
361 static const nsAString
& GetDriverVendor(DriverVendor id
);
362 static nsAString
* sDriverVendors
[static_cast<size_t>(DriverVendor::Max
)];
364 nsString mModel
, mHardware
, mProduct
, mManufacturer
;
369 #define GFX_DRIVER_VERSION(a, b, c, d) \
370 ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | \
373 inline uint64_t V(uint32_t a
, uint32_t b
, uint32_t c
, uint32_t d
) {
374 // We make sure every driver number is padded by 0s, this will allow us the
375 // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
376 // more extensive explanation of this approach.
377 while (b
> 0 && b
< 1000) {
380 while (c
> 0 && c
< 1000) {
383 while (d
> 0 && d
< 1000) {
386 return GFX_DRIVER_VERSION(a
, b
, c
, d
);
389 // All destination string storage needs to have at least 5 bytes available.
390 inline bool SplitDriverVersion(const char* aSource
, char* aAStr
, char* aBStr
,
391 char* aCStr
, char* aDStr
) {
392 // sscanf doesn't do what we want here to we parse this manually.
393 int len
= strlen(aSource
);
395 // This "4" is hardcoded in a few places, including once as a 3.
396 char* dest
[4] = {aAStr
, aBStr
, aCStr
, aDStr
};
397 unsigned destIdx
= 0;
398 unsigned destPos
= 0;
400 for (int i
= 0; i
< len
; i
++) {
402 // Invalid format found. Ensure we don't access dest beyond bounds.
406 if (aSource
[i
] == '.') {
407 MOZ_ASSERT(destIdx
< 4 && destPos
<= 4);
408 dest
[destIdx
++][destPos
] = 0;
414 // Ignore more than 4 chars. Ensure we never access dest[destIdx]
415 // beyond its bounds.
419 MOZ_ASSERT(destIdx
< 4 && destPos
< 4);
420 dest
[destIdx
][destPos
++] = aSource
[i
];
423 // Take care of the trailing period
428 // Add last terminator.
429 MOZ_ASSERT(destIdx
< 4 && destPos
<= 4);
430 dest
[destIdx
][destPos
] = 0;
438 // This allows us to pad driver version 'substrings' with 0s, this
439 // effectively allows us to treat the version numbers as 'decimals'. This is
440 // a little strange but this method seems to do the right thing for all
441 // different vendor's driver strings. i.e. .98 will become 9800, which is
442 // larger than .978 which would become 9780.
443 inline void PadDriverDecimal(char* aString
) {
444 for (int i
= 0; i
< 4; i
++) {
446 for (int c
= i
; c
< 4; c
++) {
455 inline bool ParseDriverVersion(const nsAString
& aVersion
,
456 uint64_t* aNumericVersion
) {
457 *aNumericVersion
= 0;
459 #if defined(XP_WIN) || defined(MOZ_X11)
461 char aStr
[8], bStr
[8], cStr
[8], dStr
[8];
462 /* honestly, why do I even bother */
463 if (!SplitDriverVersion(NS_LossyConvertUTF16toASCII(aVersion
).get(), aStr
,
467 PadDriverDecimal(bStr
);
468 PadDriverDecimal(cStr
);
469 PadDriverDecimal(dStr
);
476 if (a
< 0 || a
> 0xffff) return false;
477 if (b
< 0 || b
> 0xffff) return false;
478 if (c
< 0 || c
> 0xffff) return false;
479 if (d
< 0 || d
> 0xffff) return false;
481 *aNumericVersion
= GFX_DRIVER_VERSION(a
, b
, c
, d
);
482 MOZ_ASSERT(*aNumericVersion
!= GfxDriverInfo::allDriverVersions
);
484 #elif defined(ANDROID)
485 // Can't use aVersion.ToInteger() because that's not compiled into our code
486 // unless we have XPCOM_GLUE_AVOID_NSPR disabled.
487 *aNumericVersion
= atoi(NS_LossyConvertUTF16toASCII(aVersion
).get());
488 MOZ_ASSERT(*aNumericVersion
!= GfxDriverInfo::allDriverVersions
);
495 } // namespace widget
496 } // namespace mozilla
498 #endif /*__mozilla_widget_GfxDriverInfo_h__ */