Bug 1094338 - Allow depth texture on OS X 10.8.3 and higher. Clean up some OS X versioning tracking in the process. r=jgilbert
authorMilan Sreckovic <milan@mozilla.com>
Mon, 10 Nov 2014 22:15:22 -0500
changeset 240524 92e947245f1de0ed1d2d41f229d64ef731dd0ea5
parent 240523 39b1bc270aed524c278bda8bd88f4a820bcfc6ce
child 240525 076b942c1a6e2479f0c05b506e733ea8d075eb34
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1094338
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1094338 - Allow depth texture on OS X 10.8.3 and higher. Clean up some OS X versioning tracking in the process. r=jgilbert
dom/canvas/WebGLContextValidate.cpp
gfx/gl/GLContext.cpp
widget/cocoa/nsCocoaFeatures.h
widget/cocoa/nsCocoaFeatures.mm
widget/cocoa/nsNativeThemeCocoa.mm
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -1825,18 +1825,17 @@ WebGLContext::InitAndValidateGL()
         // Note that this used to cause crashes on old ATI drivers... hopefully not a significant
         // problem anymore. See bug 602183.
         gl->fEnable(LOCAL_GL_POINT_SPRITE);
     }
 
 #ifdef XP_MACOSX
     if (gl->WorkAroundDriverBugs() &&
         gl->Vendor() == gl::GLVendor::ATI &&
-        nsCocoaFeatures::OSXVersionMajor() == 10 &&
-        nsCocoaFeatures::OSXVersionMinor() < 9)
+        !nsCocoaFeatures::IsAtLeastVersion(10,9))
     {
         // The Mac ATI driver, in all known OSX version up to and including 10.8,
         // renders points sprites upside-down. Apple bug 11778921
         gl->fPointParameterf(LOCAL_GL_POINT_SPRITE_COORD_ORIGIN, LOCAL_GL_LOWER_LEFT);
     }
 #endif
 
     // Check the shader validator pref
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -678,21 +678,22 @@ GLContext::InitWithPrefix(const char *pr
 
             if (Renderer() == GLRenderer::MicrosoftBasicRenderDriver) {
                 // Bug 978966: on Microsoft's "Basic Render Driver" (software renderer)
                 // multisampling hardcodes blending with the default blendfunc, which breaks WebGL.
                 MarkUnsupported(GLFeature::framebuffer_multisample);
             }
 
 #ifdef XP_MACOSX
-            // The Mac Nvidia driver, for versions up to and including 10.8, don't seem
-            // to properly support this.  See 814839
+            // The Mac Nvidia driver, for versions up to and including 10.8,
+            // don't seem to properly support this.  See 814839
             // this has been fixed in Mac OS X 10.9. See 907946
+            // and it also works in 10.8.3 and higher.  See 1094338.
             if (Vendor() == gl::GLVendor::NVIDIA &&
-                !nsCocoaFeatures::OnMavericksOrLater())
+                !nsCocoaFeatures::IsAtLeastVersion(10,8,3))
             {
                 MarkUnsupported(GLFeature::depth_texture);
             }
 #endif
         }
 
         NS_ASSERTION(!IsExtensionSupported(GLContext::ARB_pixel_buffer_object) ||
                      (mSymbols.fMapBuffer && mSymbols.fUnmapBuffer),
--- a/widget/cocoa/nsCocoaFeatures.h
+++ b/widget/cocoa/nsCocoaFeatures.h
@@ -16,17 +16,16 @@ public:
   static int32_t OSXVersionBugFix();
   static bool OnLionOrLater();
   static bool OnMountainLionOrLater();
   static bool OnMavericksOrLater();
   static bool OnYosemiteOrLater();
   static bool SupportCoreAnimationPlugins();
   static bool AccelerateByDefault();
 
+  static bool IsAtLeastVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix=0);
+
 private:
   static void InitializeVersionNumbers();
 
   static int32_t mOSXVersion;
-  static int32_t mOSXVersionMajor;
-  static int32_t mOSXVersionMinor;
-  static int32_t mOSXVersionBugFix;
 };
 #endif // nsCocoaFeatures_h_
