Bug 1212982 - Get ClearType parameters using API instead of reading registry. r=jrmuizel
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 01 Feb 2019 22:48:37 +0900
changeset 460204 37069977b1e6873e6ef54d4c4b8e5ed3554bc02a
parent 460203 b7edcc2144422a0b8e46e5cc7cb2091794dd7ba3
child 460205 ddb817eed3bc951cba0c3b43a68e2c3d1aacc470
push id35587
push usernbeleuzu@mozilla.com
push dateThu, 21 Feb 2019 15:56:54 +0000
treeherdermozilla-central@471db22054e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1212982
milestone67.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 1212982 - Get ClearType parameters using API instead of reading registry. r=jrmuizel This patch is changing a way to get ClearType paramters because registry key may not be present. CreateMonitorRenderingParams() will return default values if the corresponding registry key is not present.
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -1061,105 +1061,52 @@ void gfxWindowsPlatform::GetDLLVersion(c
   vers[2] = HIWORD(fileVersLS);
   vers[3] = LOWORD(fileVersLS);
 
   char buf[256];
   SprintfLiteral(buf, "%u.%u.%u.%u", vers[0], vers[1], vers[2], vers[3]);
   aVersion.Assign(NS_ConvertUTF8toUTF16(buf));
 }
 
-void gfxWindowsPlatform::GetCleartypeParams(
-    nsTArray<ClearTypeParameterInfo>& aParams) {
-  HKEY hKey, subKey;
-  DWORD i, rv, size, type;
-  WCHAR displayName[256], subkeyName[256];
-
-  aParams.Clear();
+static BOOL CALLBACK AppendClearTypeParams(HMONITOR aMonitor, HDC, LPRECT,
+                                           LPARAM aContext) {
+  MONITORINFOEXW monitorInfo;
+  monitorInfo.cbSize = sizeof(MONITORINFOEXW);
+  if (!GetMonitorInfoW(aMonitor, &monitorInfo)) {
+    return TRUE;
+  }
 
-  // construct subkeys based on HKLM subkeys, assume they are same for HKCU
-  rv =
-      RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Avalon.Graphics",
-                    0, KEY_READ, &hKey);
+  ClearTypeParameterInfo ctinfo;
+  ctinfo.displayName.Assign(monitorInfo.szDevice);
 
-  if (rv != ERROR_SUCCESS) {
-    return;
+  RefPtr<IDWriteRenderingParams> renderingParams;
+  HRESULT hr = Factory::GetDWriteFactory()->CreateMonitorRenderingParams(
+      aMonitor, getter_AddRefs(renderingParams));
+  if (FAILED(hr)) {
+    return TRUE;
   }
 
-  // enumerate over subkeys
-  for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) {
-    size = ArrayLength(displayName);
-    rv = RegEnumKeyExW(hKey, i, displayName, &size, nullptr, nullptr, nullptr,
-                       nullptr);
-    if (rv != ERROR_SUCCESS) {
-      continue;
-    }
-
-    ClearTypeParameterInfo ctinfo;
-    ctinfo.displayName.Assign(displayName);
-
-    DWORD subrv, value;
-    bool foundData = false;
-
-    swprintf_s(subkeyName, ArrayLength(subkeyName),
-               L"Software\\Microsoft\\Avalon.Graphics\\%s", displayName);
-
-    // subkey for gamma, pixel structure
-    subrv = RegOpenKeyExW(HKEY_LOCAL_MACHINE, subkeyName, 0, KEY_QUERY_VALUE,
-                          &subKey);
-
-    if (subrv == ERROR_SUCCESS) {
-      size = sizeof(value);
-      subrv = RegQueryValueExW(subKey, L"GammaLevel", nullptr, &type,
-                               (LPBYTE)&value, &size);
-      if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
-        foundData = true;
-        ctinfo.gamma = value;
-      }
+  ctinfo.gamma = renderingParams->GetGamma() * 1000;
+  ctinfo.pixelStructure = renderingParams->GetPixelGeometry();
+  ctinfo.clearTypeLevel = renderingParams->GetClearTypeLevel() * 100;
+  ctinfo.enhancedContrast = renderingParams->GetEnhancedContrast() * 100;
 
-      size = sizeof(value);
-      subrv = RegQueryValueExW(subKey, L"PixelStructure", nullptr, &type,
-                               (LPBYTE)&value, &size);
-      if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
-        foundData = true;
-        ctinfo.pixelStructure = value;
-      }
-
-      RegCloseKey(subKey);
-    }
-
-    // subkey for cleartype level, enhanced contrast
-    subrv = RegOpenKeyExW(HKEY_CURRENT_USER, subkeyName, 0, KEY_QUERY_VALUE,
-                          &subKey);
+  auto* params = reinterpret_cast<nsTArray<ClearTypeParameterInfo>*>(aContext);
+  params->AppendElement(ctinfo);
+  return TRUE;
+}
 
-    if (subrv == ERROR_SUCCESS) {
-      size = sizeof(value);
-      subrv = RegQueryValueExW(subKey, L"ClearTypeLevel", nullptr, &type,
-                               (LPBYTE)&value, &size);
-      if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
-        foundData = true;
-        ctinfo.clearTypeLevel = value;
-      }
-
-      size = sizeof(value);
-      subrv = RegQueryValueExW(subKey, L"EnhancedContrastLevel", nullptr, &type,
-                               (LPBYTE)&value, &size);
-      if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
-        foundData = true;
-        ctinfo.enhancedContrast = value;
-      }
-
-      RegCloseKey(subKey);
-    }
-
-    if (foundData) {
-      aParams.AppendElement(ctinfo);
-    }
+void gfxWindowsPlatform::GetCleartypeParams(
+    nsTArray<ClearTypeParameterInfo>& aParams) {
+  aParams.Clear();
+  if (!DWriteEnabled()) {
+    return;
   }
-
-  RegCloseKey(hKey);
+  EnumDisplayMonitors(nullptr, nullptr, AppendClearTypeParams,
+                      reinterpret_cast<LPARAM>(&aParams));
 }
 
 void gfxWindowsPlatform::FontsPrefsChanged(const char* aPref) {
   bool clearTextFontCaches = true;
 
   gfxPlatform::FontsPrefsChanged(aPref);
 
   if (aPref &&
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -178,17 +178,17 @@ class gfxWindowsPlatform : public gfxPla
 
   // returns ClearType tuning information for each display
   static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
 
   virtual void FontsPrefsChanged(const char* aPref) override;
 
   void SetupClearTypeParams();
 
-  inline bool DWriteEnabled() const {
+  static inline bool DWriteEnabled() {
     return !!mozilla::gfx::Factory::GetDWriteFactory();
   }
   inline DWRITE_MEASURING_MODE DWriteMeasuringMode() { return mMeasuringMode; }
 
   IDWriteRenderingParams* GetRenderingParams(TextRenderingMode aRenderMode) {
     return mRenderingParams[aRenderMode];
   }