Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 61fe801

Browse files
author
Zijie He
committed
Allow Windows to return a monitor out of the first quadrant
Windows may return a DesktopCoordinate out of the first quadrant (x >= 0 && y >= 0), this typically happens when the primary and secondary monitors are swapped. i.e. The secondary monitor is on the left but the primary one is on the right. This change "moves" the entire screen from any quadrant to the (0, 0), so we can capture the monitors in other quadrants. BUG=chromium:715689 Review-Url: https://codereview.webrtc.org/2848443004 Cr-Original-Commit-Position: refs/heads/master@{#17935} Committed: https://chromium.googlesource.com/external/webrtc/+/049ec71e657eef3d15e0f15d60acb1a71e81b521 Review-Url: https://codereview.webrtc.org/2848443004 Cr-Commit-Position: refs/heads/master@{#17938} (cherry picked from commit 419c742) Review-Url: https://codereview.webrtc.org/2866493002 . Cr-Commit-Position: refs/branch-heads/59@{#9} Cr-Branched-From: 10d095d-refs/heads/master@{#17657}
1 parent b06caae commit 61fe801

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ using Microsoft::WRL::ComPtr;
2525
namespace {
2626

2727
bool IsValidRect(const RECT& rect) {
28-
return rect.left >= 0 && rect.top >= 0 && rect.right > rect.left &&
29-
rect.bottom > rect.top;
28+
return rect.right > rect.left && rect.bottom > rect.top;
3029
}
3130

3231
} // namespace
@@ -153,4 +152,12 @@ int64_t DxgiAdapterDuplicator::GetNumFramesCaptured() const {
153152
return min;
154153
}
155154

155+
void DxgiAdapterDuplicator::TranslateRect(const DesktopVector& position) {
156+
desktop_rect_.Translate(position);
157+
RTC_DCHECK(desktop_rect_.left() >= 0 && desktop_rect_.top() >= 0);
158+
for (auto& duplicator : duplicators_) {
159+
duplicator.TranslateRect(position);
160+
}
161+
}
162+
156163
} // namespace webrtc

webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class DxgiAdapterDuplicator {
7171
// The minimum num_frames_captured() returned by |duplicators_|.
7272
int64_t GetNumFramesCaptured() const;
7373

74+
// Moves |desktop_rect_| and all underlying |duplicators_|. See
75+
// DxgiDuplicatorController::TranslateRect().
76+
void TranslateRect(const DesktopVector& position);
77+
7478
private:
7579
bool DoInitialize();
7680

webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ bool DxgiDuplicatorController::DoInitialize() {
194194
std::max(left.bottom(), right.bottom()));
195195
}
196196
}
197+
TranslateRect();
197198

198199
HDC hdc = GetDC(nullptr);
199200
// Use old DPI value if failed.
@@ -295,7 +296,7 @@ int64_t DxgiDuplicatorController::GetNumFramesCaptured() const {
295296
}
296297

297298
DesktopSize DxgiDuplicatorController::desktop_size() const {
298-
return DesktopSize(desktop_rect_.right(), desktop_rect_.bottom());
299+
return desktop_rect_.size();
299300
}
300301

301302
DesktopRect DxgiDuplicatorController::ScreenRect(int id) const {
@@ -378,4 +379,13 @@ bool DxgiDuplicatorController::EnsureFrameCaptured(Context* context,
378379
return true;
379380
}
380381

382+
void DxgiDuplicatorController::TranslateRect() {
383+
const DesktopVector position =
384+
DesktopVector().subtract(desktop_rect_.top_left());
385+
desktop_rect_.Translate(position);
386+
for (auto& duplicator : duplicators_) {
387+
duplicator.TranslateRect(position);
388+
}
389+
}
390+
381391
} // namespace webrtc

webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ class DxgiDuplicatorController {
158158
// The minimum GetNumFramesCaptured() returned by |duplicators_|.
159159
int64_t GetNumFramesCaptured() const;
160160

161-
// Returns a DesktopSize to cover entire desktop_rect. This may be different
162-
// than desktop_rect().size(), since top-left of the screen does not need to
163-
// be started from (0, 0).
161+
// Returns a DesktopSize to cover entire |desktop_rect_|.
164162
DesktopSize desktop_size() const;
165163

166164
// Returns the size of one screen. |id| should be >= 0. If system does not
@@ -181,6 +179,12 @@ class DxgiDuplicatorController {
181179
// during first several capture attempts.
182180
bool EnsureFrameCaptured(Context* context, SharedDesktopFrame* target);
183181

182+
// Moves |desktop_rect_| and all underlying |duplicators_|, putting top left
183+
// corner of the desktop at (0, 0). This is necessary because DXGI_OUTPUT_DESC
184+
// may return negative coordinates. Called from DoInitialize() after all
185+
// DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized.
186+
void TranslateRect();
187+
184188
// This lock must be locked whenever accessing any of the following objects.
185189
rtc::CriticalSection lock_;
186190

webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ DxgiOutputDuplicator::DxgiOutputDuplicator(const D3dDevice& device,
6767
desktop_rect_(RECTToDesktopRect(desc.DesktopCoordinates)) {
6868
RTC_DCHECK(output_);
6969
RTC_DCHECK(!desktop_rect_.is_empty());
70-
RTC_DCHECK(desktop_rect_.left() >= 0 && desktop_rect_.top() >= 0);
70+
RTC_DCHECK(desktop_rect_.width() > 0 && desktop_rect_.height() > 0);
7171
}
7272

7373
DxgiOutputDuplicator::DxgiOutputDuplicator(DxgiOutputDuplicator&& other) =
@@ -381,4 +381,9 @@ int64_t DxgiOutputDuplicator::num_frames_captured() const {
381381
return num_frames_captured_;
382382
}
383383

384+
void DxgiOutputDuplicator::TranslateRect(const DesktopVector& position) {
385+
desktop_rect_.Translate(position);
386+
RTC_DCHECK(desktop_rect_.left() >= 0 && desktop_rect_.top() >= 0);
387+
}
388+
384389
} // namespace webrtc

webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class DxgiOutputDuplicator {
7575
// How many frames have been captured by this DxigOutputDuplicator.
7676
int64_t num_frames_captured() const;
7777

78+
// Moves |desktop_rect_|. See DxgiDuplicatorController::TranslateRect().
79+
void TranslateRect(const DesktopVector& position);
80+
7881
private:
7982
// Calls DoDetectUpdatedRegion(). If it fails, this function sets the
8083
// |updated_region| as entire UntranslatedDesktopRect().
@@ -109,7 +112,7 @@ class DxgiOutputDuplicator {
109112

110113
const D3dDevice device_;
111114
const Microsoft::WRL::ComPtr<IDXGIOutput1> output_;
112-
const DesktopRect desktop_rect_;
115+
DesktopRect desktop_rect_;
113116
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
114117
DXGI_OUTDUPL_DESC desc_;
115118
std::vector<uint8_t> metadata_;

0 commit comments

Comments
 (0)