--- a/widget/cocoa/nsCocoaFeatures.mm
+++ b/widget/cocoa/nsCocoaFeatures.mm
@@ -1,31 +1,64 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+// This file makes some assumptions about the versions of OS X.
+// Instead of making it work major version 11 right now,
+// we will wait until that happens and worry about it then.
+// There are MOZ_ASSERTs to remind us to do that.
+// We are assuming that the minor version is less than 16.
+// There are MOZ_ASSERTs for that as well.
+
+// The formula for the version integer based on OS X version 10.minor.bugfix is
+// 0x1000 + (minor << 4) + bugifix.  See AssembleVersion() below.
+
 #define MAC_OS_X_VERSION_MASK      0x0000FFFF
+#define MAC_OS_X_VERSION_10_0_HEX  0x00001000
 #define MAC_OS_X_VERSION_10_6_HEX  0x00001060
 #define MAC_OS_X_VERSION_10_7_HEX  0x00001070
 #define MAC_OS_X_VERSION_10_8_HEX  0x00001080
 #define MAC_OS_X_VERSION_10_9_HEX  0x00001090
 #define MAC_OS_X_VERSION_10_10_HEX 0x000010A0
 
 #include "nsCocoaFeatures.h"
 #include "nsCocoaUtils.h"
 #include "nsDebug.h"
 #include "nsObjCExceptions.h"
 
 #import <Cocoa/Cocoa.h>
 
 int32_t nsCocoaFeatures::mOSXVersion = 0;
-int32_t nsCocoaFeatures::mOSXVersionMajor = 0;
-int32_t nsCocoaFeatures::mOSXVersionMinor = 0;
-int32_t nsCocoaFeatures::mOSXVersionBugFix = 0;
+
+inline int32_t AssembleVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
+{
+    MOZ_ASSERT(aMajor == 10);
+    return MAC_OS_X_VERSION_10_0_HEX + (aMinor << 4) + aBugFix;
+}
+
+inline int32_t ExtractMajorVersion(int32_t aVersion)
+{
+    MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion);
+    MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_10_0_HEX) == MAC_OS_X_VERSION_10_0_HEX);
+    return 10;
+}
+
+inline int32_t ExtractMinorVersion(int32_t aVersion)
+{
+    MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion);
+    return (aVersion & 0xF0) >> 4;
+}
+
+inline int32_t ExtractBugFixVersion(int32_t aVersion)
+{
+    MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion);
+    return aVersion & 0x0F;
+}
 
 static int intAtStringIndex(NSArray *array, int index)
 {
     return [(NSString *)[array objectAtIndex:index] integerValue];
 }
 
 static void GetSystemVersion(int &major, int &minor, int &bugfix)
 {
@@ -41,84 +74,85 @@ static void GetSystemVersion(int &major,
             minor = intAtStringIndex(versions, 1);
             if (count > 2) {
                 bugfix = intAtStringIndex(versions, 2);
             }
         }
     }
 }
 
