Bug 925599 - Replace gfxWindowsPlatform::WindowsOSVersion(). r=Bas
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 22 Nov 2013 12:35:40 +0900
changeset 156988 6c1ed54cd96c20991bae5eaa20bfa04b2e3de4fc
parent 156987 2e503bef99d77716724619a3b724a7da7cb31367
child 156989 34be216f6d0e8ef3a51140156a62a807ab315f48
push id36590
push userVYV03354@nifty.ne.jp
push dateFri, 22 Nov 2013 03:37:02 +0000
treeherdermozilla-inbound@01e15a1abbb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs925599
milestone28.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 925599 - Replace gfxWindowsPlatform::WindowsOSVersion(). r=Bas
gfx/thebes/gfxGDIFont.cpp
gfx/thebes/gfxGDIFontList.cpp
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
widget/windows/GfxInfo.cpp
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -1,16 +1,17 @@
 /* -*- 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/. */
 
 #include "gfxGDIFont.h"
 
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/WindowsVersion.h"
 
 #include "gfxGDIShaper.h"
 #include "gfxUniscribeShaper.h"
 #include "gfxHarfBuzzShaper.h"
 #include <algorithm>
 #include "gfxGraphiteShaper.h"
 #include "gfxWindowsPlatform.h"
 #include "gfxContext.h"
