Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h

Issue 2099123002: [Chromoting] Improve DirectX capturer to support multiple outputs (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve review comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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 MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
13
14 #include <comdef.h>
15 #include <wrl/client.h>
16 #include <DXGI.h>
17 #include <DXGI1_2.h>
18
19 #include <memory>
20 #include <vector>
21
22 #include "webrtc/base/criticalsection.h"
23 #include "webrtc/base/thread_annotations.h"
24 #include "webrtc/modules/desktop_capture/desktop_frame.h"
25 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
26 #include "webrtc/modules/desktop_capture/desktop_region.h"
27 #include "webrtc/modules/desktop_capture/win/d3d_device.h"
28 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h"
29
30 namespace webrtc {
31
32 struct DxgiOutputContext {
Sergey Ulanov 2016/08/06 01:27:57 Nest this inside DxgiOutputDuplicator as DxgiOutpu
Hzj_jie 2016/08/08 00:16:09 Oh, I thought you won't like to have classes with
33 // The updated region DxgiOutputDuplicator::DetectUpdatedRegion() output
34 // during last Duplicate() function call. It's a DesktopRegion translated by
35 // offset of each DxgiOutputDuplicator instance.
36 DesktopRegion updated_region;
37 };
38
39 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one
40 // video card. None of functions in this class is thread-safe.
41 // TODO(zijiehe): Understand the meaning of rotation.
42 class DxgiOutputDuplicator {
43 public:
44 // Creates an instance of DxgiOutputDuplicator from a D3dDevice and one of its
45 // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it
46 // outlives this instance. Only DxgiAdapterDuplicator can create an instance.
47 DxgiOutputDuplicator(const D3dDevice& device,
48 const Microsoft::WRL::ComPtr<IDXGIOutput1>& output,
49 const DXGI_OUTPUT_DESC& desc);
50
51 // To allow this class to work with vector.
52 DxgiOutputDuplicator(DxgiOutputDuplicator&& other);
53
54 // Destructs this instance. We need to make sure texture_ has been released
55 // before duplication_.
56 ~DxgiOutputDuplicator();
57
58 // Initializes duplication_ object.
59 bool Initialize();
60
61 // Copies the content of current IDXGIOutput to the |target|. To improve the
62 // performance, this function copies only regions merged from
63 // |last_frame|.updated_region and DetectUpdatedRegion. The offset decides the
64 // offset in the |target| where the content should be copied to. i.e. this
65 // function copies the content to the rectangle of (offset.x(), offset.y()) to
66 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()).
67 // The |last_frame| is always expected to be translated by the same offset.
68 // Returns false if this function failed to execute Windows APIs.
Sergey Ulanov 2016/08/06 01:27:57 s/if this function failed to execute Windows APIs/
Hzj_jie 2016/08/08 00:16:09 Done.
69 bool Duplicate(DxgiOutputContext* context,
70 const DesktopFrame* last_frame,
71 const DesktopVector offset,
72 DesktopFrame* target);
73
74 // Returns the desktop rect covered by this DxgiOutputDuplicator.
75 DesktopRect desktop_rect() const { return desktop_rect_; }
76
77 private:
78 friend class DxgiAdapterDuplicator;
79
80 // Detects updated region translated by offset from IDXGIOutput1. This
81 // function will set the |updated_region| as entire DesktopRect starts from
82 // offset if it failed to execute Windows APIs.
83 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
84 const DesktopVector offset,
85 DesktopRegion* updated_region);
86
87 // Returns untranslated updated region, which are directly returned by Windows
88 // APIs. Returns false if this function failed to execute Windows APIs.
89 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
90 DesktopRegion* updated_region);
91
92 bool ReleaseFrame();
93
94 // Initializes duplication_ instance. Expects duplication_ is in empty status.
95 // Returns false if system does not support IDXGIOutputDuplication.
96 bool DuplicateOutput();
97
98 // Returns a DesktopRect with the same size of desktop_size_, but translated
99 // by offset.
100 DesktopRect TranslatedDesktopRect(const DesktopVector offset);
101
102 void Setup(DxgiOutputContext* context);
103
104 void Unregister(const DxgiOutputContext* const context);
105
106 // Spreads changes from |context| to other registered DxgiOutputContext(s) in
107 // contexts_.
108 void SpreadContextChange(const DxgiOutputContext* const context);
109
110 const D3dDevice& device_;
111 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_;
112 const DesktopRect desktop_rect_;
113 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
114 DXGI_OUTDUPL_DESC desc_;
115 std::vector<uint8_t> metadata;
116 std::unique_ptr<DxgiTexture> texture_;
117
118 // After each AcquireNextFrame() function call, updated_region_(s) of all
119 // active DxgiOutputContext(s) need to be updated. Since they have missed the
120 // change this time. And during next Duplicate() function call, their
121 // updated_region_ will be merged and copied.
122 std::vector<DxgiOutputContext*> contexts_;
123 };
124
125 } // namespace webrtc
126
127 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698