Remove DesktopRegion parameter from DesktopCapturer::Capture.
To ensure this change won't break Chromium, this is the first change, to add a
new CaptureFrame() function, and let Capture(DesktopRegion) and CaptureFrame()
call each other. So both a legacy consumer or a legacy implementation won't be
broken.
BUG=https://bugs.chromium.org/p/webrtc/issues/detail?id=6513
Review-Url: https://codereview.webrtc.org/2409833002
Cr-Commit-Position: refs/heads/master@{#14635}
diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer.cc b/webrtc/modules/desktop_capture/cropping_window_capturer.cc
index 50aaeea..63a62f5 100644
--- a/webrtc/modules/desktop_capture/cropping_window_capturer.cc
+++ b/webrtc/modules/desktop_capture/cropping_window_capturer.cc
@@ -36,7 +36,7 @@
window_capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory));
}
-void CroppingWindowCapturer::Capture(const DesktopRegion& region) {
+void CroppingWindowCapturer::CaptureFrame() {
if (ShouldUseScreenCapturer()) {
if (!screen_capturer_.get()) {
screen_capturer_.reset(ScreenCapturer::Create(options_));
@@ -45,9 +45,9 @@
}
screen_capturer_->Start(this);
}
- screen_capturer_->Capture(region);
+ screen_capturer_->CaptureFrame();
} else {
- window_capturer_->Capture(region);
+ window_capturer_->CaptureFrame();
}
}
diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer.h b/webrtc/modules/desktop_capture/cropping_window_capturer.h
index e2db7da..d24d770 100644
--- a/webrtc/modules/desktop_capture/cropping_window_capturer.h
+++ b/webrtc/modules/desktop_capture/cropping_window_capturer.h
@@ -32,7 +32,7 @@
void Start(DesktopCapturer::Callback* callback) override;
void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
void SetExcludedWindow(WindowId window) override;
// WindowCapturer implementation.
diff --git a/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc b/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc
index a4deda6..0ff3373 100644
--- a/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc
+++ b/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc
@@ -145,10 +145,10 @@
desktop_capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory));
}
-void DesktopAndCursorComposer::Capture(const DesktopRegion& region) {
+void DesktopAndCursorComposer::CaptureFrame() {
if (mouse_monitor_.get())
mouse_monitor_->Capture();
- desktop_capturer_->Capture(region);
+ desktop_capturer_->CaptureFrame();
}
void DesktopAndCursorComposer::SetExcludedWindow(WindowId window) {
diff --git a/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h b/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h
index ef63402..801d3e3 100644
--- a/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h
+++ b/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h
@@ -37,7 +37,7 @@
void Start(DesktopCapturer::Callback* callback) override;
void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
void SetExcludedWindow(WindowId window) override;
private:
diff --git a/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc b/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc
index 5e7a02a..77471b8 100644
--- a/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc
+++ b/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc
@@ -77,7 +77,7 @@
void Start(Callback* callback) override { callback_ = callback; }
- void Capture(const DesktopRegion& region) override {
+ void CaptureFrame() override {
callback_->OnCaptureResult(
next_frame_ ? Result::SUCCESS : Result::ERROR_TEMPORARY,
std::move(next_frame_));
@@ -193,7 +193,7 @@
fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector());
fake_screen_->SetNextFrame(nullptr);
- blender_.Capture(DesktopRegion());
+ blender_.CaptureFrame();
EXPECT_FALSE(frame_);
}
@@ -237,7 +237,7 @@
SharedDesktopFrame::Wrap(CreateTestFrame()));
fake_screen_->SetNextFrame(frame->Share());
- blender_.Capture(DesktopRegion());
+ blender_.CaptureFrame();
VerifyFrame(*frame_, state, pos);
diff --git a/webrtc/modules/desktop_capture/desktop_capturer.h b/webrtc/modules/desktop_capture/desktop_capturer.h
index 778c93c..0c7b68e 100644
--- a/webrtc/modules/desktop_capture/desktop_capturer.h
+++ b/webrtc/modules/desktop_capture/desktop_capturer.h
@@ -66,13 +66,12 @@
virtual void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {}
- // Captures next frame. |region| specifies region of the capture target that
- // should be fresh in the resulting frame. The frame may also include fresh
- // data for areas outside |region|. In that case capturer will include these
- // areas in updated_region() of the frame. |region| is specified relative to
- // the top left corner of the capture target. Pending capture operations are
- // canceled when DesktopCapturer is deleted.
- virtual void Capture(const DesktopRegion& region) = 0;
+ // This is a legacy interface, consumers should call CaptureFrame() function.
+ virtual void Capture(const DesktopRegion& region) { CaptureFrame(); }
+
+ // Captures next frame, and involve callback provided by Start() function.
+ // Pending capture requests are canceled when DesktopCapturer is deleted.
+ virtual void CaptureFrame() { Capture(DesktopRegion()); }
// Sets the window to be excluded from the captured image in the future
// Capture calls. Used to exclude the screenshare notification window for
diff --git a/webrtc/modules/desktop_capture/fake_desktop_capturer.h b/webrtc/modules/desktop_capture/fake_desktop_capturer.h
index db53809..fa5ccba 100644
--- a/webrtc/modules/desktop_capture/fake_desktop_capturer.h
+++ b/webrtc/modules/desktop_capture/fake_desktop_capturer.h
@@ -62,7 +62,7 @@
callback_ = callback;
}
- void Capture(const DesktopRegion& region) override {
+ void CaptureFrame() override {
if (generator_) {
std::unique_ptr<DesktopFrame> frame(
generator_->GetNextFrame(shared_memory_factory_.get()));
diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc
index dc76b67..b0d2282 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc
+++ b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc
@@ -161,8 +161,8 @@
base_capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory));
}
-void ScreenCapturerDifferWrapper::Capture(const DesktopRegion& region) {
- base_capturer_->Capture(region);
+void ScreenCapturerDifferWrapper::CaptureFrame() {
+ base_capturer_->CaptureFrame();
}
bool ScreenCapturerDifferWrapper::GetScreenList(ScreenList* screens) {
diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h
index c7a20b3..6ae3a1b 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h
+++ b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h
@@ -39,7 +39,7 @@
void Start(DesktopCapturer::Callback* callback) override;
void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
bool GetScreenList(ScreenList* screens) override;
bool SelectScreen(ScreenId id) override;
diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc
index f04d809..ae7b7d9 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc
+++ b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc
@@ -136,7 +136,7 @@
for (const auto& rect : updated_region) {
frame_painter->updated_region()->AddRect(rect);
}
- capturer->Capture(DesktopRegion());
+ capturer->CaptureFrame();
}
// Executes a ScreenCapturerDifferWrapper::Capture(), if updated_region() is not
@@ -147,7 +147,7 @@
EXPECT_CALL(*callback,
OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_))
.Times(1);
- capturer->Capture(DesktopRegion());
+ capturer->CaptureFrame();
}
void ExecuteDifferWrapperTest(bool with_hints,
@@ -178,7 +178,7 @@
AssertUpdatedRegionIs(**frame,
{DesktopRect::MakeSize((*frame)->size())});
}));
- capturer.Capture(DesktopRegion());
+ capturer.CaptureFrame();
ExecuteDifferWrapperCase(&frame_painter, &capturer, &callback,
{DesktopRect::MakeLTRB(100, 100, 200, 200),
diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac.mm b/webrtc/modules/desktop_capture/screen_capturer_mac.mm
index eed59c8..47885ee 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_mac.mm
+++ b/webrtc/modules/desktop_capture/screen_capturer_mac.mm
@@ -285,7 +285,7 @@
// Overridden from ScreenCapturer:
void Start(Callback* callback) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
void SetExcludedWindow(WindowId window) override;
bool GetScreenList(ScreenList* screens) override;
bool SelectScreen(ScreenId id) override;
@@ -426,7 +426,7 @@
callback_ = callback;
}
-void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) {
+void ScreenCapturerMac::CaptureFrame() {
int64_t capture_start_time_nanos = rtc::TimeNanos();
queue_.MoveToNextFrame();
diff --git a/webrtc/modules/desktop_capture/screen_capturer_mock_objects.h b/webrtc/modules/desktop_capture/screen_capturer_mock_objects.h
index f08dab5..6baaa47 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_mock_objects.h
+++ b/webrtc/modules/desktop_capture/screen_capturer_mock_objects.h
@@ -19,11 +19,16 @@
class MockScreenCapturer : public ScreenCapturer {
public:
- MockScreenCapturer() {}
+ MockScreenCapturer() {
+ ON_CALL(*this, Capture(testing::_))
+ .WillByDefault(testing::WithoutArgs(testing::Invoke(
+ this, &MockScreenCapturer::CaptureFrame)));
+ }
virtual ~MockScreenCapturer() {}
MOCK_METHOD1(Start, void(Callback* callback));
MOCK_METHOD1(Capture, void(const DesktopRegion& region));
+ MOCK_METHOD0(CaptureFrame, void(void));
MOCK_METHOD1(GetScreenList, bool(ScreenList* screens));
MOCK_METHOD1(SelectScreen, bool(ScreenId id));
diff --git a/webrtc/modules/desktop_capture/screen_capturer_unittest.cc b/webrtc/modules/desktop_capture/screen_capturer_unittest.cc
index fa666a9..ce0cab1 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_unittest.cc
+++ b/webrtc/modules/desktop_capture/screen_capturer_unittest.cc
@@ -204,7 +204,7 @@
EXPECT_CALL(callback_,
OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
.WillOnce(SaveUniquePtrArg(&frame));
- capturer->Capture(DesktopRegion());
+ capturer->CaptureFrame();
EXPECT_TRUE(frame);
return frame;
}
@@ -259,7 +259,7 @@
.WillOnce(SaveUniquePtrArg(&frame));
capturer_->Start(&callback_);
- capturer_->Capture(DesktopRegion());
+ capturer_->CaptureFrame();
ASSERT_TRUE(frame);
EXPECT_GT(frame->size().width(), 0);
@@ -302,7 +302,7 @@
capturer_->Start(&callback_);
capturer_->SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory()));
- capturer_->Capture(DesktopRegion());
+ capturer_->CaptureFrame();
ASSERT_TRUE(frame);
ASSERT_TRUE(frame->shared_memory());
@@ -318,7 +318,7 @@
.WillOnce(SaveUniquePtrArg(&frame));
capturer_->Start(&callback_);
- capturer_->Capture(DesktopRegion());
+ capturer_->CaptureFrame();
ASSERT_TRUE(frame);
}
@@ -333,7 +333,7 @@
.WillOnce(SaveUniquePtrArg(&frame));
capturer_->Start(&callback_);
- capturer_->Capture(DesktopRegion());
+ capturer_->CaptureFrame();
ASSERT_TRUE(frame);
}
@@ -350,7 +350,7 @@
capturer_->Start(&callback_);
capturer_->SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory()));
- capturer_->Capture(DesktopRegion());
+ capturer_->CaptureFrame();
ASSERT_TRUE(frame);
ASSERT_TRUE(frame->shared_memory());
EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId);
diff --git a/webrtc/modules/desktop_capture/screen_capturer_x11.cc b/webrtc/modules/desktop_capture/screen_capturer_x11.cc
index 6f5e520..ff3ee11 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_x11.cc
+++ b/webrtc/modules/desktop_capture/screen_capturer_x11.cc
@@ -54,7 +54,7 @@
// DesktopCapturer interface.
void Start(Callback* delegate) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
// ScreenCapturer interface.
bool GetScreenList(ScreenList* screens) override;
@@ -228,7 +228,7 @@
callback_ = callback;
}
-void ScreenCapturerLinux::Capture(const DesktopRegion& region) {
+void ScreenCapturerLinux::CaptureFrame() {
int64_t capture_start_time_nanos = rtc::TimeNanos();
queue_.MoveToNextFrame();
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc
index 9e3f58b..38a3999 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc
@@ -54,7 +54,7 @@
.size();
}
-void ScreenCapturerWinDirectx::Capture(const DesktopRegion& region) {
+void ScreenCapturerWinDirectx::CaptureFrame() {
RTC_DCHECK(callback_);
int64_t capture_start_time_nanos = rtc::TimeNanos();
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h
index 86232c7..2427ec4 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h
@@ -38,7 +38,7 @@
void Start(Callback* callback) override;
void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
bool GetScreenList(ScreenList* screens) override;
bool SelectScreen(ScreenId id) override;
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc
index 2c2178d..4bf8b14 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc
@@ -71,7 +71,7 @@
shared_memory_factory_ = std::move(shared_memory_factory);
}
-void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) {
+void ScreenCapturerWinGdi::CaptureFrame() {
int64_t capture_start_time_nanos = rtc::TimeNanos();
queue_.MoveToNextFrame();
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h
index 01a5991..a9e1845 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h
@@ -39,7 +39,7 @@
void Start(Callback* callback) override;
void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
bool GetScreenList(ScreenList* screens) override;
bool SelectScreen(ScreenId id) override;
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc
index e5a37c9..5ffd1f9 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc
@@ -72,7 +72,7 @@
shared_memory_factory_ = std::move(shared_memory_factory);
}
-void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) {
+void ScreenCapturerWinMagnifier::CaptureFrame() {
if (!magnifier_initialized_ ||
!magnifier_capture_succeeded_ ||
GetSystemMetrics(SM_CMONITORS) != 1) {
@@ -82,7 +82,7 @@
"initialization or last capture attempt failed, or "
"execute on multi-screen system.";
StartFallbackCapturer();
- fallback_capturer_->Capture(region);
+ fallback_capturer_->CaptureFrame();
return;
}
@@ -111,7 +111,7 @@
LOG_F(LS_WARNING) << "Switching to the fallback screen capturer because "
"last capture attempt failed.";
StartFallbackCapturer();
- fallback_capturer_->Capture(region);
+ fallback_capturer_->CaptureFrame();
return;
}
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h
index 080a57c..6c72138 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h
@@ -51,7 +51,7 @@
void Start(Callback* callback) override;
void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
bool GetScreenList(ScreenList* screens) override;
bool SelectScreen(ScreenId id) override;
void SetExcludedWindow(WindowId window) override;
diff --git a/webrtc/modules/desktop_capture/window_capturer_mac.mm b/webrtc/modules/desktop_capture/window_capturer_mac.mm
index cbdf14b..1e706fa 100644
--- a/webrtc/modules/desktop_capture/window_capturer_mac.mm
+++ b/webrtc/modules/desktop_capture/window_capturer_mac.mm
@@ -55,7 +55,7 @@
// DesktopCapturer interface.
void Start(Callback* callback) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
private:
Callback* callback_ = nullptr;
@@ -176,7 +176,7 @@
callback_ = callback;
}
-void WindowCapturerMac::Capture(const DesktopRegion& region) {
+void WindowCapturerMac::CaptureFrame() {
if (!IsWindowValid(window_id_)) {
callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
return;
diff --git a/webrtc/modules/desktop_capture/window_capturer_null.cc b/webrtc/modules/desktop_capture/window_capturer_null.cc
index 3fe21cf..802d74f 100755
--- a/webrtc/modules/desktop_capture/window_capturer_null.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_null.cc
@@ -31,7 +31,7 @@
// DesktopCapturer interface.
void Start(Callback* callback) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
private:
Callback* callback_ = nullptr;
@@ -64,7 +64,7 @@
callback_ = callback;
}
-void WindowCapturerNull::Capture(const DesktopRegion& region) {
+void WindowCapturerNull::CaptureFrame() {
// Not implemented yet.
callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
}
diff --git a/webrtc/modules/desktop_capture/window_capturer_win.cc b/webrtc/modules/desktop_capture/window_capturer_win.cc
index c7c312a..61de06c 100644
--- a/webrtc/modules/desktop_capture/window_capturer_win.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_win.cc
@@ -92,7 +92,7 @@
// DesktopCapturer interface.
void Start(Callback* callback) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
private:
Callback* callback_ = nullptr;
@@ -160,7 +160,7 @@
callback_ = callback;
}
-void WindowCapturerWin::Capture(const DesktopRegion& region) {
+void WindowCapturerWin::CaptureFrame() {
if (!window_) {
LOG(LS_ERROR) << "Window hasn't been selected: " << GetLastError();
callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
diff --git a/webrtc/modules/desktop_capture/window_capturer_x11.cc b/webrtc/modules/desktop_capture/window_capturer_x11.cc
index d88585b..e4a0917 100644
--- a/webrtc/modules/desktop_capture/window_capturer_x11.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_x11.cc
@@ -95,7 +95,7 @@
// DesktopCapturer interface.
void Start(Callback* callback) override;
- void Capture(const DesktopRegion& region) override;
+ void CaptureFrame() override;
// SharedXDisplay::XEventHandler interface.
bool HandleXEvent(const XEvent& event) override;
@@ -271,7 +271,7 @@
callback_ = callback;
}
-void WindowCapturerLinux::Capture(const DesktopRegion& region) {
+void WindowCapturerLinux::CaptureFrame() {
if (!x_server_pixel_buffer_.IsWindowValid()) {
LOG(LS_INFO) << "The window is no longer valid.";
callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);