@@ -90,18 +91,17 @@ gfxGDIFont::CopyWithAntialiasOption(Anti
 static bool
 UseUniscribe(gfxShapedText *aShapedText,
              const PRUnichar *aText,
              uint32_t aLength)
 {
     uint32_t flags = aShapedText->Flags();
     bool useGDI;
 
-    bool isXP = (gfxWindowsPlatform::WindowsOSVersion() 
-                       < gfxWindowsPlatform::kWindowsVista);
+    bool isXP = !IsVistaOrLater();
 
     // bug 561304 - Uniscribe bug produces bad positioning at certain
     // font sizes on XP, so default to GDI on XP using logic of 3.6
 
     useGDI = isXP &&
              (flags &
                (gfxTextRunFactory::TEXT_OPTIMIZE_SPEED | 
                 gfxTextRunFactory::TEXT_IS_RTL)
@@ -141,18 +141,17 @@ gfxGDIFont::ShapeText(gfxContext      *a
     if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
         ok = mGraphiteShaper->ShapeText(aContext, aText,
                                         aOffset, aLength,
                                         aScript, aShapedText);
     }
 
     if (!ok && mHarfBuzzShaper) {
         if (gfxPlatform::GetPlatform()->UseHarfBuzzForScript(aScript) ||
-            (gfxWindowsPlatform::WindowsOSVersion() <
-                 gfxWindowsPlatform::kWindowsVista &&
+            (!IsVistaOrLater() &&
              ScriptShapingType(aScript) == SHAPING_INDIC &&
              !Preferences::GetBool("gfx.font_rendering.winxp-indic-uniscribe",
                                    false))) {
             ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
                                             aScript, aShapedText);
         }
     }
 
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -25,16 +25,17 @@
 #include "nsDirectoryServiceDefs.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIWindowsRegKey.h"
 #include "gfxFontConstants.h"
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/WindowsVersion.h"
 
 #include <usp10.h>
 
 using namespace mozilla;
 
 #define ROUND(x) floor((x) + 0.5)
 
 
@@ -213,18 +214,17 @@ GDIFontEntry::IsSymbolFont()
     // initialize cmap first
     HasCmapTable();
     return mSymbolFont;  
 }
 
 gfxFont *
 GDIFontEntry::CreateFontInstance(const gfxFontStyle* aFontStyle, bool aNeedsBold)
 {
-    bool isXP = (gfxWindowsPlatform::WindowsOSVersion() 
-                       < gfxWindowsPlatform::kWindowsVista);
+    bool isXP = !IsVistaOrLater();
 
     bool useClearType = isXP && !aFontStyle->systemFont &&
         (gfxWindowsPlatform::GetPlatform()->UseClearTypeAlways() ||
          (mIsUserFont && !mIsLocalUserFont &&
           gfxWindowsPlatform::GetPlatform()->UseClearTypeForDownloadableFonts()));
 
     return new gfxGDIFont(this, aFontStyle, aNeedsBold, 
                           (useClearType ? gfxFont::kAntialiasSubpixel
@@ -824,21 +824,20 @@ gfxGDIFontList::MakePlatformFont(const g
 
     if (!fe)
         return fe;
 
     fe->mIsUserFont = true;
 
     // Uniscribe doesn't place CFF fonts loaded privately 
     // via AddFontMemResourceEx on XP/Vista
-    if (isCFF && gfxWindowsPlatform::WindowsOSVersion() 
-                 < gfxWindowsPlatform::kWindows7) {
+    if (isCFF && !IsWin7OrLater()) {
         fe->mForceGDI = true;
     }
- 
+
     return fe;
 }
 
 gfxFontFamily*
 gfxGDIFontList::GetDefaultFont(const gfxFontStyle* aStyle)
 {
     // this really shouldn't fail to find a font....
     HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -9,16 +9,17 @@
 #include "gfxWindowsPlatform.h"
 
 #include "gfxImageSurface.h"
 #include "gfxWindowsSurface.h"
 
 #include "nsUnicharUtils.h"
 
 #include "mozilla/Preferences.h"
+#include "mozilla/WindowsVersion.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTArray.h"
 
 #include "nsIWindowsRegKey.h"
 #include "nsIFile.h"
 #include "plbase64.h"
 #include "nsIXULRuntime.h"
 
@@ -231,31 +232,28 @@ public:
     GPUAdapterReporter()
       : MemoryMultiReporter("gpu-adapter")
     {}
 
     NS_IMETHOD
     CollectReports(nsIMemoryReporterCallback* aCb,
                    nsISupports* aClosure)
     {
-        int32_t winVers, buildNum;
         HANDLE ProcessHandle = GetCurrentProcess();
 
         int64_t dedicatedBytesUsed = 0;
         int64_t sharedBytesUsed = 0;
         int64_t committedBytesUsed = 0;
         IDXGIAdapter *DXGIAdapter;
 
         HMODULE gdi32Handle;
         PFND3DKMTQS queryD3DKMTStatistics;
 
-        winVers = gfxWindowsPlatform::WindowsOSVersion(&buildNum);
-
         // GPU memory reporting is not available before Windows 7
-        if (winVers < gfxWindowsPlatform::kWindows7)
+        if (!IsWin7OrLater()) 
             return NS_OK;
 
         if (gdi32Handle = LoadLibrary(TEXT("gdi32.dll")))
             queryD3DKMTStatistics = (PFND3DKMTQS)GetProcAddress(gdi32Handle, "D3DKMTQueryStatistics");
 
         if (queryD3DKMTStatistics && GetDXGIAdapter(&DXGIAdapter)) {
             // Most of this block is understood thanks to wj32's work on Process Hacker
 
@@ -285,17 +283,17 @@ public:
                     queryStatistics.Type = D3DKMTQS_SEGMENT;
                     queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
                     queryStatistics.QuerySegment.SegmentId = i;
 
                     if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
                         bool aperture;
 
                         // SegmentInformation has a different definition in Win7 than later versions
-                        if (winVers < gfxWindowsPlatform::kWindows8)
+                        if (!IsWin8OrLater())
                             aperture = queryStatistics.QueryResult.SegmentInfoWin7.Aperture;
                         else
                             aperture = queryStatistics.QueryResult.SegmentInfoWin8.Aperture;
 
                         memset(&queryStatistics, 0, sizeof(D3DKMTQS));
                         queryStatistics.Type = D3DKMTQS_PROCESS_SEGMENT;
                         queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
                         queryStatistics.hProcess = ProcessHandle;
@@ -410,20 +408,17 @@ gfxWindowsPlatform::~gfxWindowsPlatform(
 void
 gfxWindowsPlatform::UpdateRenderMode()
 {
 /* Pick the default render mode for
  * desktop.
  */
     mRenderMode = RENDER_GDI;
 
-    OSVERSIONINFOA versionInfo;
-    versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
-    ::GetVersionExA(&versionInfo);
-    bool isVistaOrHigher = versionInfo.dwMajorVersion >= 6;
+    bool isVistaOrHigher = IsVistaOrLater();
 
     bool safeMode = false;
     nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
     if (xr)
       xr->GetInSafeMode(&safeMode);
 
     mUseDirectWrite = Preferences::GetBool("gfx.font_rendering.directwrite.enabled", false);
 
@@ -616,46 +611,23 @@ gfxWindowsPlatform::VerifyD2DDevice(bool
 
     if (mD2DDevice) {
         reporter.SetSuccessful();
         mozilla::gfx::Factory::SetDirect3D10Device(cairo_d2d_device_get_device(mD2DDevice));
     }
 #endif
 }
 
-// bug 630201 - older pre-RTM versions of Direct2D/DirectWrite cause odd
-// crashers so blacklist them altogether
-
-#ifdef CAIRO_HAS_DWRITE_FONT
-#define WINDOWS7_RTM_BUILD 7600
-
-static bool
-AllowDirectWrite()
-{
-    int32_t winVers, buildNum;
-
-    winVers = gfxWindowsPlatform::WindowsOSVersion(&buildNum);
-    if (winVers == gfxWindowsPlatform::kWindows7 &&
-        buildNum < WINDOWS7_RTM_BUILD)
-    {
-        // don't use Direct2D/DirectWrite on older versions of Windows 7
-        return false;
-    }
-
-    return true;
-}
-#endif
-
 gfxPlatformFontList*
 gfxWindowsPlatform::CreatePlatformFontList()
 {
     mUsingGDIFonts = false;
     gfxPlatformFontList *pfl;
 #ifdef CAIRO_HAS_DWRITE_FONT
-    if (AllowDirectWrite() && GetDWriteFactory()) {
+    if (GetDWriteFactory()) {
         pfl = new gfxDWriteFontList();
         if (NS_SUCCEEDED(pfl->InitFontList())) {
             return pfl;
         }
         // DWrite font initialization failed! Don't know why this would happen,
         // but apparently it can - see bug 594865.
         // So we're going to fall back to GDI fonts & rendering.
         gfxPlatformFontList::Shutdown();
@@ -1144,42 +1116,16 @@ gfxWindowsPlatform::UseClearTypeAlways()
 {
     if (mUseClearTypeAlways == UNINITIALIZED_VALUE) {
         mUseClearTypeAlways = Preferences::GetBool(GFX_USE_CLEARTYPE_ALWAYS, false);
     }
 
     return mUseClearTypeAlways;
 }
 
-int32_t
-gfxWindowsPlatform::WindowsOSVersion(int32_t *aBuildNum)
-{
-    static int32_t winVersion = UNINITIALIZED_VALUE;
-    static int32_t buildNum = UNINITIALIZED_VALUE;
-
-    OSVERSIONINFO vinfo;
-
-    if (winVersion == UNINITIALIZED_VALUE) {
-        vinfo.dwOSVersionInfoSize = sizeof (vinfo);
-        if (!GetVersionEx(&vinfo)) {
-            winVersion = kWindowsUnknown;
-            buildNum = 0;
-        } else {
-            winVersion = int32_t(vinfo.dwMajorVersion << 16) + vinfo.dwMinorVersion;
-            buildNum = int32_t(vinfo.dwBuildNumber);
-        }
-    }
-
-    if (aBuildNum) {
-        *aBuildNum = buildNum;
-    }
-
-    return winVersion;
-}
-
 void 
 gfxWindowsPlatform::GetDLLVersion(const PRUnichar *aDLLPath, nsAString& aVersion)
 {
     DWORD versInfoSize, vers[4] = {0};
     // version info not available case
     aVersion.Assign(NS_LITERAL_STRING("0.0.0.0"));
     versInfoSize = GetFileVersionInfoSizeW(aDLLPath, nullptr);
     nsAutoTArray<BYTE,512> versionInfo;
@@ -1502,17 +1448,17 @@ gfxWindowsPlatform::GetD3D11Device()
   D3D11CreateDeviceFunc d3d11CreateDevice = (D3D11CreateDeviceFunc)
     GetProcAddress(d3d11Module, "D3D11CreateDevice");
 
   if (!d3d11CreateDevice) {
     return nullptr;
   }
 
   nsTArray<D3D_FEATURE_LEVEL> featureLevels;
-  if (gfxWindowsPlatform::WindowsOSVersion() >= gfxWindowsPlatform::kWindows8) {
+  if (IsWin8OrLater()) {
     featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
   }
   featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
   featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
   featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
   featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
 
   RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -233,30 +233,16 @@ public:
 
     void ClearPrefFonts() { mPrefFonts.Clear(); }
 
     // ClearType is not always enabled even when available (e.g. Windows XP)
     // if either of these prefs are enabled and apply, use ClearType rendering
     bool UseClearTypeForDownloadableFonts();
     bool UseClearTypeAlways();
 
-    // OS version in 16.16 major/minor form
-    // based on http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
-    enum {
-        kWindowsUnknown = 0,
-        kWindowsXP = 0x50001,
-        kWindowsServer2003 = 0x50002,
-        kWindowsVista = 0x60000,
-        kWindows7 = 0x60001,
-        kWindows8 = 0x60002,
-        kWindows8_1 = 0x60003
-    };
-
-    static int32_t WindowsOSVersion(int32_t *aBuildNum = nullptr);
-
     static void GetDLLVersion(const PRUnichar *aDLLPath, nsAString& aVersion);
 
     // returns ClearType tuning information for each display
     static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
 
     virtual void FontsPrefsChanged(const char *aPref);
 
     void SetupClearTypeParams();
--- a/widget/windows/GfxInfo.cpp
+++ b/widget/windows/GfxInfo.cpp
@@ -228,16 +228,50 @@ ParseIDFromDeviceID(const nsAString &key
   if (start != -1) {
     id.Cut(0, start + strlen(prefix));
     id.Truncate(length);
   }
   nsresult err;
   return id.ToInteger(&err, 16);
 }
 
+// OS version in 16.16 major/minor form
+// based on http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
+enum {
+  kWindowsUnknown = 0,
+  kWindowsXP = 0x50001,
+  kWindowsServer2003 = 0x50002,
+  kWindowsVista = 0x60000,
+  kWindows7 = 0x60001,
+  kWindows8 = 0x60002,
+  kWindows8_1 = 0x60003
+};
+
+static int32_t
+WindowsOSVersion()
+{
+  static int32_t winVersion = UNINITIALIZED_VALUE;
+
+  OSVERSIONINFO vinfo;
+
+  if (winVersion == UNINITIALIZED_VALUE) {
+    vinfo.dwOSVersionInfoSize = sizeof (vinfo);
+#pragma warning(push)
+#pragma warning(disable:4996)
+    if (!GetVersionEx(&vinfo)) {
+#pragma warning(pop)
+      winVersion = kWindowsUnknown;
+    } else {
+      winVersion = int32_t(vinfo.dwMajorVersion << 16) + vinfo.dwMinorVersion;
+    }
+  }
+
+  return winVersion;
+}
+
 /* Other interesting places for info:
  *   IDXGIAdapter::GetDesc()
  *   IDirectDraw7::GetAvailableVidMem()
  *   e->GetAvailableTextureMem()
  * */
 
 #define DEVICE_KEY_PREFIX L"\\Registry\\Machine\\"
 nsresult
@@ -248,17 +282,17 @@ GfxInfo::Init()
   DISPLAY_DEVICEW displayDevice;
   displayDevice.cb = sizeof(displayDevice);
   int deviceIndex = 0;
 
   const char *spoofedWindowsVersion = PR_GetEnv("MOZ_GFX_SPOOF_WINDOWS_VERSION");
   if (spoofedWindowsVersion) {
     PR_sscanf(spoofedWindowsVersion, "%x", &mWindowsVersion);
   } else {
-    mWindowsVersion = gfxWindowsPlatform::WindowsOSVersion();
+    mWindowsVersion = WindowsOSVersion();
   }
 
   mDeviceKeyDebug = NS_LITERAL_STRING("PrimarySearch");
 
   while (EnumDisplayDevicesW(nullptr, deviceIndex, &displayDevice, 0)) {
     if (displayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
       mDeviceKeyDebug = NS_LITERAL_STRING("NullSearch");
       break;
@@ -290,17 +324,17 @@ GfxInfo::Init()
   // On Windows 8 and Server 2012 hosts, we want to not block RDP
   // sessions from attempting hardware acceleration.  RemoteFX
   // provides features and functionaltiy that can give a good D3D10 +
   // D2D + DirectWrite experience emulated via a software GPU.
   //
   // Unfortunately, the Device ID is nullptr, and we can't enumerate
   // it using the setup infrastructure (SetupDiGetClassDevsW below
   // will return INVALID_HANDLE_VALUE).
-  if (mWindowsVersion == gfxWindowsPlatform::kWindows8 &&
+  if (mWindowsVersion == kWindows8 &&
       mDeviceID.Length() == 0 &&
       mDeviceString.EqualsLiteral("RDPUDD Chained DD"))
   {
     WCHAR sysdir[255];
     UINT len = GetSystemDirectory(sysdir, sizeof(sysdir));
     if (len < sizeof(sysdir)) {
       nsString rdpudd(sysdir);
       rdpudd.AppendLiteral("\\rdpudd.dll");
@@ -753,29 +787,29 @@ GfxInfo::AddCrashReportAnnotations()
 
 #endif
 }
 
 static OperatingSystem
 WindowsVersionToOperatingSystem(int32_t aWindowsVersion)
 {
   switch(aWindowsVersion) {
-    case gfxWindowsPlatform::kWindowsXP:
+    case kWindowsXP:
       return DRIVER_OS_WINDOWS_XP;
-    case gfxWindowsPlatform::kWindowsServer2003:
+    case kWindowsServer2003:
       return DRIVER_OS_WINDOWS_SERVER_2003;
-    case gfxWindowsPlatform::kWindowsVista:
+    case kWindowsVista:
       return DRIVER_OS_WINDOWS_VISTA;
-    case gfxWindowsPlatform::kWindows7:
+    case kWindows7:
       return DRIVER_OS_WINDOWS_7;
-    case gfxWindowsPlatform::kWindows8:
+    case kWindows8:
       return DRIVER_OS_WINDOWS_8;
-    case gfxWindowsPlatform::kWindows8_1:
+    case kWindows8_1:
       return DRIVER_OS_WINDOWS_8_1;
-    case gfxWindowsPlatform::kWindowsUnknown:
+    case kWindowsUnknown:
     default:
       return DRIVER_OS_UNKNOWN;
     };
 }
 
 const nsTArray<GfxDriverInfo>&
 GfxInfo::GetGfxDriverInfo()
 {
@@ -1018,17 +1052,17 @@ GfxInfo::GetFeatureStatusImpl(int32_t aF
     uint64_t driverVersion;
     if (!ParseDriverVersion(adapterDriverVersionString, &driverVersion)) {
       return NS_ERROR_FAILURE;
     }
 
     // special-case the WinXP test slaves: they have out-of-date drivers, but we still want to
     // whitelist them, actually we do know that this combination of device and driver version
     // works well.
-    if (mWindowsVersion == gfxWindowsPlatform::kWindowsXP &&
+    if (mWindowsVersion == kWindowsXP &&
         adapterVendorID.Equals(GfxDriverInfo::GetDeviceVendor(VendorNVIDIA), nsCaseInsensitiveStringComparator()) &&
         adapterDeviceID.LowerCaseEqualsLiteral("0x0861") && // GeForce 9400
         driverVersion == V(6,14,11,7756))
     {
       *aStatus = FEATURE_NO_INFO;
       return NS_OK;
     }