diff --git a/modules/desktop_capture/win/wgc_capturer_win.cc b/modules/desktop_capture/win/wgc_capturer_win.cc index 9c545597aa..54a0917842 100644 --- a/modules/desktop_capture/win/wgc_capturer_win.cc +++ b/modules/desktop_capture/win/wgc_capturer_win.cc @@ -38,6 +38,7 @@ constexpr wchar_t kCoreMessagingDll[] = L"CoreMessaging.dll"; constexpr wchar_t kWgcSessionType[] = L"Windows.Graphics.Capture.GraphicsCaptureSession"; constexpr wchar_t kApiContract[] = L"Windows.Foundation.UniversalApiContract"; +constexpr wchar_t kDirtyRegionMode[] = L"DirtyRegionMode"; constexpr UINT16 kRequiredApiContractVersion = 8; enum class WgcCapturerResult { @@ -58,6 +59,44 @@ void RecordWgcCapturerResult(WgcCapturerResult error) { static_cast(WgcCapturerResult::kMaxValue)); } +// Checks if the DirtyRegionMode property is present in GraphicsCaptureSession +// and logs a boolean histogram with the result. +// TODO(https://crbug.com/40259177): Detecting support for this property means +// that the WGC API supports dirty regions and it can be utilized to improve +// the capture performance and the existing zero-herz support. +void LogDirtyRegionSupport() { + ComPtr + api_info_statics; + HRESULT hr = GetActivationFactory< + ABI::Windows::Foundation::Metadata::IApiInformationStatics, + RuntimeClass_Windows_Foundation_Metadata_ApiInformation>( + &api_info_statics); + if (FAILED(hr)) { + return; + } + + HSTRING dirty_region_mode; + hr = webrtc::CreateHstring(kDirtyRegionMode, wcslen(kDirtyRegionMode), + &dirty_region_mode); + if (FAILED(hr)) { + webrtc::DeleteHstring(dirty_region_mode); + return; + } + + HSTRING wgc_session_type; + hr = webrtc::CreateHstring(kWgcSessionType, wcslen(kWgcSessionType), + &wgc_session_type); + if (SUCCEEDED(hr)) { + boolean is_dirty_region_mode_supported = + api_info_statics->IsPropertyPresent(wgc_session_type, dirty_region_mode, + &is_dirty_region_mode_supported); + RTC_HISTOGRAM_BOOLEAN("WebRTC.DesktopCapture.Win.WgcDirtyRegionSupport", + !!is_dirty_region_mode_supported); + } + webrtc::DeleteHstring(dirty_region_mode); + webrtc::DeleteHstring(wgc_session_type); +} + } // namespace bool IsWgcSupported(CaptureType capture_type) { @@ -87,7 +126,7 @@ bool IsWgcSupported(CaptureType capture_type) { if (!ResolveCoreWinRTDelayload()) return false; - // We need to check if the WGC APIs are presesnt on the system. Certain SKUs + // We need to check if the WGC APIs are present on the system. Certain SKUs // of Windows ship without these APIs. ComPtr api_info_statics; @@ -156,6 +195,7 @@ WgcCapturerWin::WgcCapturerWin( reinterpret_cast(GetProcAddress( core_messaging_library_, "CreateDispatcherQueueController")); } + LogDirtyRegionSupport(); } WgcCapturerWin::~WgcCapturerWin() {