Update MacOS Version detection.

master
Fedor 2020-12-23 03:02:30 +02:00
parent 3e87c989a7
commit 38fd9ff2bb
8 changed files with 150 additions and 112 deletions

View File

@ -1857,8 +1857,8 @@ GLContext::InitExtensions()
// textures with glCompressedTexSubImage2D. Works on Intel HD 4000 // textures with glCompressedTexSubImage2D. Works on Intel HD 4000
// and Intel HD 5000/Iris that I tested. // and Intel HD 5000/Iris that I tested.
// Bug 1124996: Appears to be the same on OSX Yosemite (10.10) // Bug 1124996: Appears to be the same on OSX Yosemite (10.10)
if (nsCocoaFeatures::OSXVersionMajor() == 10 && if (nsCocoaFeatures::macOSVersionMajor() == 10 &&
nsCocoaFeatures::OSXVersionMinor() >= 9 && nsCocoaFeatures::macOSVersionMinor() >= 9 &&
Renderer() == GLRenderer::IntelHD3000) Renderer() == GLRenderer::IntelHD3000)
{ {
MarkExtensionUnsupported(EXT_texture_compression_s3tc); MarkExtensionUnsupported(EXT_texture_compression_s3tc);

View File

@ -906,8 +906,8 @@ nsHttpHandler::InitUserAgentComponents()
#elif defined(__i386__) || defined(__x86_64__) #elif defined(__i386__) || defined(__x86_64__)
mOscpu.AssignLiteral("Intel Mac OS X"); mOscpu.AssignLiteral("Intel Mac OS X");
#endif #endif
SInt32 majorVersion = nsCocoaFeatures::OSXVersionMajor(); SInt32 majorVersion = nsCocoaFeatures::macOSVersionMajor();
SInt32 minorVersion = nsCocoaFeatures::OSXVersionMinor(); SInt32 minorVersion = nsCocoaFeatures::macOSVersionMinor();
mOscpu += nsPrintfCString(" %d.%d", majorVersion, minorVersion); mOscpu += nsPrintfCString(" %d.%d", majorVersion, minorVersion);
#elif defined (XP_UNIX) #elif defined (XP_UNIX)
struct utsname name; struct utsname name;

View File

@ -58,6 +58,11 @@ enum class OperatingSystem {
OSX10_10, OSX10_10,
OSX10_11, OSX10_11,
OSX10_12, OSX10_12,
OSX10_13,
OSX10_14,
OSX10_15,
OSX10_16,
OSX11_0,
Android, Android,
Ios Ios
}; };

View File

@ -284,6 +284,14 @@ BlacklistOSToOperatingSystem(const nsAString& os)
return OperatingSystem::OSX10_11; return OperatingSystem::OSX10_11;
else if (os.EqualsLiteral("Darwin 16")) else if (os.EqualsLiteral("Darwin 16"))
return OperatingSystem::OSX10_12; return OperatingSystem::OSX10_12;
else if (os.EqualsLiteral("Darwin 17"))
return OperatingSystem::OSX10_13;
else if (os.EqualsLiteral("Darwin 18"))
return OperatingSystem::OSX10_14;
else if (os.EqualsLiteral("Darwin 19"))
return OperatingSystem::OSX10_15;
else if (os.EqualsLiteral("Darwin 20"))
return OperatingSystem::OSX11_0;
else if (os.EqualsLiteral("Android")) else if (os.EqualsLiteral("Android"))
return OperatingSystem::Android; return OperatingSystem::Android;
// For historical reasons, "All" in blocklist means "All Windows" // For historical reasons, "All" in blocklist means "All Windows"

View File

@ -30,25 +30,46 @@ GfxInfo::GfxInfo()
} }
static OperatingSystem static OperatingSystem
OSXVersionToOperatingSystem(uint32_t aOSXVersion) OSXVersionToOperatingSystem(uint32_t aOSXVersion) {
{ switch (nsCocoaFeatures::ExtractMajorVersion(aOSXVersion)) {
if (nsCocoaFeatures::ExtractMajorVersion(aOSXVersion) == 10) { case 10:
switch (nsCocoaFeatures::ExtractMinorVersion(aOSXVersion)) { switch (nsCocoaFeatures::ExtractMinorVersion(aOSXVersion)) {
case 6: case 6:
return OperatingSystem::OSX10_6; return OperatingSystem::OSX10_6;
case 7: case 7:
return OperatingSystem::OSX10_7; return OperatingSystem::OSX10_7;
case 8: case 8:
return OperatingSystem::OSX10_8; return OperatingSystem::OSX10_8;
case 9: case 9:
return OperatingSystem::OSX10_9; return OperatingSystem::OSX10_9;
case 10: case 10:
return OperatingSystem::OSX10_10; return OperatingSystem::OSX10_10;
case 11: case 11:
return OperatingSystem::OSX10_11; return OperatingSystem::OSX10_11;
case 12: case 12:
return OperatingSystem::OSX10_12; return OperatingSystem::OSX10_12;
} case 13:
return OperatingSystem::OSX10_13;
case 14:
return OperatingSystem::OSX10_14;
case 15:
return OperatingSystem::OSX10_15;
case 16:
// Depending on the SDK version, we either get 10.16 or 11.0.
// Normalize this to 11.0.
return OperatingSystem::OSX11_0;
default:
break;
}
break;
case 11:
switch (nsCocoaFeatures::ExtractMinorVersion(aOSXVersion)) {
case 0:
return OperatingSystem::OSX11_0;
default:
break;
}
break;
} }
return OperatingSystem::Unknown; return OperatingSystem::Unknown;
@ -107,7 +128,7 @@ GfxInfo::Init()
AddCrashReportAnnotations(); AddCrashReportAnnotations();
mOSXVersion = nsCocoaFeatures::OSXVersion(); mOSXVersion = nsCocoaFeatures::macOSVersion();
return rv; return rv;
} }

