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

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: Fix several lint errors 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 WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
12 #define WEBRTC_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 // 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 DxgiOutputDuplicator {
36 public:
37 struct Context {
38 // The updated region DxgiOutputDuplicator::DetectUpdatedRegion() output
39 // during last Duplicate() function call. It's a DesktopRegion translated by
40 // offset of each DxgiOutputDuplicator instance.
41 DesktopRegion updated_region;
42 };
43
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
64 // the
65 // offset in the |target| where the content should be copied to. i.e. this
66 // function copies the content to the rectangle of (offset.x(), offset.y()) to
67 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()).
68 // The |last_frame| is always expected to be translated by the same offset.
69 // Returns false in case of a failure.
70 bool Duplicate(Context* context,
71 const DesktopFrame* last_frame,
72 const DesktopVector offset,
73 DesktopFrame* target);
74
75 // Returns the desktop rect covered by this DxgiOutputDuplicator.
76 DesktopRect desktop_rect() const { return desktop_rect_; }
77
78 private:
79 friend class DxgiAdapterDuplicator;
80
81 // Detects updated region translated by offset from IDXGIOutput1. This
82 // function will set the |updated_region| as entire DesktopRect starts from
83 // offset if it failed to execute Windows APIs.
84 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
85 const DesktopVector offset,
86 DesktopRegion* updated_region);
87
88 // Returns untranslated updated region, which are directly returned by Windows
89 // APIs. Returns false in case of a failure.
90 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
91 DesktopRegion* updated_region);
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 void Setup(Context* context);
104
105 void Unregister(const Context* const context);
106
107 // Spreads changes from |context| to other registered Context(s) in
108 // contexts_.
109 void SpreadContextChange(const Context* const context);
110
111 const D3dDevice& device_;
112 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_;
113 const DesktopRect desktop_rect_;
114 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
115 DXGI_OUTDUPL_DESC desc_;
116 std::vector<uint8_t> metadata;
117 std::unique_ptr<DxgiTexture> texture_;
118
119 // After each AcquireNextFrame() function call, updated_region_(s) of all
120 // active Context(s) need to be updated. Since they have missed the
121 // change this time. And during next Duplicate() function call, their
122 // updated_region_ will be merged and copied.
123 std::vector<Context*> contexts_;
124 };
125
126 } // namespace webrtc
127
128 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698