Bug 1630371 - Disable DirectComposition when we have a scaled resolution and no hardware stretching. r=aosmond
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 16 Apr 2020 14:54:17 +0000
changeset 524471 fce1cf0a2abb78829f17c2d7178885272abe7d6b
parent 524470 c424381097d7cd4e386939977dbcde0cf940e601
child 524472 35dbf0dcac73ee69c2adb53163da74d11de2d4c0
push id113209
push userjmuizelaar@mozilla.com
push dateThu, 16 Apr 2020 19:14:17 +0000
treeherderautoland@fce1cf0a2abb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaosmond
bugs1630371
milestone77.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 1630371 - Disable DirectComposition when we have a scaled resolution and no hardware stretching. r=aosmond Differential Revision: https://phabricator.services.mozilla.com/D71089
gfx/thebes/DisplayConfigWindows.cpp
gfx/thebes/DisplayConfigWindows.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/moz.build
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/DisplayConfigWindows.cpp
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 <iostream>
+#include <windows.h>
+#include <wingdi.h>
+#include <optional>
+#include <vector>
+
+#include "DisplayConfigWindows.h"
+
+namespace mozilla {
+namespace gfx {
+
+using namespace std;
+
+struct DisplayConfig {
+  vector<DISPLAYCONFIG_PATH_INFO> mPaths;
+  vector<DISPLAYCONFIG_MODE_INFO> mModes;
+};
+
+optional<DisplayConfig> GetDisplayConfig() {
+  LONG result;
+
+  UINT32 numPaths;
+  UINT32 numModes;
+  vector<DISPLAYCONFIG_PATH_INFO> paths;
+  vector<DISPLAYCONFIG_MODE_INFO> modes;
+  do {
+    result = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPaths,
+                                         &numModes);
+    if (result != ERROR_SUCCESS) {
+      return {};
+    }
+    // allocate the recommended amount of space
+    paths.resize(numPaths);
+    modes.resize(numModes);
+
+    result = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &numPaths, paths.data(),
+                                &numModes, modes.data(), NULL);
+    // try again if there wasn't enough space
+  } while (result == ERROR_INSUFFICIENT_BUFFER);
+
+  if (result != ERROR_SUCCESS) return {};
+
+  // shrink to fit the actual number of modes and paths returned
+  modes.resize(numModes);
+  paths.resize(numPaths);
+
+  return DisplayConfig{paths, modes};
+}
+
+bool HasScaledResolution() {
+  auto config = GetDisplayConfig();
+  if (config) {
+    for (auto& path : config->mPaths) {
+      auto& modes = config->mModes;
+      int targetModeIndex = path.targetInfo.modeInfoIdx;
+      int sourceModeIndex = path.sourceInfo.modeInfoIdx;
+
+      // Check if the source and target resolutions are different
+      if ((modes[targetModeIndex]
+               .targetMode.targetVideoSignalInfo.activeSize.cx !=
+           modes[sourceModeIndex].sourceMode.width) ||
+          (modes[targetModeIndex]
+               .targetMode.targetVideoSignalInfo.activeSize.cy !=
+           modes[sourceModeIndex].sourceMode.height)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+}  // namespace gfx
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/DisplayConfigWindows.h
@@ -0,0 +1,17 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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/. */
+
+#ifndef mozilla_gfx_thebes_DisplayConfigWindows_h
+#define mozilla_gfx_thebes_DisplayConfigWindows_h
+
+namespace mozilla {
+namespace gfx {
+
+extern bool HasScaledResolution();
+
+}  // namespace gfx
+}  // namespace mozilla
+
+#endif  // mozilla_gfx_thebes_DisplayConfigWindows_h
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -59,16 +59,17 @@
 #endif
 
 #include "nsXULAppAPI.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 
 #if defined(XP_WIN)
 #  include "gfxWindowsPlatform.h"
+#  include "DisplayConfigWindows.h"
 #elif defined(XP_MACOSX)
 #  include "gfxPlatformMac.h"
 #  include "gfxQuartzSurface.h"
 #  include "nsCocoaFeatures.h"
 #elif defined(MOZ_WIDGET_GTK)
 #  include "gfxPlatformGtk.h"
 #elif defined(ANDROID)
 #  include "gfxAndroidPlatform.h"
@@ -3081,22 +3082,21 @@ void gfxPlatform::InitWebRenderConfig() 
     featureComp.Disable(
         FeatureStatus::Unavailable, "No DirectComposition usage",
         NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_DIRECTCOMPOSITION"));
   }
 
   // Disable native compositor when hardware stretching is not supported. It is
   // for avoiding a problem like Bug 1618370.
   // XXX Is there a better check for Bug 1618370?
-  if (!DeviceManagerDx::Get()->CheckHardwareStretchingSupport()) {
-    /*
+  if (!DeviceManagerDx::Get()->CheckHardwareStretchingSupport() &&
+      HasScaledResolution()) {
     featureComp.Disable(
         FeatureStatus::Unavailable, "No hardware stretching support",
         NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_HARDWARE_STRETCHING"));
-    */
   }
 
 #endif
 
   if (!StaticPrefs::gfx_webrender_picture_caching()) {
     featureComp.ForceDisable(
         FeatureStatus::Unavailable, "Picture caching is disabled",
         NS_LITERAL_CSTRING("FEATURE_FAILURE_PICTURE_CACHING_DISABLED"));
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -150,16 +150,17 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wi
         'gfxWindowsPlatform.h',
         'gfxWindowsSurface.h',
     ]
     EXPORTS.mozilla.gfx += [
         'PrintTargetPDF.h',
         'PrintTargetWindows.h',
     ]
     SOURCES += [
+        'DisplayConfigWindows.cpp',
         'gfxDWriteCommon.cpp',
         'gfxDWriteFonts.cpp',
         'gfxGDIFont.cpp',
         'gfxGDIFontList.cpp',
         'gfxWindowsNativeDrawing.cpp',
         'gfxWindowsPlatform.cpp',
         'gfxWindowsSurface.cpp',
         'PrintTargetPDF.cpp',