+static int32_t GetFullVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
+{
+    int32_t osxVersion;
+    if (aMajor < 10) {
+        aMajor = 10;
+        NS_ERROR("Couldn't determine OS X version, assuming 10.6");
+        osxVersion = MAC_OS_X_VERSION_10_6_HEX;
+    } else if (aMinor < 6) {
+        aMinor = 6;
+        NS_ERROR("OS X version too old, assuming 10.6");
+        osxVersion = MAC_OS_X_VERSION_10_6_HEX;
+    } else {
+        MOZ_ASSERT(aMajor == 10);
+        MOZ_ASSERT(aMinor < 16);
+        MOZ_ASSERT(aBugFix >= 0);
+        MOZ_ASSERT(aBugFix < 16);
+        osxVersion = AssembleVersion(aMajor, aMinor, aBugFix);
+    }
+    MOZ_ASSERT(aMajor == ExtractMajorVersion(osxVersion));
+    MOZ_ASSERT(aMinor == ExtractMinorVersion(osxVersion));
+    MOZ_ASSERT(aBugFix == ExtractBugFixVersion(osxVersion));
+    return osxVersion;
+}
+
 /*static*/ void
 nsCocoaFeatures::InitializeVersionNumbers()
 {
     NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
     // Provide an autorelease pool to avoid leaking Cocoa objects,
     // as this gets called before the main autorelease pool is in place.
     nsAutoreleasePool localPool;
 
     int major, minor, bugfix;
     GetSystemVersion(major, minor, bugfix);
-
-    mOSXVersionMajor = major;
-    mOSXVersionMinor = minor;
-    mOSXVersionBugFix = bugfix;
-
-    if (major < 10) {
-        NS_ERROR("Couldn't determine OS X version, assuming 10.6");
-        mOSXVersion = MAC_OS_X_VERSION_10_6_HEX;
-        mOSXVersionMajor = 10;
-        mOSXVersionMinor = 6;
-        mOSXVersionBugFix = 0;
-    } else if (minor < 6) {
-        NS_ERROR("OS X version too old, assuming 10.6");
-        mOSXVersion = MAC_OS_X_VERSION_10_6_HEX;
-        mOSXVersionMinor = 6;
-        mOSXVersionBugFix = 0;
-    } else {
-        mOSXVersion = 0x1000 + (minor << 4);
-    }
+    mOSXVersion = GetFullVersion(major, minor, bugfix);
 
     NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 /* static */ int32_t
 nsCocoaFeatures::OSXVersion()
 {
+    // Don't let this be called while we're first setting the value...
+    MOZ_ASSERT((mOSXVersion & MAC_OS_X_VERSION_MASK) >= 0);
     if (!mOSXVersion) {
+        mOSXVersion = -1;
         InitializeVersionNumbers();
     }
     return mOSXVersion;
 }
 
 /* static */ int32_t
 nsCocoaFeatures::OSXVersionMajor()
 {
-    if (!mOSXVersion) {
-        InitializeVersionNumbers();
-    }
-    return mOSXVersionMajor;
+    MOZ_ASSERT((OSXVersion() & MAC_OS_X_VERSION_10_0_HEX) == MAC_OS_X_VERSION_10_0_HEX);
+    return 10;
 }
 
 /* static */ int32_t
 nsCocoaFeatures::OSXVersionMinor()
 {
-    if (!mOSXVersion) {
-        InitializeVersionNumbers();
-    }
-    return mOSXVersionMinor;
+    return ExtractMinorVersion(OSXVersion());
 }
 
 /* static */ int32_t
 nsCocoaFeatures::OSXVersionBugFix()
 {
-    if (!mOSXVersion) {
-        InitializeVersionNumbers();
-    }
-    return mOSXVersionBugFix;
+    return ExtractBugFixVersion(OSXVersion());
 }
 
 /* static */ bool
 nsCocoaFeatures::SupportCoreAnimationPlugins()
 {
     // Disallow Core Animation on 10.5 because of crashes.
     // See Bug 711564.
     return (OSXVersion() >= MAC_OS_X_VERSION_10_6_HEX);
@@ -146,13 +180,16 @@ nsCocoaFeatures::OnMavericksOrLater()
 nsCocoaFeatures::OnYosemiteOrLater()
 {
     return (OSXVersion() >= MAC_OS_X_VERSION_10_10_HEX);
 }
 
 /* static */ bool
 nsCocoaFeatures::AccelerateByDefault()
 {
-    return !(OSXVersionMajor() == 10 &&
-             OSXVersionMinor() == 6 &&
-             OSXVersionBugFix() <= 2);
+    return IsAtLeastVersion(10, 6, 3);
 }
 
+/* static */ bool
+nsCocoaFeatures::IsAtLeastVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
+{
+    return OSXVersion() >= GetFullVersion(aMajor, aMinor, aBugFix);
+}
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -1090,20 +1090,17 @@ nsNativeThemeCocoa::DrawMenuIcon(CGConte
     aIconSize.width, aIconSize.height);
 
   BOOL isDisabled = IsDisabled(aFrame, inState);
   BOOL isActive = CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
 
   // On 10.6 and at least on 10.7.0, Apple doesn’t seem to have implemented all
   // keys and values used on 10.7.5 and later. We can however draw menu icons
   // on earlier OS versions by using different keys/values.
-  BOOL otherKeysAndValues = !nsCocoaFeatures::OnLionOrLater() ||
-                            (nsCocoaFeatures::OSXVersionMajor() == 10 &&
-                             nsCocoaFeatures::OSXVersionMinor() == 7 &&
-                             nsCocoaFeatures::OSXVersionBugFix() < 5);
+  BOOL otherKeysAndValues = !nsCocoaFeatures::IsAtLeastVersion(10,7,5);
 
   // 2 states combined with 2 different backgroundTypeKeys on earlier versions.
   NSString* state = isDisabled ? @"disabled" :
     (isActive && !otherKeysAndValues) ? @"pressed" : @"normal";
   NSString* backgroundTypeKey = !otherKeysAndValues ? @"kCUIBackgroundTypeMenu" :
     !isDisabled && isActive ? @"backgroundTypeDark" : @"backgroundTypeLight";
 
   NSMutableArray* keys = [NSMutableArray arrayWithObjects:@"backgroundTypeKey",