diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn index d2b4eea652..91c8d0f456 100644 --- a/modules/desktop_capture/BUILD.gn +++ b/modules/desktop_capture/BUILD.gn @@ -77,9 +77,6 @@ if (rtc_include_tests) { "window_finder_unittest.cc", ] public_configs = [ ":x11_config" ] - if (is_win) { - deps += [ "../../rtc_base:win32" ] - } } } @@ -515,7 +512,10 @@ rtc_library("desktop_capture_generic") { "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 a8eacde62e..bbd35530a1 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 @@ void CroppingWindowCapturerWin::CaptureFrame() { } 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 4d3f83a0f9..8350ff669b 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 @@ TEST_F(ScreenCapturerIntegrationTest, // 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 @@ TEST_F(ScreenCapturerIntegrationTest, DISABLED_TwoMagnifierCapturers) { // 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_TwoMagnifierCapturers) { 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 032465fa88..ccfef49bc5 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 @@ bool GetCroppedWindowRect(HWND window, // 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 @@ WindowCaptureHelperWin::WindowCaptureHelperWin() { 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 4a73a9ac14..22b0c44aeb 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 @@ WindowCapturerWinGdi::CaptureResults WindowCapturerWinGdi::CaptureFrame( // 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 9471d83517..8fb8193520 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -694,7 +694,10 @@ rtc_library("net_helpers") { deps += [ ":ifaddrs_android" ] } if (is_win) { - deps += [ ":win32" ] + deps += [ + ":rtc_base_approved", + ":win32", + ] } } @@ -1406,7 +1409,6 @@ if (rtc_include_tests) { ":socket_server", ":stringutils", ":testclient", - "containers:flat_map", ":threading", "../api:array_view", "../api:scoped_refptr", @@ -1416,6 +1418,7 @@ if (rtc_include_tests) { "../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 bec854af03..f521f0f64b 100644 --- a/rtc_base/net_helpers.cc +++ b/rtc_base/net_helpers.cc @@ -16,7 +16,7 @@ #include #include -#include "rtc_base/win32.h" +#include "rtc_base/win/windows_version.h" #endif #if defined(WEBRTC_POSIX) && !defined(__native_client__) #include @@ -70,10 +70,10 @@ bool HasIPv6Enabled() { // 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 c90296ebbb..6e8d2873aa 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 // must come first +#include + +// Must be after winsock2.h. #include -// clang-format on typedef int socklen_t; @@ -39,66 +38,11 @@ typedef struct _TOKEN_MANDATORY_LABEL { #undef SetPort -#include - 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_