OLD | NEW |
---|---|
(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_DUPLICATOR_H_ | |
12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_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 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one | |
33 // video card. None of functions in this class is thread-safe. | |
34 // TODO(zijiehe): Understand the meaning of rotation. | |
35 class DxgiDuplicator { | |
Sergey Ulanov
2016/07/08 22:36:54
Call this DxgiOutputDuplicator to make it clear ho
Hzj_jie
2016/07/11 00:55:00
Done.
| |
36 public: | |
37 // Creates an instance of DxgiDuplicator from a D3dDevice and one of its | |
38 // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it | |
39 // outlives this instance. | |
40 DxgiDuplicator(const D3dDevice& device, | |
41 const Microsoft::WRL::ComPtr<IDXGIOutput1>& output, | |
42 const DXGI_OUTPUT_DESC& desc); | |
43 | |
44 // To allow this class to use with vector. | |
45 DxgiDuplicator(DxgiDuplicator&& other) = default; | |
Sergey Ulanov
2016/07/08 22:36:54
move =default to the .cc file. (otherwise the comp
Hzj_jie
2016/07/11 00:55:00
Done.
| |
46 | |
47 // Destructs this instance. We need to make sure texture_ has been released | |
48 // before duplication_. | |
49 ~DxgiDuplicator(); | |
50 | |
51 // Initializes duplication_ object. | |
52 bool Initialize(); | |
53 | |
54 // Copies the content of current IDXGIOutput to the target. To improve the | |
Sergey Ulanov
2016/07/08 22:36:54
s/target/|target|/
Hzj_jie
2016/07/11 00:55:00
Done.
| |
55 // performance, this function copies only regions merged from | |
56 // |last_frame|.updated_region and DetectUpdatedRegion. The offset decides the | |
57 // offset in the target where the content should be copied to. i.e. this | |
58 // function copies the content to the rectangle of (offset.x(), offset.y()) to | |
59 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()). | |
60 // The |last_frame| is always expected to be translated by the same offset. | |
61 // Returns false if this function failed to execute Windows APIs. | |
62 bool Duplicate(DesktopFrame* target, | |
63 const DesktopFrame* last_frame, | |
64 const DesktopVector& offset); | |
Sergey Ulanov
2016/07/08 22:36:54
nit: pass DesktopVector by value instead of refere
Hzj_jie
2016/07/11 00:55:00
Done.
| |
65 | |
66 // A shortcut to execute the Duplicate function with desktop_rect_.top_left(). | |
67 bool Duplicate(DesktopFrame* target, | |
68 const DesktopFrame* last_frame) { | |
Sergey Ulanov
2016/07/08 22:36:54
override methods are discouraged. I suggest removi
Hzj_jie
2016/07/11 00:55:00
Done.
| |
69 return Duplicate(target, last_frame, desktop_rect_.top_left()); | |
70 } | |
71 | |
72 // Returns the desktop rect covered by this DxgiDuplicator. | |
73 DesktopRect desktop_rect() const { | |
74 return desktop_rect_; | |
75 } | |
76 | |
77 private: | |
78 // Detects updated region translated by offset from IDXGIOutput1. This | |
79 // function will set the updated_region_ as entire DesktopRect starts from | |
80 // offset if it failed to execute Windows APIs. | |
81 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
82 const DesktopVector& offset); | |
83 | |
84 // Returns untranslated updated region, which are directly returned by Windows | |
85 // APIs. Returns false if this function failed to execute Windows APIs. | |
86 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
87 DesktopRegion* updated_region); | |
88 | |
89 bool DoDuplicate(DesktopFrame* target, | |
90 const DesktopFrame* last_frame, | |
91 const DesktopVector& offset); | |
92 | |
93 bool ReleaseFrame(); | |
94 | |
95 // Initializes duplication_ instance. Expects duplication_ is in empty status. | |
96 // Returns false if system does not support IDXGIOutputDuplication. | |
97 bool DuplicateOutput(); | |
98 | |
99 // Returns a DesktopRect with the same size of desktop_size_, but translated | |
100 // by offset. | |
101 DesktopRect TranslatedDesktopRect(const DesktopVector& offset); | |
102 | |
103 const D3dDevice& device_; | |
104 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_; | |
105 const DesktopRect desktop_rect_; | |
106 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; | |
107 DXGI_OUTDUPL_DESC desc_; | |
108 std::vector<uint8_t> metadata; | |
109 std::unique_ptr<DxgiTexture> texture_; | |
110 // The updated region from DXGI_OUTDUPL_FRAME_INFO. | |
111 DesktopRegion updated_region_; | |
112 }; | |
113 | |
114 } // namespace webrtc | |
115 | |
116 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_H_ | |
OLD | NEW |