View File

@ -14,10 +14,10 @@
/// is the only call that returns the unadjusted values. /// is the only call that returns the unadjusted values.
class nsCocoaFeatures { class nsCocoaFeatures {
public: public:
static int32_t OSXVersion(); static int32_t macOSVersion();
static int32_t OSXVersionMajor(); static int32_t macOSVersionMajor();
static int32_t OSXVersionMinor(); static int32_t macOSVersionMinor();
static int32_t OSXVersionBugFix(); static int32_t macOSVersionBugFix();
static bool OnYosemiteOrLater(); static bool OnYosemiteOrLater();
static bool OnElCapitanOrLater(); static bool OnElCapitanOrLater();
static bool OnSierraOrLater(); static bool OnSierraOrLater();
@ -41,6 +41,6 @@ public:
private: private:
static void InitializeVersionNumbers(); static void InitializeVersionNumbers();
static int32_t mOSXVersion; static int32_t mOSVersion;
}; };
#endif // nsCocoaFeatures_h_ #endif // nsCocoaFeatures_h_

View File

@ -3,27 +3,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This file makes some assumptions about the versions of OS X. // This file makes some assumptions about the versions of macOS.
// We are assuming that the minor and bugfix versions are less than 16. // We are assuming that the major, minor and bugfix versions are each less than
// 256.
// There are MOZ_ASSERTs for that. // There are MOZ_ASSERTs for that.
// The formula for the version integer based on OS X version 10.minor.bugfix is // The formula for the version integer is (major << 16) + (minor << 8) + bugfix.
// 0x1000 + (minor << 4) + bugifix. See AssembleVersion() below for major > 10.
// Major version < 10 is not allowed.
#define MAC_OS_X_VERSION_MASK 0x0000FFFF #define MACOS_VERSION_MASK 0x00FFFFFF
#define MAC_OS_X_VERSION_10_0_HEX 0x00001000 #define MACOS_MAJOR_VERSION_MASK 0x00FFFFFF
#define MAC_OS_X_VERSION_10_7_HEX 0x00001070 #define MACOS_MINOR_VERSION_MASK 0x00FFFFFF
#define MAC_OS_X_VERSION_10_8_HEX 0x00001080 #define MACOS_BUGFIX_VERSION_MASK 0x00FFFFFF
#define MAC_OS_X_VERSION_10_9_HEX 0x00001090 #define MACOS_VERSION_10_0_HEX 0x000A0000
#define MAC_OS_X_VERSION_10_10_HEX 0x000010A0 #define MACOS_VERSION_10_7_HEX 0x000A0700
#define MAC_OS_X_VERSION_10_11_HEX 0x000010B0 #define MACOS_VERSION_10_8_HEX 0x000A0800
#define MAC_OS_X_VERSION_10_12_HEX 0x000010C0 #define MACOS_VERSION_10_9_HEX 0x000A0900
#define MAC_OS_X_VERSION_10_13_HEX 0x000010D0 #define MACOS_VERSION_10_10_HEX 0x000A0A00
#define MAC_OS_X_VERSION_10_14_HEX 0x000010E0 #define MACOS_VERSION_10_11_HEX 0x000A0B00
#define MAC_OS_X_VERSION_10_15_HEX 0x000010F0 #define MACOS_VERSION_10_12_HEX 0x000A0C00
#define MAC_OS_X_VERSION_10_16_HEX 0x000A1000 #define MACOS_VERSION_10_13_HEX 0x000A0D00
#define MAC_OS_X_VERSION_11_0_HEX 0x000B0000 #define MACOS_VERSION_10_14_HEX 0x000A0E00
#define MACOS_VERSION_10_15_HEX 0x000A0F00
#define MACOS_VERSION_10_16_HEX 0x000A1000
#define MACOS_VERSION_11_0_HEX 0x000B0000
#include "nsCocoaFeatures.h" #include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h" #include "nsCocoaUtils.h"
@ -32,36 +34,36 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
int32_t nsCocoaFeatures::mOSXVersion = 0; int32_t nsCocoaFeatures::mOSVersion = 0;
// This should not be called with unchecked aMajor, which should be >= 10. // This should not be called with unchecked aMajor, which should be >= 10.
inline int32_t AssembleVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix) inline int32_t AssembleVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
{ {
MOZ_ASSERT(aMajor >= 10); MOZ_ASSERT(aMajor >= 10);
return MAC_OS_X_VERSION_10_0_HEX + (aMajor-10) * 0x100 + (aMinor << 4) + aBugFix; return (aMajor << 16) + (aMinor << 8) + aBugFix;
} }
int32_t nsCocoaFeatures::ExtractMajorVersion(int32_t aVersion) int32_t nsCocoaFeatures::ExtractMajorVersion(int32_t aVersion)
{ {
MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion); MOZ_ASSERT((aVersion & MACOS_VERSION_MASK) == aVersion);
return ((aVersion & 0xFF00) - 0x1000) / 0x100 + 10; return (aVersion & 0xFF0000) >> 16;
} }
int32_t nsCocoaFeatures::ExtractMinorVersion(int32_t aVersion) int32_t nsCocoaFeatures::ExtractMinorVersion(int32_t aVersion)
{ {
MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion); MOZ_ASSERT((aVersion & MACOS_VERSION_MASK) == aVersion);
return (aVersion & 0xF0) >> 4; return (aVersion & 0xFF00) >> 8;
} }
int32_t nsCocoaFeatures::ExtractBugFixVersion(int32_t aVersion) int32_t nsCocoaFeatures::ExtractBugFixVersion(int32_t aVersion)
{ {
MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion); MOZ_ASSERT((aVersion & MACOS_VERSION_MASK) == aVersion);
return aVersion & 0x0F; return aVersion & 0xFF;
} }
static int intAtStringIndex(NSArray *array, int index) static int intAtStringIndex(NSArray *array, int index)
{ {
return [(NSString *)[array objectAtIndex:index] integerValue]; return [(NSString*)[array objectAtIndex:index] integerValue];
} }
void nsCocoaFeatures::GetSystemVersion(int &major, int &minor, int &bugfix) void nsCocoaFeatures::GetSystemVersion(int &major, int &minor, int &bugfix)
@ -85,121 +87,123 @@ void nsCocoaFeatures::GetSystemVersion(int &major, int &minor, int &bugfix)
int32_t nsCocoaFeatures::GetVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix) int32_t nsCocoaFeatures::GetVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
{ {
int32_t osxVersion; int32_t macOSVersion;
if (aMajor < 10) { if (aMajor < 10) {
aMajor = 10; aMajor = 10;
NS_ERROR("Couldn't determine OS X version, assuming 10.7"); NS_ERROR("Couldn't determine macOS version, assuming 10.7");
osxVersion = MAC_OS_X_VERSION_10_7_HEX; macOSVersion = MACOS_VERSION_10_7_HEX;
} else if (aMinor < 7) { } else if (aMajor == 10 && aMinor < 7) {
aMinor = 7; aMinor = 7;
NS_ERROR("OS X version too old, assuming 10.7"); NS_ERROR("macOS version too old, assuming 10.7");
osxVersion = MAC_OS_X_VERSION_10_7_HEX; macOSVersion = MACOS_VERSION_10_7_HEX;
} else { } else {
MOZ_ASSERT(aMajor == 10); // For now, even though we're ready... MOZ_ASSERT(aMajor >= 10);
MOZ_ASSERT(aMinor < 16); MOZ_ASSERT(aMajor < 256);
MOZ_ASSERT(aBugFix >= 0); MOZ_ASSERT(aMinor >= 0);
MOZ_ASSERT(aBugFix < 16); MOZ_ASSERT(aMinor < 256);
osxVersion = AssembleVersion(aMajor, aMinor, aBugFix); MOZ_ASSERT(aBugFix >= 0);
} MOZ_ASSERT(aBugFix < 256);
MOZ_ASSERT(aMajor == ExtractMajorVersion(osxVersion)); macOSVersion = AssembleVersion(aMajor, aMinor, aBugFix);
MOZ_ASSERT(aMinor == ExtractMinorVersion(osxVersion)); }
MOZ_ASSERT(aBugFix == ExtractBugFixVersion(osxVersion)); MOZ_ASSERT(aMajor == ExtractMajorVersion(macOSVersion));
return osxVersion; MOZ_ASSERT(aMinor == ExtractMinorVersion(macOSVersion));
MOZ_ASSERT(aBugFix == ExtractBugFixVersion(macOSVersion));
return macOSVersion;
} }
/*static*/ void /*static*/ void
nsCocoaFeatures::InitializeVersionNumbers() nsCocoaFeatures::InitializeVersionNumbers()
{ {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK; NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// Provide an autorelease pool to avoid leaking Cocoa objects, // Provide an autorelease pool to avoid leaking Cocoa objects,
// as this gets called before the main autorelease pool is in place. // as this gets called before the main autorelease pool is in place.
nsAutoreleasePool localPool; nsAutoreleasePool localPool;
int major, minor, bugfix; int major, minor, bugfix;
GetSystemVersion(major, minor, bugfix); GetSystemVersion(major, minor, bugfix);
mOSXVersion = GetVersion(major, minor, bugfix); mOSVersion = GetVersion(major, minor, bugfix);
NS_OBJC_END_TRY_ABORT_BLOCK; NS_OBJC_END_TRY_ABORT_BLOCK;
} }
/* static */ int32_t /* static */ int32_t
nsCocoaFeatures::OSXVersion() nsCocoaFeatures::macOSVersion()
{ {
// Don't let this be called while we're first setting the value... // Don't let this be called while we're first setting the value...
MOZ_ASSERT((mOSXVersion & MAC_OS_X_VERSION_MASK) >= 0); MOZ_ASSERT((mOSVersion & MACOS_VERSION_MASK) >= 0);
if (!mOSXVersion) { if (!mOSVersion) {
mOSXVersion = -1; mOSVersion = -1;
InitializeVersionNumbers(); InitializeVersionNumbers();
} }
return mOSXVersion; return mOSVersion;
} }
/* static */ int32_t /* static */ int32_t
nsCocoaFeatures::OSXVersionMajor() nsCocoaFeatures::macOSVersionMajor()
{ {
MOZ_ASSERT((OSXVersion() & MAC_OS_X_VERSION_10_0_HEX) == MAC_OS_X_VERSION_10_0_HEX); return ExtractMajorVersion(macOSVersion());
return 10;
} }
/* static */ int32_t /* static */ int32_t
nsCocoaFeatures::OSXVersionMinor() nsCocoaFeatures::macOSVersionMinor()
{ {
return ExtractMinorVersion(OSXVersion()); return ExtractMinorVersion(macOSVersion());
} }
/* static */ int32_t /* static */ int32_t
nsCocoaFeatures::OSXVersionBugFix() nsCocoaFeatures::macOSVersionBugFix()
{ {
return ExtractBugFixVersion(OSXVersion()); return ExtractBugFixVersion(macOSVersion());
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnYosemiteOrLater() nsCocoaFeatures::OnYosemiteOrLater()
{ {
return (OSXVersion() >= MAC_OS_X_VERSION_10_10_HEX); return (macOSVersion() >= MACOS_VERSION_10_10_HEX);
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnElCapitanOrLater() nsCocoaFeatures::OnElCapitanOrLater()
{ {
return (OSXVersion() >= MAC_OS_X_VERSION_10_11_HEX); return (macOSVersion() >= MACOS_VERSION_10_11_HEX);
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnSierraOrLater() nsCocoaFeatures::OnSierraOrLater()
{ {
return (OSXVersion() >= MAC_OS_X_VERSION_10_12_HEX); return (macOSVersion() >= MACOS_VERSION_10_12_HEX);
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnHighSierraOrLater() nsCocoaFeatures::OnHighSierraOrLater()
{ {
return (OSXVersion() >= MAC_OS_X_VERSION_10_13_HEX); return (macOSVersion() >= MACOS_VERSION_10_13_HEX);
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnMojaveOrLater() nsCocoaFeatures::OnMojaveOrLater()
{ {
return (OSXVersion() >= MAC_OS_X_VERSION_10_14_HEX); return (macOSVersion() >= MACOS_VERSION_10_14_HEX);
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnCatalinaOrLater() nsCocoaFeatures::OnCatalinaOrLater()
{ {
return (OSXVersion() >= MAC_OS_X_VERSION_10_15_HEX); return (macOSVersion() >= MACOS_VERSION_10_15_HEX);
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::OnBigSurOrLater() { nsCocoaFeatures::OnBigSurOrLater()
{
// Account for the version being 10.16 (which occurs when the // Account for the version being 10.16 (which occurs when the
// application is linked with an older SDK) or 11.0 on Big Sur. // application is linked with an older SDK) or 11.0 on Big Sur.
return ((OSXVersion() >= MAC_OS_X_VERSION_10_16_HEX) || return ((macOSVersion() >= MACOS_VERSION_10_16_HEX) ||
(OSXVersion() >= MAC_OS_X_VERSION_11_0_HEX)); (macOSVersion() >= MACOS_VERSION_11_0_HEX));
} }
/* static */ bool /* static */ bool
nsCocoaFeatures::IsAtLeastVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix) nsCocoaFeatures::IsAtLeastVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
{ {
return OSXVersion() >= GetVersion(aMajor, aMinor, aBugFix); return macOSVersion() >= GetVersion(aMajor, aMinor, aBugFix);
} }

View File

@ -547,8 +547,8 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
} }
#pragma warning(pop) #pragma warning(pop)
#elif defined(MOZ_WIDGET_COCOA) #elif defined(MOZ_WIDGET_COCOA)
SInt32 majorVersion = nsCocoaFeatures::OSXVersionMajor(); SInt32 majorVersion = nsCocoaFeatures::macOSVersionMajor();
SInt32 minorVersion = nsCocoaFeatures::OSXVersionMinor(); SInt32 minorVersion = nsCocoaFeatures::macOSVersionMinor();
nsTextFormatter::ssprintf(osVersion, u"%ld.%ld", nsTextFormatter::ssprintf(osVersion, u"%ld.%ld",
majorVersion, majorVersion,
minorVersion); minorVersion);