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

Commit b06caae

Browse files
author
Zijie He
committed
Merge ScreenCapturerWinDirectx::frames_ and contexts_
The key change of this CL is to merge ScreenCapturerWinDirectx::frames_ and contexts_ into a new DxgiFrame class. So consumers of DxgiDuplicateController does not need to maintain two objects. DxgiDuplicateController::Duplicate*() functions are also updated to accept DxgiFrame parameter instead of SharedDesktopFrame + Context. The advantages of this change are, 1. Once the screen resolution changes or an existing monitor has been removed, DxgiFrame can automatically reset the frame without needing to return a capture failure. 2. Remove public APIs of DxgiDuplicatorController. Some public APIs are not needed anymore, i.e. consumers of DxgiDuplicatorController do not need to take care about these internal states anymore. It also helps to remove several lock acquiements. 3. Reduce the complexity of ScreenCapturerWinDirectx. But the disadvantage is, instead of a boolean value, DxgiDuplicateController::Duplicate*() now return an enumeration. Clients need to use the enumeration to decide whether the error can be recovered or not. This change also removes a duplicating logic in ScreenCapturerWinDirectx. i.e. ResolutionChangeDetector, DxgiDuplicateController now takes care of the screen resolution changes. I have verified the scenarios with and without SharedMemoryFactory, also the Desktop capture API example. So far no regression is detected. BUG=704205, 715689 Review-Url: https://codereview.webrtc.org/2788863006 Cr-Commit-Position: refs/heads/master@{#17795} (cherry picked from commit cf5753d) Review-Url: https://codereview.webrtc.org/2860573010 . Cr-Commit-Position: refs/branch-heads/59@{#8} Cr-Branched-From: 10d095d-refs/heads/master@{#17657}
1 parent 01b3df3 commit b06caae

12 files changed

+406
-268
lines changed

webrtc/modules/desktop_capture/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ rtc_static_library("desktop_capture") {
203203
"win/desktop.h",
204204
"win/dxgi_adapter_duplicator.cc",
205205
"win/dxgi_adapter_duplicator.h",
206+
"win/dxgi_context.cc",
207+
"win/dxgi_context.h",
206208
"win/dxgi_duplicator_controller.cc",
207209
"win/dxgi_duplicator_controller.h",
210+
"win/dxgi_frame.cc",
211+
"win/dxgi_frame.h",
208212
"win/dxgi_output_duplicator.cc",
209213
"win/dxgi_output_duplicator.h",
210214
"win/dxgi_texture.cc",

webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ bool IsValidRect(const RECT& rect) {
3131

3232
} // namespace
3333

34-
DxgiAdapterDuplicator::Context::Context() = default;
35-
DxgiAdapterDuplicator::Context::Context(const Context& other) = default;
36-
DxgiAdapterDuplicator::Context::~Context() = default;
37-
3834
DxgiAdapterDuplicator::DxgiAdapterDuplicator(const D3dDevice& device)
3935
: device_(device) {}
4036
DxgiAdapterDuplicator::DxgiAdapterDuplicator(DxgiAdapterDuplicator&&) = default;

webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include <vector>
1717

1818
#include "webrtc/modules/desktop_capture/desktop_geometry.h"
19-
#include "webrtc/modules/desktop_capture/desktop_region.h"
2019
#include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
2120
#include "webrtc/modules/desktop_capture/win/d3d_device.h"
21+
#include "webrtc/modules/desktop_capture/win/dxgi_context.h"
2222
#include "webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h"
2323

2424
namespace webrtc {
@@ -27,15 +27,7 @@ namespace webrtc {
2727
// single video card.
2828
class DxgiAdapterDuplicator {
2929
public:
30-
struct Context {
31-
Context();
32-
Context(const Context& other);
33-
~Context();
34-
35-
// Child DxgiOutputDuplicator::Context belongs to this
36-
// DxgiAdapterDuplicator::Context.
37-
std::vector<DxgiOutputDuplicator::Context> contexts;
38-
};
30+
using Context = DxgiAdapterContext;
3931

4032
// Creates an instance of DxgiAdapterDuplicator from a D3dDevice. Only
4133
// DxgiDuplicatorController can create an instance.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
#include "webrtc/modules/desktop_capture/win/dxgi_context.h"
12+
#include "webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h"
13+
14+
namespace webrtc {
15+
16+
DxgiAdapterContext::DxgiAdapterContext() = default;
17+
DxgiAdapterContext::DxgiAdapterContext(
18+
const DxgiAdapterContext& context) = default;
19+
DxgiAdapterContext::~DxgiAdapterContext() = default;
20+
21+
DxgiFrameContext::DxgiFrameContext() = default;
22+
23+
DxgiFrameContext::~DxgiFrameContext() {
24+
DxgiDuplicatorController::Instance()->Unregister(this);
25+
}
26+
27+
void DxgiFrameContext::Reset() {
28+
controller_id = 0;
29+
}
30+
31+
} // namespace webrtc
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_CONTEXT_H_
12+
#define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_CONTEXT_H_
13+
14+
#include <vector>
15+
#include "webrtc/modules/desktop_capture/desktop_region.h"
16+
17+
namespace webrtc {
18+
19+
// A DxgiOutputContext stores the status of a single DxgiFrame of
20+
// DxgiOutputDuplicator.
21+
struct DxgiOutputContext final {
22+
// The updated region DxgiOutputDuplicator::DetectUpdatedRegion() output
23+
// during last Duplicate() function call. It's always relative to the (0, 0).
24+
DesktopRegion updated_region;
25+
};
26+
27+
// A DxgiAdapterContext stores the status of a single DxgiFrame of
28+
// DxgiAdapterDuplicator.
29+
struct DxgiAdapterContext final {
30+
DxgiAdapterContext();
31+
DxgiAdapterContext(const DxgiAdapterContext& other);
32+
~DxgiAdapterContext();
33+
34+
// Child DxgiOutputContext belongs to this AdapterContext.
35+
std::vector<DxgiOutputContext> contexts;
36+
};
37+
38+
// A DxgiFrameContext stores the status of a single DxgiFrame of
39+
// DxgiDuplicatorController.
40+
struct DxgiFrameContext final {
41+
public:
42+
DxgiFrameContext();
43+
// Unregister this Context instance from DxgiDuplicatorController during
44+
// destructing.
45+
~DxgiFrameContext();
46+
47+
// Reset current Context, so it will be reinitialized next time.
48+
void Reset();
49+
50+
// A Context will have an exactly same |controller_id| as
51+
// DxgiDuplicatorController, to ensure it has been correctly setted up after
52+
// each DxgiDuplicatorController::Initialize().
53+
int controller_id = 0;
54+
55+
// Child DxgiAdapterContext belongs to this DxgiFrameContext.
56+
std::vector<DxgiAdapterContext> contexts;
57+
};
58+
59+
} // namespace webrtc
60+
61+
#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_CONTEXT_H_

0 commit comments

Comments
 (0)