From 3f2a3b19e3de1531fed98a6d8295f89a79f6d969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zarach?= Date: Thu, 24 Nov 2022 17:32:45 +0100 Subject: [PATCH] [DesktopCapture]: Allow toggling the visibility of the cursor This is a change needed to implement (cursor: 'never') https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/cursor constraint. Bug: chromium:1007177 Change-Id: Id7fae62de180d46a3874856978a3fda559aa6477 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282861 Commit-Queue: Alexander Cooper Reviewed-by: Alexander Cooper Cr-Commit-Position: refs/heads/main@{#38770} --- AUTHORS | 1 + modules/desktop_capture/win/wgc_capture_session.cc | 11 ++++++++++- modules/desktop_capture/win/wgc_capture_session.h | 2 +- modules/desktop_capture/win/wgc_capturer_win.cc | 12 +++++++----- modules/desktop_capture/win/wgc_capturer_win.h | 5 ++++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 7c7cb34709..ad0220d4d9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -79,6 +79,7 @@ Maksim Sisov Maxim Pavlov Maxim Potapov Michael Iedema +MichaƂ Zarach Michel Promonet Miguel Paris Mike Gilbert diff --git a/modules/desktop_capture/win/wgc_capture_session.cc b/modules/desktop_capture/win/wgc_capture_session.cc index 831257b4d4..e16529167f 100644 --- a/modules/desktop_capture/win/wgc_capture_session.cc +++ b/modules/desktop_capture/win/wgc_capture_session.cc @@ -105,7 +105,7 @@ WgcCaptureSession::~WgcCaptureSession() { RemoveEventHandlers(); } -HRESULT WgcCaptureSession::StartCapture() { +HRESULT WgcCaptureSession::StartCapture(const DesktopCaptureOptions& options) { RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DCHECK(!is_capture_started_); @@ -187,6 +187,15 @@ HRESULT WgcCaptureSession::StartCapture() { return hr; } + if (!options.prefer_cursor_embedded()) { + ComPtr session2; + if (SUCCEEDED(session_->QueryInterface( + ABI::Windows::Graphics::Capture::IID_IGraphicsCaptureSession2, + &session2))) { + session2->put_IsCursorCaptureEnabled(false); + } + } + hr = session_->StartCapture(); if (FAILED(hr)) { RTC_LOG(LS_ERROR) << "Failed to start CaptureSession: " << hr; diff --git a/modules/desktop_capture/win/wgc_capture_session.h b/modules/desktop_capture/win/wgc_capture_session.h index 27d412baf9..dfe1fa60bb 100644 --- a/modules/desktop_capture/win/wgc_capture_session.h +++ b/modules/desktop_capture/win/wgc_capture_session.h @@ -39,7 +39,7 @@ class WgcCaptureSession final { ~WgcCaptureSession(); - HRESULT StartCapture(); + HRESULT StartCapture(const DesktopCaptureOptions& options); // Returns a frame from the frame pool, if any are present. HRESULT GetFrame(std::unique_ptr* output_frame); diff --git a/modules/desktop_capture/win/wgc_capturer_win.cc b/modules/desktop_capture/win/wgc_capturer_win.cc index ce5eb6b31f..8ec6a29f23 100644 --- a/modules/desktop_capture/win/wgc_capturer_win.cc +++ b/modules/desktop_capture/win/wgc_capturer_win.cc @@ -140,10 +140,12 @@ bool IsWgcSupported(CaptureType capture_type) { } WgcCapturerWin::WgcCapturerWin( + const DesktopCaptureOptions& options, std::unique_ptr source_factory, std::unique_ptr source_enumerator, bool allow_delayed_capturable_check) - : source_factory_(std::move(source_factory)), + : options_(options), + source_factory_(std::move(source_factory)), source_enumerator_(std::move(source_enumerator)), allow_delayed_capturable_check_(allow_delayed_capturable_check) { if (!core_messaging_library_) @@ -166,7 +168,7 @@ std::unique_ptr WgcCapturerWin::CreateRawWindowCapturer( const DesktopCaptureOptions& options, bool allow_delayed_capturable_check) { return std::make_unique( - std::make_unique(), + options, std::make_unique(), std::make_unique( options.enumerate_current_process_windows()), allow_delayed_capturable_check); @@ -176,7 +178,7 @@ std::unique_ptr WgcCapturerWin::CreateRawWindowCapturer( std::unique_ptr WgcCapturerWin::CreateRawScreenCapturer( const DesktopCaptureOptions& options) { return std::make_unique( - std::make_unique(), + options, std::make_unique(), std::make_unique(), false); } @@ -309,7 +311,7 @@ void WgcCapturerWin::CaptureFrame() { } if (!capture_session->IsCaptureStarted()) { - hr = capture_session->StartCapture(); + hr = capture_session->StartCapture(options_); if (FAILED(hr)) { RTC_LOG(LS_ERROR) << "Failed to start capture: " << hr; ongoing_captures_.erase(capture_source_->GetSourceId()); @@ -344,7 +346,7 @@ void WgcCapturerWin::CaptureFrame() { capture_time_ms); frame->set_capture_time_ms(capture_time_ms); frame->set_capturer_id(DesktopCapturerId::kWgcCapturerWin); - frame->set_may_contain_cursor(true); + frame->set_may_contain_cursor(options_.prefer_cursor_embedded()); frame->set_top_left(capture_source_->GetTopLeft()); RecordWgcCapturerResult(WgcCapturerResult::kSuccess); callback_->OnCaptureResult(DesktopCapturer::Result::SUCCESS, diff --git a/modules/desktop_capture/win/wgc_capturer_win.h b/modules/desktop_capture/win/wgc_capturer_win.h index d9ee9d3fc6..30253d9db6 100644 --- a/modules/desktop_capture/win/wgc_capturer_win.h +++ b/modules/desktop_capture/win/wgc_capturer_win.h @@ -83,7 +83,8 @@ class ScreenEnumerator final : public SourceEnumerator { // capturer appropriate for the type of source they want to capture. class WgcCapturerWin : public DesktopCapturer { public: - WgcCapturerWin(std::unique_ptr source_factory, + WgcCapturerWin(const DesktopCaptureOptions& options, + std::unique_ptr source_factory, std::unique_ptr source_enumerator, bool allow_delayed_capturable_check); @@ -114,6 +115,8 @@ class WgcCapturerWin : public DesktopCapturer { DispatcherQueueOptions, ABI::Windows::System::IDispatcherQueueController**); + DesktopCaptureOptions options_; + // We need to either create or ensure that someone else created a // `DispatcherQueue` on the current thread so that events will be delivered // on the current thread rather than an arbitrary thread. A