win: Consolidate on a single version checking API
No intended behavior change.
Happens to remove one call to GetVersionEx.
Bug: chromium:1255114
Change-Id: If4d1c57fa27ad4a7547f8f18c3abe38bc9b2a325
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/234160
Reviewed-by: Joe Downing <joedow@chromium.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35146}
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index d2b4eea..91c8d0f 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -77,9 +77,6 @@
"window_finder_unittest.cc",
]
public_configs = [ ":x11_config" ]
- if (is_win) {
- deps += [ "../../rtc_base:win32" ]
- }
}
}
@@ -515,7 +512,10 @@
"d3d11.lib",
"dxgi.lib",
]
- deps += [ "../../rtc_base:win32" ]
+ deps += [
+ "../../rtc_base:rtc_base_approved",
+ "../../rtc_base:win32",
+ ]
}
absl_deps = [
diff --git a/modules/desktop_capture/cropping_window_capturer_win.cc b/modules/desktop_capture/cropping_window_capturer_win.cc
index a8eacde..bbd3553 100644
--- a/modules/desktop_capture/cropping_window_capturer_win.cc
+++ b/modules/desktop_capture/cropping_window_capturer_win.cc
@@ -15,7 +15,7 @@
#include "modules/desktop_capture/win/window_capture_utils.h"
#include "rtc_base/logging.h"
#include "rtc_base/trace_event.h"
-#include "rtc_base/win32.h"
+#include "rtc_base/win/windows_version.h"
namespace webrtc {
@@ -196,7 +196,8 @@
}
bool CroppingWindowCapturerWin::ShouldUseScreenCapturer() {
- if (!rtc::IsWindows8OrLater() && window_capture_helper_.IsAeroEnabled()) {
+ if (rtc::rtc_win::GetVersion() < rtc::rtc_win::Version::VERSION_WIN8 &&
+ window_capture_helper_.IsAeroEnabled()) {
return false;
}
diff --git a/modules/desktop_capture/screen_capturer_integration_test.cc b/modules/desktop_capture/screen_capturer_integration_test.cc
index 4d3f83a..8350ff6 100644
--- a/modules/desktop_capture/screen_capturer_integration_test.cc
+++ b/modules/desktop_capture/screen_capturer_integration_test.cc
@@ -33,7 +33,7 @@
#if defined(WEBRTC_WIN)
#include "modules/desktop_capture/win/screen_capturer_win_directx.h"
-#include "rtc_base/win32.h"
+#include "rtc_base/win/windows_version.h"
#endif // defined(WEBRTC_WIN)
using ::testing::_;
@@ -338,7 +338,7 @@
// Bug https://bugs.chromium.org/p/webrtc/issues/detail?id=6844
// TODO(zijiehe): Find the root cause of the border and failure, which cannot
// reproduce on my dev machine.
- if (rtc::IsWindows8OrLater()) {
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_WIN8) {
return;
}
CreateMagnifierCapturer();
@@ -351,7 +351,7 @@
// Bug https://bugs.chromium.org/p/webrtc/issues/detail?id=6844
// TODO(zijiehe): Find the root cause of the border and failure, which cannot
// reproduce on my dev machine.
- if (rtc::IsWindows8OrLater()) {
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_WIN8) {
return;
}
CreateMagnifierCapturer();
@@ -362,7 +362,7 @@
TEST_F(ScreenCapturerIntegrationTest,
DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) {
- if (!rtc::IsWindows8OrLater()) {
+ if (rtc::rtc_win::GetVersion() < rtc::rtc_win::Version::VERSION_WIN8) {
// ScreenCapturerWinGdi randomly returns blank screen, the root cause is
// still unknown. Bug,
// https://bugs.chromium.org/p/webrtc/issues/detail?id=6843.
diff --git a/modules/desktop_capture/win/window_capture_utils.cc b/modules/desktop_capture/win/window_capture_utils.cc
index 032465f..ccfef49 100644
--- a/modules/desktop_capture/win/window_capture_utils.cc
+++ b/modules/desktop_capture/win/window_capture_utils.cc
@@ -20,7 +20,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/string_utils.h"
-#include "rtc_base/win32.h"
+#include "rtc_base/win/windows_version.h"
namespace webrtc {
@@ -179,7 +179,8 @@
// As of Windows8, transparent resize borders are added by the OS at
// left/bottom/right sides of a resizeable window. If the cropped window
// doesn't remove these borders, the background will be exposed a bit.
- if (rtc::IsWindows8OrLater() || is_maximized) {
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_WIN8 ||
+ is_maximized) {
// Only apply this cropping to windows with a resize border (otherwise,
// it'd clip the edges of captured pop-up windows without this border).
LONG style = GetWindowLong(window, GWL_STYLE);
@@ -311,7 +312,7 @@
GetProcAddress(dwmapi_library_, "DwmGetWindowAttribute"));
}
- if (rtc::IsWindows10OrLater()) {
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_WIN10) {
if (FAILED(::CoCreateInstance(__uuidof(VirtualDesktopManager), nullptr,
CLSCTX_ALL,
IID_PPV_ARGS(&virtual_desktop_manager_)))) {
diff --git a/modules/desktop_capture/win/window_capturer_win_gdi.cc b/modules/desktop_capture/win/window_capturer_win_gdi.cc
index 4a73a9a..22b0c44 100644
--- a/modules/desktop_capture/win/window_capturer_win_gdi.cc
+++ b/modules/desktop_capture/win/window_capturer_win_gdi.cc
@@ -29,7 +29,7 @@
#include "rtc_base/string_utils.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
-#include "rtc_base/win32.h"
+#include "rtc_base/win/windows_version.h"
#include "system_wrappers/include/metrics.h"
namespace webrtc {
@@ -295,7 +295,7 @@
// on Windows 8.1 and later, PrintWindow is only used when the window is
// occluded. When the window is not occluded, it is much faster to capture
// the screen and to crop it to the window position and size.
- if (rtc::IsWindows8OrLater()) {
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_WIN8) {
// Special flag that makes PrintWindow to work on Windows 8.1 and later.
// Indeed certain apps (e.g. those using DirectComposition rendering) can't
// be captured using BitBlt or PrintWindow without this flag. Note that on
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 9471d83..8fb8193 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -694,7 +694,10 @@
deps += [ ":ifaddrs_android" ]
}
if (is_win) {
- deps += [ ":win32" ]
+ deps += [
+ ":rtc_base_approved",
+ ":win32",
+ ]
}
}
@@ -1406,7 +1409,6 @@
":socket_server",
":stringutils",
":testclient",
- "containers:flat_map",
":threading",
"../api:array_view",
"../api:scoped_refptr",
@@ -1416,6 +1418,7 @@
"../test:fileutils",
"../test:test_main",
"../test:test_support",
+ "containers:flat_map",
"containers:unittests",
"memory:unittests",
"synchronization:mutex",
diff --git a/rtc_base/net_helpers.cc b/rtc_base/net_helpers.cc
index bec854a..f521f0f 100644
--- a/rtc_base/net_helpers.cc
+++ b/rtc_base/net_helpers.cc
@@ -16,7 +16,7 @@
#include <ws2spi.h>
#include <ws2tcpip.h>
-#include "rtc_base/win32.h"
+#include "rtc_base/win/windows_version.h"
#endif
#if defined(WEBRTC_POSIX) && !defined(__native_client__)
#include <arpa/inet.h>
@@ -70,10 +70,10 @@
// WinUWP always has IPv6 capability.
return true;
#elif defined(WEBRTC_WIN)
- if (IsWindowsVistaOrLater()) {
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_VISTA) {
return true;
}
- if (!IsWindowsXpOrLater()) {
+ if (rtc::rtc_win::GetVersion() < rtc::rtc_win::Version::VERSION_XP) {
return false;
}
DWORD protbuff_size = 4096;
diff --git a/rtc_base/win32.h b/rtc_base/win32.h
index c90296e..6e8d287 100644
--- a/rtc_base/win32.h
+++ b/rtc_base/win32.h
@@ -20,11 +20,10 @@
#define NOMINMAX
#endif
-// clang-format off
-// clang formating would change include order.
-#include <winsock2.h> // must come first
+#include <winsock2.h>
+
+// Must be after winsock2.h.
#include <windows.h>
-// clang-format on
typedef int socklen_t;
@@ -39,66 +38,11 @@
#undef SetPort
-#include <string>
-
namespace rtc {
const char* win32_inet_ntop(int af, const void* src, char* dst, socklen_t size);
int win32_inet_pton(int af, const char* src, void* dst);
-enum WindowsMajorVersions {
- kWindows2000 = 5,
- kWindowsVista = 6,
- kWindows10 = 10,
-};
-
-#if !defined(WINUWP)
-bool GetOsVersion(int* major, int* minor, int* build);
-
-inline bool IsWindowsVistaOrLater() {
- int major;
- return (GetOsVersion(&major, nullptr, nullptr) && major >= kWindowsVista);
-}
-
-inline bool IsWindowsXpOrLater() {
- int major, minor;
- return (GetOsVersion(&major, &minor, nullptr) &&
- (major >= kWindowsVista || (major == kWindows2000 && minor >= 1)));
-}
-
-inline bool IsWindows8OrLater() {
- int major, minor;
- return (GetOsVersion(&major, &minor, nullptr) &&
- (major > kWindowsVista || (major == kWindowsVista && minor >= 2)));
-}
-
-inline bool IsWindows10OrLater() {
- int major;
- return (GetOsVersion(&major, nullptr, nullptr) && (major >= kWindows10));
-}
-
-#else
-
-// When targetting WinUWP the OS must be Windows 10 (or greater) as lesser
-// Windows OS targets are not supported.
-inline bool IsWindowsVistaOrLater() {
- return true;
-}
-
-inline bool IsWindowsXpOrLater() {
- return true;
-}
-
-inline bool IsWindows8OrLater() {
- return true;
-}
-
-inline bool IsWindows10OrLater() {
- return true;
-}
-
-#endif // !defined(WINUWP)
-
} // namespace rtc
#endif // RTC_BASE_WIN32_H_