[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 <alcooper@chromium.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/main@{#38770}
This commit is contained in:
Michał Zarach 2022-11-24 17:32:45 +01:00 committed by WebRTC LUCI CQ
parent 03bccbe62d
commit 3f2a3b19e3
5 changed files with 23 additions and 8 deletions

View file

@ -79,6 +79,7 @@ Maksim Sisov <msisov@igalia.com>
Maxim Pavlov <pavllovmax@gmail.com>
Maxim Potapov <vopatop.skam@gmail.com>
Michael Iedema <michael@kapsulate.com>
Michał Zarach <michalzaq12@gmail.com>
Michel Promonet <michel.promonet.1@gmail.com>
Miguel Paris <mparisdiaz@gmail.com>
Mike Gilbert <floppymaster@gmail.com>

View file

@ -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<ABI::Windows::Graphics::Capture::IGraphicsCaptureSession2> 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;

View file

@ -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<DesktopFrame>* output_frame);

View file

@ -140,10 +140,12 @@ bool IsWgcSupported(CaptureType capture_type) {
}
WgcCapturerWin::WgcCapturerWin(
const DesktopCaptureOptions& options,
std::unique_ptr<WgcCaptureSourceFactory> source_factory,
std::unique_ptr<SourceEnumerator> 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<DesktopCapturer> WgcCapturerWin::CreateRawWindowCapturer(
const DesktopCaptureOptions& options,
bool allow_delayed_capturable_check) {
return std::make_unique<WgcCapturerWin>(
std::make_unique<WgcWindowSourceFactory>(),
options, std::make_unique<WgcWindowSourceFactory>(),
std::make_unique<WindowEnumerator>(
options.enumerate_current_process_windows()),
allow_delayed_capturable_check);
@ -176,7 +178,7 @@ std::unique_ptr<DesktopCapturer> WgcCapturerWin::CreateRawWindowCapturer(
std::unique_ptr<DesktopCapturer> WgcCapturerWin::CreateRawScreenCapturer(
const DesktopCaptureOptions& options) {
return std::make_unique<WgcCapturerWin>(
std::make_unique<WgcScreenSourceFactory>(),
options, std::make_unique<WgcScreenSourceFactory>(),
std::make_unique<ScreenEnumerator>(), 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,

View file

@ -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<WgcCaptureSourceFactory> source_factory,
WgcCapturerWin(const DesktopCaptureOptions& options,
std::unique_ptr<WgcCaptureSourceFactory> source_factory,
std::unique_ptr<SourceEnumerator> 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